diff --git a/seaweed-block/core/replication/component/stale_entry_adversarial_test.go b/seaweed-block/core/replication/component/stale_entry_adversarial_test.go index 286920763c..7b60558ff4 100644 --- a/seaweed-block/core/replication/component/stale_entry_adversarial_test.go +++ b/seaweed-block/core/replication/component/stale_entry_adversarial_test.go @@ -90,19 +90,18 @@ func TestComponent_Adversarial_StaleEntryDoesNotRegress(t *testing.T) { }) } -// TestComponent_Adversarial_BlockStoreApplyEntryRegressesWalHead -// pins the BlockStore bug architect identified in round-41: -// `BlockStore.ApplyEntry` does `s.walHead = lsn` unconditionally, -// so an older-LSN apply REGRESSES walHead. This contradicts the -// LogicalStorage contract (logical_storage.go §3 rule 3: "stable -// frontier never goes backward"). +// TestComponent_BlockStore_ApplyEntry_OldLSN_DoesNotRegressWalHead +// pins the round-43 substrate hardening fix at +// `BlockStore.ApplyEntry`. Pre-fix: `s.walHead = lsn` unconditional +// → older-LSN apply REGRESSES walHead, violating LogicalStorage +// contract §3 rule 3 ("stable frontier never goes backward"). +// Post-fix: `if lsn > s.walHead { s.walHead = lsn }`. // -// EXPECTED TO FAIL today. T4d (or a sooner BlockStore fix) must -// gate the walHead update on `lsn > walHead`. This test exists to -// surface the bug and gate the fix. -func TestComponent_Adversarial_BlockStoreApplyEntryRegressesWalHead(t *testing.T) { - t.Skip("Round-41 architect-identified bug: BlockStore.ApplyEntry sets walHead unconditionally; older-LSN apply regresses H. Un-skip when fixed.") - +// Pre-T4d-1 hotfix (round-44): substrate-level guard lands ahead of +// the larger T4d-2 replica recovery apply gate work. The gate is +// the primary correctness boundary; this guard is defense-in-depth +// for paths that may bypass the gate. +func TestComponent_BlockStore_ApplyEntry_OldLSN_DoesNotRegressWalHead(t *testing.T) { store := storage.NewBlockStore(64, 4096) // Apply LSN=10 first. diff --git a/seaweed-block/core/storage/store.go b/seaweed-block/core/storage/store.go index 2825d4d94a..0a15faf520 100644 --- a/seaweed-block/core/storage/store.go +++ b/seaweed-block/core/storage/store.go @@ -261,7 +261,17 @@ func (s *BlockStore) ApplyEntry(lba uint32, data []byte, lsn uint64) error { if lsn >= s.nextLSN { s.nextLSN = lsn + 1 } - s.walHead = lsn + // Round-43 substrate hardening (defense-in-depth): walHead is + // the "stable frontier never goes backward" boundary per + // LogicalStorage contract §3 rule 3. Older-LSN ApplyEntry must + // NOT regress walHead. The replica recovery apply gate (T4d-2 + // primary fix) prevents the older-LSN apply from reaching this + // path under recovery flow; this guard is the substrate-level + // safety net for any path that bypasses the gate (live duplicate, + // retry, future cross-substrate scenarios). + if lsn > s.walHead { + s.walHead = lsn + } return nil }