From c88406df7f41c25dfc319b3a6458cb39db370eb2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 13:40:27 -0800 Subject: [PATCH] fix: require evaluation time for cleanup freshness --- .../core/ops/delete_safety_contract.go | 7 ++--- .../delete_safety_untimed_regression_test.go | 31 +++++++++++++------ seaweed-block/docs/kubernetes-status.md | 3 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/seaweed-block/core/ops/delete_safety_contract.go b/seaweed-block/core/ops/delete_safety_contract.go index f556c64916..9153b26f2b 100644 --- a/seaweed-block/core/ops/delete_safety_contract.go +++ b/seaweed-block/core/ops/delete_safety_contract.go @@ -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) } diff --git a/seaweed-block/core/ops/delete_safety_untimed_regression_test.go b/seaweed-block/core/ops/delete_safety_untimed_regression_test.go index 7eab644614..2452f05bcd 100644 --- a/seaweed-block/core/ops/delete_safety_untimed_regression_test.go +++ b/seaweed-block/core/ops/delete_safety_untimed_regression_test.go @@ -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) + } + }) } } diff --git a/seaweed-block/docs/kubernetes-status.md b/seaweed-block/docs/kubernetes-status.md index c68d1edd80..a128cd7dbb 100644 --- a/seaweed-block/docs/kubernetes-status.md +++ b/seaweed-block/docs/kubernetes-status.md @@ -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.