fix: require evaluation time for cleanup freshness

This commit is contained in:
pingqiu committed 2026-11-28 13:40:27 -08:00
1 parent 7cfac5eee9
commit c88406df7f
3 files changed
+25 -16

No files matched your search

@@ -161,11 +161,8 @@ func cleanupEvidenceStale(facts SwBlockVolumeDeleteSafetyFacts) bool {
if facts.Cleanup == nil || facts.MaxEvidenceAge <= 0 {
return false
}
if facts.Cleanup.ObservedAt.IsZero() {
return true // An enabled age bound requires a timestamp to prove freshness.
}
if facts.ObservedAt.IsZero() {
return false
if facts.Cleanup.ObservedAt.IsZero() || facts.ObservedAt.IsZero() {
return true // An enabled age bound requires both timestamps to prove freshness.
}
return facts.Cleanup.ObservedAt.Add(facts.MaxEvidenceAge).Before(facts.ObservedAt)
}
@@ -7,16 +7,27 @@ import (
)
func TestDeleteSafety_UntimedCleanupCannotProveFreshness(t *testing.T) {
decision := EvaluateSwBlockVolumeDeleteSafety(SwBlockVolumeDeleteSafetyFacts{
DeleteRequested: true, FinalizerPresent: true,
ObservedAt: time.Date(2026, 11, 17, 0, 0, 0, 0, time.UTC), MaxEvidenceAge: 15 * time.Minute,
Cleanup: &CleanupEvidence{Status: ObservationStatusOK, EvidenceRef: "untimed-cleanup.txt"},
})
if decision.FinalizerReleaseAllowed || decision.Decision != ManagedVolumeActionDecisionUnknown {
t.Fatalf("untimed cleanup accepted as fresh: %+v; require UNKNOWN and no finalizer release", decision)
}
if decision.Reason != ReasonCleanupEvidenceStale || !stringSliceContains(decision.MissingFacts, "cleanup.freshness") || decision.SafeNextAction != ManagedVolumeActionVerifyCleanup {
t.Fatalf("missing freshness must request cleanup verification: %+v", decision)
now := time.Date(2026, 11, 17, 0, 0, 0, 0, time.UTC)
for _, tt := range []struct {
name string
cleanupAt, evaluationAt time.Time
}{
{"cleanup_time_missing", time.Time{}, now},
{"evaluation_time_missing", now, time.Time{}},
{"both_times_missing", time.Time{}, time.Time{}},
} {
t.Run(tt.name, func(t *testing.T) {
decision := EvaluateSwBlockVolumeDeleteSafety(SwBlockVolumeDeleteSafetyFacts{
DeleteRequested: true, FinalizerPresent: true, ObservedAt: tt.evaluationAt, MaxEvidenceAge: 15 * time.Minute,
Cleanup: &CleanupEvidence{Status: ObservationStatusOK, ObservedAt: tt.cleanupAt, EvidenceRef: "cleanup-summary.txt"},
})
if decision.FinalizerReleaseAllowed || decision.Decision != ManagedVolumeActionDecisionUnknown {
t.Fatalf("missing timestamp accepted as fresh: %+v; require UNKNOWN and no finalizer release", decision)
}
if decision.Reason != ReasonCleanupEvidenceStale || !stringSliceContains(decision.MissingFacts, "cleanup.freshness") || decision.SafeNextAction != ManagedVolumeActionVerifyCleanup {
t.Fatalf("missing freshness must request cleanup verification: %+v", decision)
}
})
}
}
+2 -1
View File
@@ -126,7 +126,8 @@ These are narrow alpha claims tied to documented gates. See
report a `SwBlockVolume` deletion as releasable despite the status projection's
15-minute evidence age bound ([#188](https://github.com/seaweedfs/seaweed-block/issues/188)).
Supply a real observation timestamp in the cleanup summary. The v1.0.1 fix
reports UNKNOWN with missing `cleanup.freshness` when that timestamp is absent;
reports UNKNOWN with missing `cleanup.freshness` when either the cleanup or
evaluation timestamp is absent;
the next action is to verify cleanup again. This is a Kubernetes status
projection defect; no product delete acts on this decision.