Hardware-validated diagnosis of the scenario #5/#6 "engine retry/escalate
gap" QA flagged: the bridge's onStart/onClose lambdas in
NewBlockExecutorWithDualLane built SessionStartResult /
SessionCloseResult WITHOUT the ReplicaID field. The engine's
checkReplicaID dropped both events as `wrong_replica` ("event for ,
engine owns r2"), so Session.Phase stuck at Starting forever,
hasActiveSession returned true permanently, and every subsequent
post-completion StartRebuild dispatch was silently suppressed.
This explained QA's pattern: probe r2 success R=0 S=1 H>>0 → engine
correctly classifies as Decision=rebuild (verified by adapter trace
{decision rebuild (R < S)}) but emits zero commands because of the
phase-stuck guard. The peer's runtime state diverged from the engine's
session truth: peer.SetState(Healthy) fires on the executor callback
side (which never checks ReplicaID) but engine.Apply rejects.
Scenario #2 "succeeded" only because peer.SetState(Healthy) is enough
for the harness's wait_until_peer_healthy check; the engine's session
state was already broken at that point. Scenarios #5/#6 needed a
second rebuild and that's where the bug surfaced.
Hardware result post-fix:
G7 #2: dispatch=3s, complete=3s, total=6s — GREEN.
G7 #5: rebuild dispatches in 2s (was: never dispatched). New failure
is at byte-equal verify (498 mismatches over 5500 LBAs) — the
concurrent-writes-during-rebuild seam (T4 wire-fromLSN vs
shipper-anchor split) flagged in v3-rebuild-from-lsn-pin-
clarification §4. Out of scope of this fix.
Adapter diagnostic logs (`g7-debug:`) added in core/adapter/adapter.go
that pinpointed the bug — left in for QA verification of next run.
Will gate them or remove in a follow-up commit once stable.
Anchor: hardware trace g7-20260502T012553Z primary-fail.log line
"trace=[{event SessionStarted} {wrong_replica event for , engine
owns r2}]" — the empty ReplicaID being dropped.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Hardware-validated fix for the silent rebuild stall on 40da4c8. Three
coordinated changes that close the gap between unit-test-green and
hardware-completing dual-lane rebuild:
1. **`startRebuildDualLane` — sentinel translation**
Caller passed `fromLSN=0` to the bridge, taken literally by
`WalShipper.StartSession(0)`. On a primary that's been running,
the WAL retention floor is at `checkpointLSN` (entries through
the checkpoint are durable in the extent and the WAL ring has
recycled past 0); `ScanLBAs(0)` immediately returns
`ErrWALRecycled`, the wal goroutine errors, sender exits before
barrier emission, hardware silently stalls.
Fix: pass `sessionFromLSN = targetLSN` (the snapshot pin). Base
lane covers the snapshot through the checkpoint, WAL drain has
nothing to ship at the pin (cursor==head), live writes during
the session flow via NotifyAppend on the steady-state path.
2. **`WalShipper.DrainBacklog` — cursor-caught-up shortcut**
At the dual-lane bootstrap with `cursor == fromLSN == targetLSN
== primary head`, the loop entered ScanLBAs and hit the recycle
gate. Add an early shortcut: if `cursor >= head` at iter start,
skip ScanLBAs and try the R1 transition directly.
3. **`RebuildSession.SeedWalApplied` + receiver wiring**
For a base-only rebuild (WAL drain ships nothing), `walApplied`
stayed at 0; `TryComplete`'s `walApplied >= targetLSN` conjunct
could never hold. Seed it with `fromLSN` at SessionStart so the
predicate satisfies after `MarkBaseComplete` + `WitnessBarrier`.
4. **`executor.go` dual-lane onClose — completion marker**
QA harness `wait_until_rebuild_complete` greps for
`executor: rebuild complete, sent N blocks (targetLSN=N)` —
emitted only by the legacy `doRebuild` path. Mirror it on the
dual-lane bridge's onClose callback so the harness recognizes
completion identically across modes.
Hardware result (G7 #2 — empty replica join, 1000 LBAs):
rebuild dispatched in 1s, completed in 1s after dispatch
(total 2s), 1000 LBAs byte-equal verified post-rebuild.
Markers fired: `barrier prepare ... WalLegOk=true` +
`barrier handshake ... match=true` + peer state
`catching_up → healthy`.
Known seam (out of scope, T4-during-live-writes):
When live writes arrive during the session, the receiver's T4
monotonic checker expects `lsn == appliedWalLSN+1` where
`appliedWalLSN` is seeded to `fromLSN`. Live writes get LSNs
starting at `fromLSN`, breaking T4. Resolving this requires
splitting the wire-fromLSN (T4 expectation) from the
shipper-anchor (DrainBacklog cursor) — separate work. The
hardware harness's scenario #5 (concurrent writes during
rebuild) hits an unrelated probe-loop dispatch issue first
and never gets to exercise this seam.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the recover(a,b) sole completion gate (`walApplied >=
TargetLSN`) at both Tier-1 sites with the §IV.2.1 realizable conjunct
synthesized from existing observables (ProbeBarrierEligibility witness
+ baseDone + barrier round-trip). Per recover-semantics-adjustment-plan
§1, "session semantically complete" claim moves from replica-side
verdict to coordinator-owned authority on the primary.
Tier-1 sites updated:
RebuildSession.TryComplete (replica, layer-1):
baseDone ∧ walApplied >= targetLSN ∧ barrierWitnessed
PeerShipCoordinator.CanEmitSessionComplete (primary, system close):
phase != Idle ∧ baseDone ∧ achieved >= targetLSN
∧ (walLegOkWitnessed → walLegOkAtBarrier)
Mechanics:
- Receiver latches RebuildSession.WitnessBarrier() on frameBarrierReq
arrival, BEFORE TryComplete. BarrierReq arrival = primary attests
PrimaryWalLegOk under shipMu (§IV.2.1 disjunction).
- Sender records PrimaryWalLegOk witness via
Coordinator.RecordBarrierWalLegOk(walLegOk) immediately after the
ProbeBarrierEligibility snapshot, BEFORE writing frameBarrierReq.
- Bridging-sink path (no probe) leaves walLegOkWitnessed=false; the
conjunct collapses to legacy (back-compat preserved while §IV.2.1
probe wiring is dual-lane-only). Test coverage in
TestRecoverA_BridgingSinkPath_LegacyCollapse pins this.
A-class conformance stubs unskipped (recover_a_conformance_test.go):
A1 TestRecoverA_DebtZeroPath_BarrierEligible SKIP→GREEN
A2 TestRecoverA_LiveTailPath_BarrierEligible… SKIP→GREEN
A3 TestRecoverA_Disjunction_EitherPathSuffices SKIP→GREEN
A4 TestRecoverA_NeitherPath_NotEligible SKIP→GREEN
+ TestRecoverA_BridgingSinkPath_LegacyCollapse GREEN (new)
A4 binding: walLegOk=false witness → CanEmit refuses → sender returns
FailureContract on close. Wire-level emission gating (§IV.2.2 stronger
"MUST NOT be emitted") is the B-class barrierEmitFreeze wave — out of
scope. A-class pins the binding at the close gate.
C-class still SKIP (CheckpointCutSeq on wire, achieved-as-cut-witness).
Y kept as comparator pre-C-class (`achieved >= targetLSN` retained;
"Y as enumerator only" defers to C-class wave).
Whole-tree go test ./... -count=1 green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds Receiver.appliedWalLSN/recvFromLSN tracking and checkMonotonic /
enforceWalWireMonotonic per §IV.0 T4 (recover-semantics-adjustment-plan
§7 v3.28 substrate-mode carve-out).
Behavior:
- SessionStart seeds recvFromLSN=appliedWalLSN=FromLSN.
- Each frameWALEntry runs enforceWalWireMonotonic before ApplyWALEntry.
- RecoveryModeWALReplay: requires lsn == appliedWalLSN+1; gap returns
FailureContract; exact-duplicate / backward returns FailureProtocol.
- StateConvergence (smartwal ScanLBAs): skipped — frontier LSN may
legitimately repeat across many RecoveryEntry payloads.
Tests:
- TestReceiver_checkMonotonic_T4: forward / duplicate / gap / backward.
- TestReceiver_checkMonotonic_boundaryDup: lsn==FromLSN before any
apply is a Protocol failure (not a no-op).
Authored by architect; submitted on user request.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
First behavioral wave of the recover(a) migration now that Gate G0 is
closed. OBSERVABILITY ONLY — no completion-predicate replacement,
no semantic change to BarrierReq emission gating. The recover(a,b)
band path stays GREEN as today; this commit adds the §IV.2.1
PrimaryWalLegOk observation tuple and Option B cutID counter so QA's
hardware oracle (§8.2.6) can wire round-trip grep in parallel with
A/B/C-class implementation.
Anti-discipline checks (§8.2.8) honored:
- All 5 marker fields per the §8.2.6 schema (no simplification).
- Conformance stubs in core/recovery/recover_a_conformance_test.go
remain SKIPPED — predicate replacement is the A-class wave.
Substrate changes:
WalShipper (core/transport/wal_shipper.go):
+ firstLiveEmitted atomic.Bool — set on first EmitKindLive emit
(fast-path or post-CASE-A residual); reset on StartSession.
Implements PrimaryLiveTail's per-session monotonic property.
+ ProbeBarrierEligibility() — single-shot snapshot under shipMu
returning (debtZero, liveTail, walLegOk, cursor, head). The
§IV.2(2) guard is simplified at this layer to "ever emitted
Live" — component-layer exercises the real guard.
RecoverySink (core/transport/recovery_sink_adapter.go):
+ ProbeBarrierEligibility delegate — duck-types the
barrierEligibilityProbe interface in core/recovery so the
dual-lane production path can populate marker logs.
PeerShipCoordinator (core/recovery/peer_ship_coordinator.go):
+ barrierAttempt counter on peerShipState — increments per
NextBarrierCut call within a session; resets to 0 at
StartSession (per architect Option B in plan §8.2.6).
+ NextBarrierCut(replicaID) (cutID, error) — first call per
session yields 1; pre-§IV.2.4 wire change this is a
coordinator-local sequence; post-C-class it becomes the
wire CheckpointCutSeq with no log-prefix change.
Sender.Run (core/recovery/sender.go):
+ barrierEligibilityProbe interface (optional, sink-side).
+ Two log lines per BarrierReq round-trip (5 fields each per
§8.2.6 schema):
replication: barrier prepare replica=<id> sessionID=<n>
cut=CCS:<cutID> PrimaryDebtZero=<bool> LiveTail=<bool>
WalLegOk=<bool> cursor=<n> head=<n>
replication: barrier handshake cut=CCS:<cutID>
achieved=<n> match=<bool>
Pre-C-class `match=true` unconditionally — the same cutID
flows from prepare to handshake by construction. Post-C-class
becomes the real wire-vs-engine compare.
+ Markers fire only on the dual-lane production path (sink
implements barrierEligibilityProbe); bridging-sink path
doesn't emit them — pre-§IV.2.1 markers are dual-lane-only
per the §8.2.6 hardware oracle scope.
Tests:
core/transport/probe_barrier_eligibility_test.go (new):
- FreshShipper_DebtZero — at construction, cursor==head==0,
walLegOk via debtZero.
- LiveEmitFlipsLiveTail — fast-path Live emit sets liveTail
monotonically.
- StartSessionResetsLiveTail — per-session monotonic reset
contract.
core/recovery/peer_ship_coordinator_test.go:
+ TestCoordinator_NextBarrierCut_MonotonicPerSession —
first-call-yields-1, monotonic increment, per-session reset
on StartSession-after-EndSession.
What this commit does NOT do (waiting for A-class wave):
- Replace `walApplied >= TargetLSN` predicate in TryComplete.
- Replace `achievedLSN >= targetLSN` in CanEmitSessionComplete.
- Replace Sender.Run's success-path FailureContract on
`achieved < target`.
- Add CheckpointCutSeq to BarrierReq/Resp wire payload.
- Un-skip conformance stubs.
Each of those is its own slice that turns ≥1 conformance stub
SKIP→GREEN as it lands.
Refs: recover-semantics-adjustment-plan.md §8.2 / §8.2.6
(Option B cutID); v3-recovery-algorithm-consensus.md §IV.2.1
(PrimaryDebtZero / LiveTail / WalLegOk); §I P8 (recover(a) vs
recover(a,b)). Companion to the QA→SW handoff commits 599f60e /
a08dea1 / faafa46.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Commit 3 of the QA→SW handoff (`recover-semantics-adjustment-plan.md`
§8.2.7 step 4). Adds 8 SKIPPED red-test anchors covering the three
G0-合同-unblockable categories from §8.2.5; D/E/F deferred until
G0-身份 + G0-wire close per the same section.
File: core/recovery/recover_a_conformance_test.go
Categories landed:
A. PrimaryWalLegOk disjunction (§IV.2.1) — 4 stubs:
- DebtZeroPath_BarrierEligible
- LiveTailPath_BarrierEligibleAfterEverEmittedLive
- Disjunction_EitherPathSuffices
- NeitherPath_NotEligible
B. Lock discipline at BarrierReq emission (§IV.2.2 barrierEmitFreeze)
— 2 stubs:
- BarrierReqUnderShipMu_NoInterleaveWithDriveEmits
(codifies the slice-2B Pillar2B race fix)
- BarrierImminentFlag_FreezesDriveEmits
(Option 3 from architect's lock-discipline trade-off)
C. AchievedLSN as cut-witness, not target-crossing (§IV.2.4)
— 2 stubs:
- AchievedLSN_PerCutWitness
- SuccessWith_AchievedLSN_BelowTarget
(codifies FS-4 reverse from §8.2.3 — Y as enumerator only)
Anti-discipline checks (§8.2.8) honored:
- Every t.Skip carries a reason citing §IV.2.1 / §IV.2.2 / §IV.2.4
+ the unblocking G0 sub-gate; no bare t.Skip.
- No production type imports (stubs only declare Skip; real test
bodies land alongside impl).
- D/E/F categories explicitly NOT included per §8.2.5.
Verified: go test runs the stubs as SKIP entries; commit 1's oracle
table tests still GREEN. The skip messages double as a TODO list
visible to anyone running `go test -v` against core/recovery.
Source: sw-block/design/recover-semantics-adjustment-plan.md §8.2.5.
Companion to commit 1 (`599f60e` dual-oracle table) and commit 2
(`a08dea1` legacy header annotation).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Commit 2 of the QA→SW handoff (`recover-semantics-adjustment-plan.md`
§8.2.7 step 3). Header-only annotation pass on the 19 _test.go
files in seaweed_block that reference `targetLSN` or `walApplied`
as completion-authority terms (discovery: `grep -rlE
'targetLSN|walApplied' --include='*_test.go' core/`).
Each file gets a 2-line header right after the package decl,
verbatim per §8.2.4:
// Completion oracle: recover(a,b) band — NOT recover(a) closure.
// See sw-block/design/recover-semantics-adjustment-plan.md §8.1.
Six of the 19 are deeply primary.H-bound (assertions tied to
`replica.H == primary.H` or `achieved == primary.H`) and get an
extra `migrate-candidate` line per §8.2.4:
// migrate-candidate: depends on primary.H semantics, see §8.1 Tier-5 migration
The migrate-candidate set:
- core/transport/pillar2_assembled_test.go
- core/transport/pillar3_convergence_test.go
- core/transport/walshipper_pin_protection_test.go
- core/transport/transport_test.go
- core/transport/catchup_sender_test.go
- core/recovery/e2e_test.go
Anti-discipline checks (§8.2.8) honored:
- No assertion changes — header text only.
- migrate-candidate kept on its own line, not merged with the
standard 2-line annotation.
Note on count: §8.2.4 cited "~95 files" against the broader audit
pattern (TargetLSN/AchievedLSN/FrozenTarget/TryComplete). The
narrower §8.2.4 grep (targetLSN|walApplied) targets the actual
completion-authority surface and yields 19 files in the
seaweed_block tree. Build + tests clean post-annotation.
Source: sw-block/design/recover-semantics-adjustment-plan.md §8.2.4.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>