BlockStore: gate walHead update on lsn > walHead (round-43 substrate hardening, defense-in-depth)

Pre-T4d-1 hotfix per architect-ratified kickoff sequencing
(round-44 governance call): substrate-level guard lands ahead of
the larger T4d-2 replica recovery apply gate work. Closes a
production storage-contract violation independent of the larger
T4d batch.

Bug (round-41 architect-identified, round-43 demo-confirmed):

  core/storage/store.go:264 set s.walHead = lsn unconditionally.
  Older-LSN ApplyEntry regressed walHead, violating
  LogicalStorage contract §3 rule 3 ("stable frontier never goes
  backward").

  Empirically demonstrated live at round-43:
    ApplyEntry(LSN=10) → walHead=10
    ApplyEntry(LSN=5)  → walHead=5  ← REGRESSION

Fix:

  if lsn > s.walHead {
      s.walHead = lsn
  }

Same monotonic-update pattern as walstore.ApplyEntry:544 and
smartwal.ApplyEntry:358 already use. Brings BlockStore in line.

Architectural placement (round-43 sign):

  Replica recovery apply gate (T4d-2 primary fix) is the primary
  correctness boundary; this guard is defense-in-depth for paths
  that may bypass the gate (live duplicate, retry, future
  cross-substrate scenarios). Inline godoc comment names the
  T4d-2 gate as the primary boundary so the role is clear.

Test (un-skipped from round-41/43 adversarial set):

  TestComponent_BlockStore_ApplyEntry_OldLSN_DoesNotRegressWalHead
  (renamed from TestComponent_Adversarial_BlockStoreApplyEntry
  RegressesWalHead — the bug name no longer applies).

  Pre-fix: t.Skip + T4d TODO. Post-fix: passes; pins the
  monotonic guard against regression.

Zero semantic change to any code that worked before. T4d-1 / T4d-2
will not conflict with this hotfix — different files, different
layers.

go test ./... -count=1 → 22 packages green (regression test
passes; no other test affected).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 4.7 committed 2026-04-25 15:52:39 -07:00
1 parent 360e540c76
commit dea8481bb6
2 files changed
+22 -13

No files matched your search

@@ -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.
+11 -1
View File
@@ -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
}