diff --git a/seaweed-block/core/storage/chunk_coverage.go b/seaweed-block/core/storage/chunk_coverage.go index 51376f141e..6c85c5df17 100644 --- a/seaweed-block/core/storage/chunk_coverage.go +++ b/seaweed-block/core/storage/chunk_coverage.go @@ -139,6 +139,12 @@ func (s *WALStore) InitializeChunkCoverage(ctx context.Context, epoch uint64, se s.mu.RUnlock() return fmt.Errorf("%w: initialize coverage during BASE install or reset", errDescriptorTransition) } + shapeDescriptor := current + shapeDescriptor.MapFormatID = mapFormatIDCoverage + if _, err := mapShapeForV3(shapeDescriptor, v.ownedMap.chunkBlocks); err != nil { + s.mu.RUnlock() + return err + } if current.ChunkStateFormat != 0 { if current.LocalWorkEpoch != epoch { s.mu.RUnlock() diff --git a/seaweed-block/core/storage/chunk_coverage_map.go b/seaweed-block/core/storage/chunk_coverage_map.go index d4cb8140df..82a9cf2428 100644 --- a/seaweed-block/core/storage/chunk_coverage_map.go +++ b/seaweed-block/core/storage/chunk_coverage_map.go @@ -234,9 +234,6 @@ func readCoverageMapPagesV3(f *os.File, d descriptorV3, cb uint64, shape mapShap e.Local.words[bit/64] |= uint64(value) << (bit % 64) } } - if progress != nil { - progress.advance(end - start) - } } for i := range entries { e := &entries[i] @@ -245,6 +242,7 @@ func readCoverageMapPagesV3(f *os.File, d descriptorV3, cb uint64, shape mapShap } if e.Local == nil { e.Local = noChunkLocalBits + progress.advance(1) continue } for bit := e.Local.blocks; bit < cb; bit++ { @@ -261,6 +259,7 @@ func readCoverageMapPagesV3(f *os.File, d descriptorV3, cb uint64, shape mapShap if e.Local.count() == e.Local.blocks { e.Local = &chunkLocalBits{blocks: e.Local.blocks, all: true} } + progress.advance(1) } return entries, refs, nil } diff --git a/seaweed-block/core/storage/chunk_coverage_paged_test.go b/seaweed-block/core/storage/chunk_coverage_paged_test.go index b5ffcdc517..ab29cfce87 100644 --- a/seaweed-block/core/storage/chunk_coverage_paged_test.go +++ b/seaweed-block/core/storage/chunk_coverage_paged_test.go @@ -2,12 +2,63 @@ package storage import ( "bytes" + "context" "encoding/binary" + "errors" "io" "os" "testing" ) +func TestChunkCoverageMapProgressCountsValidatedEntries(t *testing.T) { + for _, badPadding := range []bool{false, true} { + d := descriptorV3{BlockSize: 4096, VolumeSize: 9 * 4096, MapFormatID: mapFormatIDCoverage, MapGeneration: 3, MapRootLocator: 4096} + d.UUID[0], d.MapLineage[0] = 1, 2 + entries := []chunkLSNEntryV3{{Local: noChunkLocalBits}, {Local: noChunkLocalBits}, {Local: noChunkLocalBits.mark(0, 1)}} + leaf, err := encodeCoverageMapPageV3(d, 3, 0, 4, entries, 0) + if err != nil { + t.Fatal(err) + } + if badPadding { + leaf[64+2*17+16] |= 0x80 // not an addressable block of the short last chunk + } + hash := mapDigestV3(mapPageDomainV3, leaf[:4064]) + copy(leaf[4064:], hash[:]) + root, _, err := encodeCoverageTreeRootV3(d, 3, 4, 0, []mapPageRefV3{{Hash: hash}}, nil, 0, func([]byte) (uint64, error) { + t.Fatal("small map unexpectedly needs an index") + return 0, nil + }) + if err != nil { + t.Fatal(err) + } + f, err := os.CreateTemp(t.TempDir(), "progress-map") + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { f.Close() }) + if _, err := f.Write(append(leaf, root...)); err != nil { + t.Fatal(err) + } + var observed uint64 + reporter := newRecoveryReporter(WithRecoveryProgress(context.Background(), func(phase RecoveryPhase, done uint64) { + if phase != RecoveryOpenMap { + t.Fatal("unexpected progress phase") + } + observed = done + }), RecoveryOpenMap) + shape, _ := mapShapeForV3(d, 4) + _, _, err = readCoverageMapPagesV3(f, d, 4, shape, root, 8192, reporter) + reporter.finish() + want := uint64(3) + if badPadding { + want = 2 + } + if observed != want || (badPadding && !errors.Is(err, ErrMapInvalid)) || (!badPadding && err != nil) { + t.Fatalf("padding=%v: completed=%d want=%d err=%v", badPadding, observed, want, err) + } + } +} + // This independent, test-only reader pins the format's paging boundary. The // production reader deliberately remains eager; no cache or runtime API is added. func coverageEntryByPath(t *testing.T, f io.ReaderAt, rootOffset, chunk, cb uint64) ([]byte, int) { diff --git a/seaweed-block/core/storage/chunk_coverage_test.go b/seaweed-block/core/storage/chunk_coverage_test.go index d7d47ccbc7..e1e934b7d5 100644 --- a/seaweed-block/core/storage/chunk_coverage_test.go +++ b/seaweed-block/core/storage/chunk_coverage_test.go @@ -268,6 +268,115 @@ func TestChunkCoverageSeedsPartialWholeAndLastShortChunk(t *testing.T) { func coverageNoPages(ChunkCoverageReader) error { return nil } +func TestChunkCoverageLegacyFenceCannotRelabelAnInitializedEpoch(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + s.HoldExtentDrainUntilChunkLayer() + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + if err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { + return ChunkCoverageSeed{Blocks: []uint64{1}}, nil + }, coverageNoPages); err != nil { + t.Fatal(err) + } + before := s.v3.pub.current() + for _, epoch := range []uint64{8, 6} { + var mismatch *ChunkCoverageEpochMismatchError + if err := s.FenceChunkStateUpgrade(epoch); !errors.As(err, &mismatch) || mismatch.StoredEpoch != 7 || mismatch.RequestedEpoch != epoch { + t.Fatalf("legacy fence relabeled coverage epoch %d: %v", epoch, err) + } + if s.v3.pub.current() != before { + t.Fatal("refused legacy fence changed descriptor") + } + } + if err := s.FenceChunkStateUpgrade(7); err != nil { + t.Fatalf("same epoch confirmation refused: %v", err) + } +} + +func TestChunkCoverageBaselineCannotOutliveItsRetainedWAL(t *testing.T) { + for _, damaged := range []bool{false, true} { + t.Run(fmt.Sprint(damaged), func(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + s.HoldExtentDrainUntilChunkLayer() + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + if err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { + return ChunkCoverageSeed{}, nil + }, coverageNoPages); err != nil { + t.Fatal(err) + } + if _, err := s.Write(0, blk(0x61)); err != nil { + t.Fatal(err) + } + off, _, _, _, ok := s.dm.get(0) + if !ok { + t.Fatal("write missing from WAL") + } + prepared, err := s.prepareOwnedMapCheckpointV3(0) + if err != nil { + t.Fatal(err) + } + if _, err := s.v3.pub.publishMapV3(&s.mu, nil, prepared, nil); err != nil { + t.Fatal(err) + } + if s.v3.pub.current().W != 0 || s.v3.pub.mapCurrent.entries[0].LSN != 1 { + t.Fatal("control did not persist a bitmap ahead of W") + } + if damaged { + if _, err := s.fd.WriteAt([]byte{0x62}, int64(s.sb.WALOffset+off+walEntryPrefixSizeV3)); err != nil { + t.Fatal(err) + } + } + _, err = s.Recover() + if damaged { + if !isWALCorrupt(err) { + t.Fatalf("coverage baseline survived discarded WAL: %v", err) + } + if _, _, err := s.Coverage(0); !errors.Is(err, ErrChunkCoverageUnavailable) { + t.Fatalf("failed recovery exposed bitmap: %v", err) + } + return + } + if err != nil { + t.Fatal(err) + } + got, pos, err := s.Coverage(0) + if err != nil || got != CoverageSome || pos != 1 { + t.Fatalf("intact retained WAL lost coverage: %v/%d %v", got, pos, err) + } + data, readErr := s.Read(0) + if readErr != nil || string(data) != string(blk(0x61)) { + t.Fatalf("intact retained bytes differ: %v", readErr) + } + }) + } +} + +func TestChunkCoverageAdmissionPrecedesSeed(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + s.HoldExtentDrainUntilChunkLayer() + if _, err := s.Recover(); err != nil { + t.Fatal(err) + } + // Inject the oversized shape at the admission boundary, avoiding an actual + // multi-gigabyte legacy fixture just to prove callbacks have not begun. + before := s.v3.pub.cur + cb := s.v3.ownedMap.chunkBlocks + s.v3.pub.cur.VolumeSize = 34_000_000 * 64 * 4096 + s.v3.ownedMap.chunkBlocks = 64 + defer func() { s.v3.pub.cur = before; s.v3.ownedMap.chunkBlocks = cb }() + calls := 0 + err := s.InitializeChunkCoverage(context.Background(), 7, func(uint64, uint64) (ChunkCoverageSeed, error) { + calls++ + return ChunkCoverageSeed{}, nil + }, coverageNoPages) + if !errors.Is(err, ErrMapInvalid) || calls != 0 { + t.Fatalf("oversized initialization began seed: calls=%d err=%v", calls, err) + } +} + func TestChunkCoveragePreparedViewPrecedesTheFence(t *testing.T) { s, _ := newMappedCheckpointStoreV3(t) s.HoldExtentDrainUntilChunkLayer() diff --git a/seaweed-block/core/storage/chunk_lsn_map_v3.go b/seaweed-block/core/storage/chunk_lsn_map_v3.go index 19461d7235..2c03561170 100644 --- a/seaweed-block/core/storage/chunk_lsn_map_v3.go +++ b/seaweed-block/core/storage/chunk_lsn_map_v3.go @@ -334,8 +334,7 @@ func openChunkLSNMapV3Progress(path string, d descriptorV3, cb uint64, progress var metadata coverageMapMetadata es, refs, e := readChunkLSNMapV3Progress(f, d, cb, progress, &metadata) if e != nil { - f.Close() - return nil, nil, e + return nil, nil, errors.Join(e, f.Close()) } m := &chunkLSNMapV3{fd: f, identity: d, chunkBlocks: cb, lastGeneration: d.MapGeneration} m.initLiveV3() diff --git a/seaweed-block/core/storage/chunk_map_publication_v3.go b/seaweed-block/core/storage/chunk_map_publication_v3.go index 8bdcc27ce0..874b24b34c 100644 --- a/seaweed-block/core/storage/chunk_map_publication_v3.go +++ b/seaweed-block/core/storage/chunk_map_publication_v3.go @@ -216,8 +216,7 @@ func openDescriptorMapV3Progress(path string, selected descriptorV3, fallback *d } } if err != nil { - _ = m.Close() - return nil, nil, err + return nil, nil, errors.Join(err, m.Close()) } } return m, c, nil diff --git a/seaweed-block/core/storage/chunk_state_upgrade.go b/seaweed-block/core/storage/chunk_state_upgrade.go index 9ed10e0e5d..f793cb1df9 100644 --- a/seaweed-block/core/storage/chunk_state_upgrade.go +++ b/seaweed-block/core/storage/chunk_state_upgrade.go @@ -51,6 +51,9 @@ func (s *WALStore) fenceChunkStateUpgradeLocked(epoch uint64) error { if err := s.stickyIOFault(); err != nil { return err } + if p.cur.MapFormatID == mapFormatIDCoverage && p.cur.LocalWorkEpoch != epoch { + return &ChunkCoverageEpochMismatchError{StoredEpoch: p.cur.LocalWorkEpoch, RequestedEpoch: epoch} + } if p.cur.LocalWorkEpoch > epoch { return fmt.Errorf("%w: local-work epoch moved backwards", errDescriptorTransition) } diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index 0ae4bf944d..1af9b55246 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -649,6 +649,20 @@ func (s *WALStore) recoverV3(ctx context.Context) (uint64, error) { // speculative cache changes from a dropped suffix. if v.ownedMap != nil { v.pub.descMu.Lock() + if v.pub.mapCurrent.formatID() == mapFormatIDCoverage { + for index, entry := range v.pub.mapCurrent.entries { + if index%256 == 0 { + if err := ctx.Err(); err != nil { + v.pub.descMu.Unlock() + return 0, err + } + } + if entry.LSN > o.R { + v.pub.descMu.Unlock() + return 0, NewWALIntegrityFailure(nil, fmt.Sprintf("coverage chunk %d position %d exceeds retained WAL frontier %d", index, entry.LSN, o.R)) + } + } + } var err error v.mapEntries, err = copyRecoveryMap(ctx, v.mapEntries, v.pub.mapCurrent.entries) v.pub.descMu.Unlock() diff --git a/seaweed-block/docs/design/chunk-coverage.md b/seaweed-block/docs/design/chunk-coverage.md index 7adb7a95f3..726a93d674 100644 --- a/seaweed-block/docs/design/chunk-coverage.md +++ b/seaweed-block/docs/design/chunk-coverage.md @@ -1,10 +1,12 @@ # Durable chunk coverage (draft) +This draft specifies the storage-only target contract below. Its component tests do not establish daemon activation; the ledger remains STUB until that integration is qualified. + The store exposes `Coverage(chunk uint64) (LocalCoverage, uint64, error)`. The coverage and position are one observation under the store lock. Coverage is `CoverageNone`, `CoverageSome`, or `CoverageAll`; it describes local blocks, not equality with a remote reference. An uninitialized or unrecovered store -returns `ErrChunkCoverageUnavailable`. Failed recovery invalidates the answer. +returns `ErrChunkCoverageUnavailable`. Failed recovery invalidates the answer. A persisted chunk position above the retained WAL frontier refuses recovery with a WAL-integrity error; later LSN reuse cannot authorize those bits. ## Upgrade boundary @@ -25,7 +27,7 @@ initializer never calls seed: it rebuilds pages from the recovered bitmap. A marked store without a readable initialized bitmap refuses as unavailable. A marker at another epoch returns `ChunkCoverageEpochMismatchError` before calling either callback or writing storage. Attach-after-move owns Drop and -the new epoch; this initialization API cannot reset or reseed a marked store. +the new epoch; neither this initialization API nor the legacy fence can relabel an initialized coverage map. Failed or uncertain descriptor publication retains the existing fault latch and requires reopening. @@ -51,8 +53,7 @@ level, UUID, lineage, generation, first leaf index (offset 48), child count (offset 56), zero padding through offset 63, and references from offset 64. Their final 32 bytes hash the preceding 4064 bytes with domain `swblock:chunk-map:index:v2\0`. Root and leaf hashes retain their existing -domains. A zero locator AND zero hash is a virtual subtree: every entry has -the root's default position, Unknown true, and no local bits. A physical page +domains. A zero locator AND zero hash is a virtual subtree: the reader supplies the root-defined default byte at each entry-relative offset covered by that subtree. Bytes supplied by other leaves remain unchanged. A physical page at locator zero has a nonzero hash. Virtual references pin no file extent. Unchanged leaves and index branches are shared across roots. New leaves are @@ -78,7 +79,7 @@ until a paged implementation is qualified. flowchart TD A[Selected slot map] --> B{Intact?} B -->|yes| C[Open selected slot] - B -->|no| D{Selected marked; other valid, unmarked and intact?} + B -->|no| D{Integrity-only failure; selected marked; same incarnation; other valid, unmarked and intact?} D -->|yes| E[Open legacy slot; restart recovery and upgrade] D -->|no| F[Refuse open] ``` diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 87747ca8f9..adaf34bcb1 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -56,7 +56,7 @@ stateDiagram-v2 [*] --> Opened: OpenWALStore / CreateWALStore [*] --> CreateRefused: CreateWALStore without local headroom (free < size + WAL) [*] --> CreateRefused: chunk volume, create mode: geometry flags disagree with the volume record, or the record is not read - [*] --> Opened: half-fence marked map damaged, other slot valid unmarked and intact; restart legacy recovery + [*] --> Opened: half-fence marked map integrity failure, same-incarnation other slot valid unmarked and intact; restart legacy recovery Opened --> Recovering: RecoverVolume Recovering --> Serving: Recover ok, backend operational; workspace primary: lease held, then HEAD claim, then frontends listen, then ready Serving --> Closed: runtime HEAD fence, exit 78 head_fenced @@ -71,7 +71,7 @@ stateDiagram-v2 | From | To | Guard | Enforced in | Protects | |---|---|---|---|---| -| — | Opened | v3 A/B descriptors and owned-map dependencies valid (or the selected marked map fails and the other valid unmarked half-fence slot has an intact map); exclusive file ownership acquired; legacy formats refused; backend starts not operational | `core/storage/walstore.go` `OpenWALStoreWithOptions`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-WAL-OPGATE-001`, `INV-WAL-V3-ACTIVATION-001`, `INV-WAL-V3-DESCRIPTOR-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-CHUNK-HALF-FENCE-FALLBACK-001` | +| — | Opened | v3 A/B descriptors and owned-map dependencies valid (or the selected marked map has an integrity-only failure and the same-incarnation valid unmarked half-fence slot has an intact map); exclusive file ownership acquired; legacy formats refused; backend starts not operational | `core/storage/walstore.go` `OpenWALStoreWithOptions`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-WAL-OPGATE-001`, `INV-WAL-V3-ACTIVATION-001`, `INV-WAL-V3-DESCRIPTOR-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-CHUNK-HALF-FENCE-FALLBACK-001` | | — | CreateRefused | a new volume needs the durable root's free space >= its size + WAL (a lab build, tag `swblock_lab_bigvol`, only warns), checked before the store, its WAL or its fresh marker is created (the replica floor, written when the assignment arrives, precedes the check and stays); the refusal ends the process with status 1; an existing volume opens and warns when its remaining data growth + WAL exceed the free space | `core/frontend/durable/headroom.go`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-LOCAL-HEADROOM-001` | | — | CreateRefused | a chunk volume in create mode (no local store yet): before the provider is built, the geometry flags are compared with the volume record; they disagree, or the record is there but does not decode: exit 78; the filer failed the read: exit 75; nothing is created; an absent record keeps the create path; an existing store is never rechecked against the flags | `cmd/blockvolume/main.go` (create-mode check); `cmd/blockvolume/chunk_remote.go` `geometryFlagsRefusal` | `INV-VOL-GEOMETRY-FLAGS-RECORD-001` | | Opened | Recovering | the volume is open in the provider | `core/frontend/durable/provider.go` `RecoverVolume` | `INV-WAL-OPGATE-001`, `INV-RECOVERY-PROGRESS-WINDOW-001` | @@ -619,10 +619,10 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-CHUNK-UPGRADE-PASS-CURSOR-001` | Upgrade pass: rewinds only at open, before Run; a failed rewind latches it until reopen; the persisted cursor is only ever min(earliest unpublished rewind, last written-through position); a restart resumes there; while it runs, a request needing every hash answers in_progress. | M1 Opened (v1.1 upgrade compare pass) | `core/storage/chunk_upgrade_pass.go` `upgradePass.Run`, `advance`, `Rewind`, `Admit` | `TestUpgradePassCursorFollowsThePagesBehindIt`, `TestUpgradePassRestartContinuesAtTheCursor`, `TestUpgradePassRefusesWithProgress`, `TestUpgradePassRewindAtOpenAfterARebuiltPage`, `TestUpgradePassPauseAndHurry`, `TestUpgradePassFailedRewindLatchesUntilReopen`, `TestUpgradePassRewindOnlyBeforeRun`, `TestUpgradePassKeepsItsCountAcrossRuns`, `TestUpgradePassCursorRuleUnderInterleavings` (`core/storage/chunk_upgrade_pass_test.go`) | UpgradePass `BehindCursorKnown`, `NoWorkTwice`; UpgradeWide3 rows 119 to 124, rewinds at restart only (the per-chunk state models are not in this repository) | STUB | | `INV-CHUNK-RECORD-RUNTIME-001` | While serving: state only via the kernel, a known hash only with its evidence; a page dirties only when a state or hash changes, is written by its own count or age, an evict's at once, in snapshot order; header G = min(applied, dirty pages' dirty-from). | M3 Serving (chunk record runtime) | `core/storage/chunk_record_runtime.go` `chunkRecordRuntime.Apply`, `Due`, `WriteDue`, `WriteThrough`, `Flush` | `TestRecordRuntimeAppliesTheKernel`, `TestRecordRuntimeEvictWritesThePageFirst`, `TestRecordRuntimeSchedulePerPage`, `TestRecordRuntimeFlushIsLoadedBack`, `TestRecordRuntimeWriteThrough`, `TestRecordRuntimeAnUnchangedStateWritesNothing`, `TestRecordRuntimeHeaderMovesUnderWrites`, `TestRecordRuntimeEvictDuringAFlushLandsLast`, `TestRecordRuntimePageWritesFollowChangesNotSize`, `TestRecordRuntimePageWritersPublishInOrder`, `TestRecordRuntimeHashEvidence`, `TestRecordRuntimeCopiesItsInputs`, `TestRecordRuntimeAPageChangedAtOpenHoldsG` (`core/storage/chunk_record_runtime_test.go`) | chunk-kernel/2; ChunkPages rule 1 (pages before the header) and rule 3 (an evict writes its page first) (the per-chunk state models are not in this repository) | STUB | | `INV-CHUNK-RECORD-PAYLOAD-001` | Persisting and loading a chunk record preserves every entry's state and hash, including entries on either side of a segment boundary. | M1 chunk record codec (caller not wired) | `core/storage/chunk_record.go` `encodeChunkRecordPage`, `decodeChunkRecordPage` | `TestRecordEntryPayloadRoundTripsAcrossSegments` (`core/storage/chunk_record_test.go`; state-zero and one-entry hash-drop controls) | Encoding fidelity; no state transition change | STUB | -| `INV-CHUNK-LOCAL-COVERAGE-001` | Coverage returns local none/some/all and the chunk position from one observation; it is unavailable until successful recovery and bitmap initialization. | M1 chunk bitmap (caller not wired) | `core/storage/chunk_coverage.go` `WALStore.Coverage`, `WALStore.InitializeChunkCoverage` | `TestChunkCoverageInitializesEmptyWithoutFabricatingLocalBlocks`, `TestChunkCoverageAcknowledgedWriteSurvivesReplay`, `TestChunkCoverageCheckpointKeepsAllAcrossAPageBoundary`, `TestChunkCoverageRequiresSuccessfulRecovery` (`core/storage/chunk_coverage_test.go`) | MoveWide2 durable per-block map premise; SlotFence publication | STUB | -| `INV-CHUNK-LOCAL-EPOCH-001` | After a format marker, initialization never reads legacy presence: the same epoch rebuilds pages from the bitmap; another epoch is refused without changing storage. | M1 bitmap initialization (caller not wired) | `core/storage/chunk_coverage.go` `WALStore.InitializeChunkCoverage` | `TestChunkCoverageMarkedEpochNeverReseedsPresence`, `TestChunkCoverageMarkerWithoutBitmapCannotReadPresence` (`core/storage/chunk_coverage_test.go`) | SlotFence marker authority; UpgradeWide3 | STUB | +| `INV-CHUNK-COVERAGE-RETAINED-001` | A coverage-map baseline is installed by recovery only when every chunk position is at or below the retained WAL frontier; a discarded suffix cannot regain local bits through later LSN reuse. | M1 recovery (caller not wired) | `core/storage/walstore_v3.go` `WALStore.recoverV3` | `TestChunkCoverageBaselineCannotOutliveItsRetainedWAL` | SlotFence2 position-check premise; storage component guard | STUB | +| `INV-CHUNK-LOCAL-COVERAGE-001` | Coverage returns local none/some/all and the chunk position from one observation; it is unavailable until successful recovery and bitmap initialization. | M1 chunk bitmap (caller not wired) | `core/storage/chunk_coverage.go` `WALStore.Coverage`, `WALStore.InitializeChunkCoverage` | `TestChunkCoverageBaselineCannotOutliveItsRetainedWAL`, `TestChunkCoverageAdmissionPrecedesSeed`, `TestChunkCoverageInitializesEmptyWithoutFabricatingLocalBlocks`, `TestChunkCoverageAcknowledgedWriteSurvivesReplay`, `TestChunkCoverageCheckpointKeepsAllAcrossAPageBoundary`, `TestChunkCoverageRequiresSuccessfulRecovery` (`core/storage/chunk_coverage_test.go`) | MoveWide2 durable per-block map premise; SlotFence publication | STUB | +| `INV-CHUNK-LOCAL-EPOCH-001` | After a format marker, initialization never reads legacy presence: the same epoch rebuilds pages from the bitmap; another epoch is refused without changing storage. | M1 bitmap initialization (caller not wired) | `core/storage/chunk_coverage.go` `WALStore.InitializeChunkCoverage` | `TestChunkCoverageLegacyFenceCannotRelabelAnInitializedEpoch`, `TestChunkCoverageMarkedEpochNeverReseedsPresence`, `TestChunkCoverageMarkerWithoutBitmapCannotReadPresence` (`core/storage/chunk_coverage_test.go`) | SlotFence marker authority; UpgradeWide3 | STUB | | `INV-CHUNK-HALF-FENCE-FALLBACK-001` | A damaged selected marked map may fall back only on integrity-only errors, to an intact valid unmarked slot of the same store incarnation; two marked slots never authorize fallback. Each successful fallback reports a typed event and one process-local counter increment. | M1 half-fence open (caller not wired) | `core/storage/walstore_v3.go` `openWALStoreV3File`, `coverageHalfFenceFallbackEligible` | `TestChunkCoverageHalfFenceReusedMapOpensTheIntactLegacySlot`, `TestChunkCoverageBothMarkedDamagedMapNeverFallsBack` (`core/storage/chunk_coverage_test.go`) | SlotFence2.OpenNew | STUB | - | `INV-WAL-V3-DESCRIPTOR-SELECT-001` | Of the two v3 descriptor slots, open selects the valid selectable slot with the higher slotGen, and never a prepared migration slot. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `selectSlotV3` | `TestSlotV3Selection` (`core/storage/superblock_v3_test.go`); `TestWALStoreV3CloseKeepsTheNewestSlotAAndItsW` (`core/storage/walstore_close_v3_test.go`) | — | ACTIVE | | `INV-WAL-V3-DESCRIPTOR-CONFLICT-001` | Open is refused when both v3 descriptor slots are valid but carry the same slotGen with different bytes, or disagree on the UUID or the geometry. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `selectSlotV3`, `sameGeometryV3` | `TestSlotV3Selection` (`core/storage/superblock_v3_test.go`) | — | ACTIVE | | `INV-WAL-V3-RECORD-001` | An impl-3 WAL record has a fixed 62-byte prefix, 70 bytes of overhead in all, a CRC32C (Castagnoli) and an explicit EntrySize. | M1 v3 record framing | `core/storage/wal_entry_v3.go` `encodeWALEntryV3`, `payloadSizeV3` | `TestWALEntryV3_CanonicalBarrierBytes`, `TestWALEntryV3_TypeFootprints` | `WALRecovery` abstract record validity; physical byte rules are code-test obligations | ACTIVE |