Commit Graph
12 Commits
Author SHA1 Message Date
pingqiu bd6f475b9b transport: advance live ship cursor after recovery 2026-05-01 23:53:34 -07:00
pingqiu ccc3ca6cb3 transport: route live WAL through single feed ingress 2026-05-01 23:24:55 -07:00
pingqiu 8c4aa52392 transport: refresh live ship session after recovery 2026-05-01 22:27:21 -07:00
pingqiu 3ccf2ec729 transport: gate live WAL through active recovery session 2026-05-01 22:03:12 -07:00
pingqiu 8d813f6ca1 G5-5C #6: end-to-end restart-catch-up component test + StopHard listener
Architect Batch #6 review 2026-04-27 ratified scope: end-to-end
wiring + convergence test, mirror G5-5 hardware step #4 without
iSCSI/iptables harness. 5 implementation constraints all addressed:

#1 determinism: bounded retries, 30 ms loop interval, 20 ms
   cooldown base, 200 ms cap, hard 8 s deadline on convergence
   wait. CI flake guard via 1.5 s no-convergence window in negative
   control test.

#2 kill semantic: ReplicaListener.Stop() blocks on wg.Wait waiting
   for active handler conns to drain, but on localhost the primary
   side never closes the live-ship conn so handlers block forever
   on ReadMsg. Added ReplicaListener.StopHard() that closes active
   conns BEFORE waiting; KillReplicaListener routes through it. The
   pre-existing Stop() semantics are preserved for the regular
   teardown path. Same-port rebind via NewReplicaListener retry
   loop with 2 s deadline (TIME_WAIT tolerance).

#3 probe path same as cmd/blockvolume: configureProbeLoopOnCluster
   uses volume.ProductionProbeFn (NOT a stub) → ConfigureProbeLoop
   → StartProbeLoop. The exact closure main installs in production.

#4 assertion layer: byte-equal convergence only — no engine R/S/H
   peeks. Architect ruling: "至少一条: ReplicaDegraded → probe →
   catch-up dispatched → frontier/byte-equal".

#5 no rebuild branch verification: test asserts convergence only,
   not which engine command was emitted. In this scenario the
   smartwal store's post-rebind boundaries land R<S so engine
   picks Rebuild; that's incidental, not a property the test pins.

Files:
- core/transport/replica.go: +StopHard method, +conns map for
  active-conn tracking; pre-existing Stop semantics unchanged.
- core/replication/component/cluster.go: KillReplicaListener now
  calls StopHard.
- core/replication/component/g5_5c_restart_catchup_test.go (new):
  - TestG5_5C_RestartCatchUp_Convergence: positive end-to-end test.
  - TestG5_5C_RestartCatchUp_NoConvergence_WithoutProbeLoop:
    negative control — same scenario without ConfigureProbeLoop
    must NOT converge in 1.5 s window. Without this control, the
    positive test could pass via some other accidental
    reconvergence pathway; this pin proves the probe loop is
    load-bearing.

Helpers (test-local):
- rebindReplicaListener: same-port restart with 2 s rebind retry.
- configureProbeLoopOnCluster: production wiring on cluster harness.
- drivePeerAdmit: AssignmentInfo + initial ProbeResult to reach
  Healthy.
- writeOneBlock: write through StorageBackend so WriteObserver
  fires (not direct store write).

Three-counter SessionID onboarding note (architect Batch #5 follow-up):
core/replication/peer.go now documents in code why three counters
exist (peerSessionID for live-ship; adapter probe counter for
engine-emitted ProbeReplica; probeSessionID for G5-5C runtime-
driven probes) and why none cross paths.

Test results:
- TestG5_5C_RestartCatchUp_Convergence: PASS (0.05 s)
- TestG5_5C_RestartCatchUp_NoConvergence_WithoutProbeLoop: PASS (1.54 s)
- Full ./... regression: PASS (every package, no behavioral
  regression on G5-4 / earlier T4 paths).

Next: m01 hardware run of iterate-m01-replicated-write.sh
verify_restart_catchup expecting #1/#2/#3 regression GREEN + #4
GREEN within deadline. After hardware GREEN, sw drafts §close.
2026-04-27 17:25:22 -07:00
pingqiu 59d63f8274 G5-5C #5: cmd/blockvolume flag wiring + production probeFn
Closes the wire between batch 1-4's runtime/engine plumbing and
operator/CLI control. Per architect Batch #5 review 2026-04-27,
each of the 4 self-check items is addressed:

#1 --degraded-probe-interval=0 = OFF
   Default value 0 keeps the loop disabled — preserves G5-4
   behavior. Help text states this explicitly. main.go's
   "if f.degradedProbeInterval > 0" guard means we NEVER call
   ConfigureProbeLoop with a 0 interval (which the loop itself
   would reject anyway via NewProbeLoop). Two layers of defense.

#2 cooldown-base/cap normalization
   ProbeLoopConfig defaults (5s base, 60s cap) match
   PeerProbeCooldown defaults exactly. NewProbeLoop normalizes
   <=0 to defaults; Cap < Base bumps Cap up to Base. CLI flag
   defaults are 5s/60s — matches batch 1/2 contract.

#3 production probeFn
   New file core/host/volume/probe_loop_wiring.go::ProductionProbeFn
   - peer.mu released before executor.Probe (loop discipline; the
     probeFn never touches peer.mu — only Target() which is
     immutable post-construction).
   - transport failure (result.Success == false) → returns non-nil
     err so DefaultProbeResultFn calls OnProbeAttempt(false) and
     backoff advances. Wire-success returns nil so cooldown resets
     to Base regardless of engine's semantic verdict.
   - adapter.OnProbeResult is fed BOTH success and failure facts
     (NormalizeProbe distinguishes). Engine async result NOT mixed
     into transport return value — separation per architect
     guidance.
   - SessionID minted via replication.MintProbeSessionID (new
     atomic counter; distinct from peerSessionIDCounter and
     adapter's own probe sessionID counter — three contexts, three
     counters, no overlap).
   - Defensive guards: nil adapter → fail-closed shim probeFn;
     nil executor → return err; zero lineage → return err;
     ctx.Err() pre-check.

#4 Configure → Start ordering at admit time
   main.go calls ConfigureProbeLoop + StartProbeLoop in sequence
   immediately after replVolume + h.SetReplicationVolume; peers may
   or may not exist yet (master assignment arrives async). Empty
   peer set is safely no-op (covered by Batch 3
   TestVolume_ConfigureProbeLoop_HappyPath); production is just
   the same path with a real adapter.

Replication layer additions:
- ReplicaPeer.Executor() accessor for the probeFn (read-only,
  caller never closes — BUG-005 discipline).
- replication.MintProbeSessionID() — atomic counter for
  runtime-driven probes.

CLI flags (default OFF):
- --degraded-probe-interval (default 0; recommended 5s for prod)
- --degraded-probe-cooldown-base (default 5s)
- --degraded-probe-cooldown-cap (default 60s)
Help text explicitly distinguishes loop interval vs per-peer
cooldown so operators don't conflate the two 5s defaults.

Tests (3 wiring + 1 skip = 4/4 PASS as written):
- TestProductionProbeFn_NilAdapter_ReturnsErrAndDoesNotPanic
- TestProductionProbeFn_TransportFailure_ReturnsErr — dial to
  127.0.0.1:1 (reserved/closed) → result.Success=false → non-nil
  err returned + adapter received the failure fact.
- TestProductionProbeFn_ContextCancelled_ReturnsErr
- TestProductionProbeFn_ZeroLineage_ReturnsErr — skipped (defensive
  guard verified by compile-time path; zero-lineage construction
  requires package-private peer access, deferred to integration).

Full ./... regression: PASS (every package, including host 2-min
suite, frontend/iscsi 31s suite, frontend/nvme 61s suite). No
behavioral regression on G5-4 / earlier T4 paths.

Next batch (G5-5C #6): component restart-catch-up test exercising
the full primary→engine→catch-up loop without iscsi/iptables
harness. After that: m01 hardware re-run.
2026-04-27 16:56:48 -07:00
pingqiu a747fcec1f G5-5C #2: peer.go::ProbeIfDegraded + OnProbeAttempt + cooldown state machine + 10 unit tests
Per architect ratification 2026-04-27 of mini-plan v0.5 §1.A binding,
this batch wires the per-peer probe gate + backoff state machine
that the probe loop (batch 1) consumes via DefaultProbeCooldownFn /
DefaultProbeResultFn.

Key design decisions per architect's three guidance items 2026-04-27:

1. Two distinct time concepts documented separately (architect #1):
   - Loop interval (ProbeLoopConfig.Interval, default 5s) — how
     often the probe loop wakes up.
   - Per-peer cooldown (PeerProbeCooldown.Base/Cap, default 5s/60s)
     — gate AFTER an attempt before the next attempt on the SAME
     peer.
   PeerProbeCooldown godoc explicitly calls these out so future
   readers can't conflate the two.

2. peer.mu boundary (architect #2): both ProbeIfDegraded and
   OnProbeAttempt run entirely under p.mu, mutating only peer-local
   state. The actual probe transport call (executor.Probe) is
   dispatched by ProbeLoop.dispatchProbe AFTER the gate returns,
   with p.mu released. Method godocs explicitly forbid calling into
   engine, executor, or other peers' locks from these methods.

3. Close()/lineage teardown (architect #3): OnProbeAttempt on a
   closed peer always clears the in-flight flag (preventing leaks)
   but does NOT update cooldown. This guarantees §1.E (c) clean
   teardown — a delayed probe outcome arriving after Close() does
   not leak state into a fresh peer that may share the underlying
   address. Tested via TestPeer_OnProbeAttempt_ClosedDoesNotUpdateCooldown.

New types:
- PeerProbeCooldown — Base + Cap policy
- DefaultPeerProbeCooldown() — 5s/60s defaults

ReplicaPeer additions (all under p.mu):
- cooldownCfg PeerProbeCooldown
- probeNextEligible time.Time (cooldown deadline)
- probeFailureCount int (drives backoff doubling)
- probeInFlight bool (single in-flight per peer)

New methods:
- SetProbeCooldownConfig(cfg) — volume-level config push
- ProbeIfDegraded(now) bool — atomic gate + claim in-flight
- OnProbeAttempt(now, success) — release in-flight + advance cooldown
- IsProbeInFlight() bool — diagnostic
- ProbeNextEligibleAt() time.Time — diagnostic

Default loop wrappers (in peer.go for cohesion):
- DefaultProbeCooldownFn(now func() time.Time) CooldownFn
- DefaultProbeResultFn(now func() time.Time) ResultFn
Both accept a clock injection for testability.

Tests (10/10 PASS):
- TestPeer_ProbeIfDegraded_OnlyDegradedPasses — §1.A only-on-degraded
  (5 ReplicaState cases)
- TestPeer_ProbeIfDegraded_ClosedSkipped — §1.E (c) closed-peer skip
- TestPeer_ProbeIfDegraded_InFlightGuard — INV-G5-5C-SINGLE-INFLIGHT-PER-PEER
- TestPeer_OnProbeAttempt_BackoffProgression — 5→10→20→40→40 (cap)
- TestPeer_OnProbeAttempt_SuccessResetsBackoff — counter resets to 0,
  next failure restarts at Base
- TestPeer_OnProbeAttempt_ClosedDoesNotUpdateCooldown — §1.E (c)
  teardown semantics
- TestPeer_StateChange_InFlightSafe — TOCTOU: state→CatchingUp
  during in-flight; OnProbeAttempt clears flag without mutating state
- TestPeer_ProbeIfDegraded_ConcurrentClaims — 32 goroutines, exactly
  1 claim succeeds
- TestDefaultProbeCooldownFn_Wires — wrapper delegates correctly
- TestDefaultProbeResultFn_Wires — wrapper delegates correctly

Full ./core/replication/ regression: PASS.

Next batch (G5-5C #3): catch-up/rebuild dispatch branch tests +
ReplicationVolume integration (ProbeLoop owned by volume lifecycle).
2026-04-27 16:13:02 -07:00
pingqiu c6bace4e79 G5-5 upstream instrumentation: observer + OnLocalWrite + ship gates
QA round 8: ALL 6 ship/dial/barrier lines from 7a3996d are missing.
The replication outer loop is not running at all. Need to walk
upstream to find where the fan-out chain breaks.

Add 4 INFO log lines at the upstream surfaces:

  durable/storage_adapter.go (writeBytes observer dispatch):
    - obs nil: 'write observer NIL — replication fan-out skipped'
      (means SetWriteObserver wasn't called before write hit)
    - obs ok: 'write observer dispatch lba=N lsn=N'

  replication/volume.go (OnLocalWrite entry):
    - 'OnLocalWrite volume=v1 lba=N lsn=N peers=K'
      (lets us see if peers map is empty even though
      UpdateReplicaSet returned ok)

  replication/peer.go (ShipEntry early-exit gates):
    - 'ship gate-close peer=r2 lba=N lsn=N (peer closed)'
    - 'ship gate-degraded peer=r2 lba=N lsn=N (peer degraded)'
      (the existing logs are AFTER these gates, so silent
      early-exit was indistinguishable from no-call)

These 4 lines + the existing 7a3996d 6 lines = 10 total. With the
next re-run we should see exactly which hop fails:

  Expected per iSCSI WRITE on primary:
    durable: write observer dispatch lba=0 lsn=1
    replication: OnLocalWrite volume=v1 lba=0 lsn=1 peers=1
    transport: ship lazy-dial replica=r2 ...
    replication: ship ok peer=r2 ...

  If 'observer NIL' appears: SetWriteObserver wiring race — observer
    not set when iSCSI starts writing.
  If OnLocalWrite shows peers=0: UpdateReplicaSet ok but peers map
    became empty (race with stale-gen replay tearing down peers?).
  If 'ship gate-close' / 'ship gate-degraded' appears: peer state
    transitioned bad before any ship attempt.
  If none of the above + ship lines silent: Backend.writeBytes itself
    is bypassed (iSCSI handler not going through StorageBackend).

Tests still green.

Refs: QA round 8 — 7a3996d logs all silent on ship path.
2026-04-27 00:59:33 -07:00
pingqiu 7a3996d2b0 G5-5 ship/dial/barrier instrumentation (suspect B disambig)
QA round 7 confirmed peers=1 — master delivers peer set correctly,
including routable address (r2@192.168.1.184:9221). The fsync I/O
error is on the SHIP side. Sub-suspects:
  (a) lazy-dial never triggered (e.g., peer state == Degraded
      before first ship; ShipEntry returns early)
  (b) lazy-dial triggered but TCP dial failed
  (c) dial succeeded but frame write failed (handshake/framing)
  (d) ship ok, but barrier wait never gets ack (timeout silently)

Add 6 INFO log lines at the suspect surfaces so the next re-run
disambiguates which sub-case is firing:

  core/replication/peer.go (ShipEntry):
    - on ship FAILED: peer + addr + lba + lsn + err
    - on ship ok:     peer + lba + lsn

  core/replication/peer.go (Barrier):
    - on barrier wait:    peer + addr + targetLSN + epoch
    - on barrier FAILED:  peer + addr + targetLSN + err
    - on barrier ack:     peer + targetLSN + achievedLSN

  core/transport/ship_sender.go (Ship lazy-dial):
    - on lazy-dial entry:   replica + addr + sessionID + lsn
    - on lazy-dial FAILED:  replica + addr + err
    - on lazy-dial ok:      replica + addr

Replica-side already logs replica_apply on receive (existing). With
both sides logged, QA's next run should clearly show the failing
hop. No behavior change; small log footprint.

Tests still green: core/replication, core/transport, cmd/blockvolume
(incl. G5-4 integration test).

Refs: QA round 7 disambiguation (peers=1 confirmed; ship-side
instrumentation needed).
2026-04-27 00:54:50 -07:00
pingqiuandClaude Opus 4.7 3b54576e2f T4c-2: catch-up muscle port + state machine + ScanLBAs interface seam
Per design memo §7a + G-1 V2 read signed at v3-phase-15-t4c-2-g1-v2-read.md.
Round-35 architect collapse: T4c-2 covers walstore wal_replay inner-loop
muscle port (V2-faithful, narrow G-1 scope), smartwal state_convergence
production promotion, peer state machine extensions (CatchingUp /
NeedsRebuild), and observability surfacing.

Storage substrate (G-1 §3 row #4 — interface seam):
- Unified RecoveryEntry + ErrWALRecycled + RecoveryMode types in
  core/storage/recovery_contract.go (memo §5.1, §13.0a)
- LogicalStorage.ScanLBAs interface method added; substrate dispatch
  is via interface, not type-switch
- walstore POC promoted: walstore_recovery_poc.go → walstore_recovery.go;
  ScanFrom → ScanLBAs; uses unified storage.RecoveryEntry
- smartwal POC promoted: recovery_poc.go → recovery_scan.go;
  ScanFrom → ScanLBAs; type alias to storage.RecoveryEntry
- BlockStore implements ScanLBAs (state-convergence-equivalent
  synthesis since in-memory has no WAL retention; uses walHead as
  scan-time LSN so caller's targetLSN cap doesn't accidentally skip
  every entry)

Catch-up sender muscle port (G-1 §3 narrow-scope inner loop):
- core/transport/catchup_sender.go body rewritten: replaces
  AllBlocks-walk with primaryStore.ScanLBAs(0, fn) + per-entry
  ShipEntry write
- INV-REPL-CATCHUP-CALLBACK-RETURN-NIL-CONTINUES honored: callback
  skips entries past targetLSN by returning nil (not error)
- INV-REPL-CATCHUP-LASTSENT-MONOTONIC honored: lastSent only
  advances after successful frame write
- INV-REPL-CATCHUP-DEADLINE-PER-CALL-SCOPE honored: SetDeadline at
  entry, cleared at exit (deferred)
- INV-REPL-CATCHUP-TARGET-NOT-REACHED-VS-RECYCLED-DISTINGUISHED:
  ErrWALRecycled wrapped as tier-class change; target-not-reached
  surfaces as separate stream-level error
- INV-REPL-CATCHUP-COMPLETION-FROM-BARRIER-ACHIEVED-LSN (§4.2
  binding): completion judged from BarrierResponse.AchievedLSN, not
  from a separate MsgCatchupDone marker; recovery_mode label
  surfaces in success log per memo §5.1

Engine (G-1 §4.1, §4.3):
- RecoveryRuntimePolicy.MaxRetries field added; per-kind defaults
  match V2 maxCatchupRetries=3 (wal_delta), 0 (full_extent), 1
  (partial_lba)
- applySessionFailed maps ErrWALRecycled in failure reason →
  recovery.Decision = Rebuild (G-1 §4.3 Option B); engine→storage
  decoupling preserved by string-match on the sentinel text rather
  than importing storage package

Peer state machine (memo §2.2):
- ReplicaCatchingUp + ReplicaNeedsRebuild states added
- SetState method with table-driven replicaStateTransitionAllowed
  gate; rejects illegal transitions (NeedsRebuild is terminal in
  T4c per memo)

Tests (15 new):
- core/transport/catchup_sender_test.go (8 tests: 2 V2-mirror +
  6 invariant pins for §5.1-§5.5 + §4.2 binding + sentinel + mode-label)
- core/replication/peer_state_machine_test.go (4 tests: allowed
  transitions, rejected transitions, NeedsRebuild terminal,
  String forms)
- core/engine/recovery_test.go (3 new: MaxRetries per-kind defaults
  pin, WAL-recycled escalation pin, non-recycled non-escalation
  pin)

go test ./... -count=1 → all 21 packages green.

Catalogue invariants queued for §3.3 inscription at T4c batch close:
INV-REPL-CATCHUP-CALLBACK-RETURN-NIL-CONTINUES,
INV-REPL-CATCHUP-LASTSENT-MONOTONIC,
INV-REPL-CATCHUP-DEADLINE-PER-CALL-SCOPE,
INV-REPL-CATCHUP-TARGET-NOT-REACHED-VS-RECYCLED-DISTINGUISHED,
INV-REPL-CATCHUP-RECYCLE-ESCALATES,
INV-REPL-CATCHUP-COMPLETION-FROM-BARRIER-ACHIEVED-LSN,
INV-REPL-PEER-STATE-CATCHINGUP,
INV-REPL-RECOVERY-MODE-OBSERVABLE.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 02:59:53 -07:00
pingqiu 1c6dc56107 T4b-3: ReplicaPeer.Barrier + Fence wrappers (peer-level seam)
New leaf task introduced by QA round-23 §0-B review. T4b-3 originally
planned for ReplicaPeer.Fence-only; QA's peer-state-mutation locality
check surfaced that DurabilityCoordinator must consume peer.Barrier
(not peer.executor.Barrier) so the error → Invalidate translation
lives at the per-peer execution layer — matching V2's WALShipper-
internal markDegraded locality. T4b-3 now ships both Barrier + Fence
wrappers as a leaf before the T4b-4 DurabilityCoordinator muscle port.

Invariant pinned: INV-REPL-BARRIER-FAILURE-DEGRADES-PEER at the V3
per-peer layer, mirroring T4a-3's Ship → Invalidate translation.

Changes:

  core/transport/executor.go
    Extract FenceSync(replicaID, lineage) error — synchronous fence
    exchange returning a descriptive error on any dial / send /
    recv / lineage-mismatch failure. Refactored existing async
    doFence to wrap FenceSync + adapt the error to the callback-
    based FenceResult. Behavior unchanged for existing async
    callers (engine recovery path); T4b-3 peer wrapper gets a
    clean sync surface.

  core/replication/peer.go
    New ReplicaPeer.Barrier(ctx, targetLSN):
      - Passes peer.lineage UNCHANGED to executor.Barrier — does
        NOT override lineage.TargetLSN with the caller's targetLSN.
        Replica's acceptMutationLineage rejects same-authority
        messages that change TargetLSN, so override would self-
        reject. Caller's targetLSN is coordinator-layer-only
        (compared against ack.AchievedLSN for mode arithmetic).
      - MUST NOT gate on state == Degraded per V2 "always attempt
        BarrierAll" invariant (architect §4.3 note in G-1 doc).
        Only post-Close gate applies.
      - On transport error: p.Invalidate(reason) + state=Degraded
        (INV-REPL-BARRIER-FAILURE-DEGRADES-PEER pin).
    New ReplicaPeer.Fence(ctx, lineage):
      - Takes caller-supplied lineage (not peer-owned) because
        fence semantic is "confirm this specific authority tuple"
        — coordinator or recovery path chooses which lineage.
      - Delegates to executor.FenceSync.
      - Same error → Invalidate translation.

Tests (5 required per QA spec):

  - TestReplicaPeer_Barrier_Happy — round-trip against real
    ReplicaListener; ack.Lineage == peer.lineage byte-exact;
    state remains Healthy
  - TestReplicaPeer_Barrier_ErrorPropagates_MarksDegraded —
    unreachable replica; Barrier returns error; peer transitions
    Healthy → Degraded. INV-REPL-BARRIER-FAILURE-DEGRADES-PEER
    pin at peer layer.
  - TestReplicaPeer_Fence_Happy — fence exchange at peer.lineage
    against real replica; state stays Healthy
  - TestReplicaPeer_Barrier_AfterClose_Errors — post-Close call
    returns 'closed' error; no panic
  - TestReplicaPeer_Fence_AfterClose_Errors — post-Close call
    returns 'closed' error; no panic

Verification: full 21-package repo suite green. G-2 tri-line godoc
on Barrier, Fence (Called by / Owns / Borrows) + FenceSync on
executor. G-3 cumulative. Existing T4b-2 Fence tests pass after the
doFence → FenceSync refactor (behavior preserved).

Third task in T4b batch. Next: T4b-4 DurabilityCoordinator (muscle
port; G-1 pre-signed by QA in revised artifact at sw-block/design/
v3-phase-15-t4b-4-g1-v2-read.md) against the peer.Barrier surface.
2026-04-23 18:51:49 -07:00
wzcheng99 debeb55f28 T4a-3: ReplicaPeer (leaf) — per-replica runtime handle
Introduces core/replication/ package and ReplicaPeer — the per-remote-
replica runtime handle that bridges ReplicationVolume fan-out (T4a-4)
to the transport layer (T4a-2). T4a-3 is the Opt-4 leaf: ships first,
then ReplicationVolume consumes it.

Surface (~220 LOC production + 230 LOC tests):
  - ReplicaTarget: authoritative addressing + lineage from master
    assignment (Epoch, EndpointVersion, DataAddr, ControlAddr).
  - ReplicaState: Unknown / Healthy / Degraded. T4a scope only;
    CatchingUp / Rebuilding / NeedsRebuild arrive at T4c with the
    recovery pipeline.
  - NewReplicaPeer: registers a live-ship session in the executor
    using a fresh peer-local SessionID + target.{Epoch,
    EndpointVersion} + constant liveShipTargetLSN = 1. Steady-state
    live-ship session; recovery-bound sessions (with engine-frozen
    TargetLSNs) arrive at T4c.
  - ShipEntry: state-gated fan-out leaf. Healthy → executor.Ship;
    Degraded / closed → reject at peer without dialing. On Ship
    error: mark Degraded + log reason (forward-carry CARRY-1 from
    T4a-2). Caller-supplied lineage is informational for T4a (peer
    owns its session); T4b/T4c may tighten when recovery sessions
    thread through.
  - Invalidate: explicit Healthy → Degraded mutation for authority-
    driven peer-down (no-op on closed peer).
  - Close: idempotent; invalidates the peer's executor session via
    InvalidateSession. Does NOT close the executor — caller owns
    executor lifecycle (BUG-005 discipline).

BlockExecutor gets one new public method:
  - RegisterLiveShipSession(lineage): thin wrapper around internal
    registerSession, needed because ReplicaPeer in core/replication
    needs to register its live-ship session from outside
    core/transport. Tri-line godoc contract attached.

Gate G-2: every public symbol in both files carries a Called by /
Owns / Borrows tri-line contract. PR-rejectable if any symbol lacks
the three-line contract.

Forward-carry CARRY-1 closed: ShipEntry → Invalidate + Degraded on
transport error. Pin test TestReplicaPeer_ShipEntry_ConnFailure_
MarksDegraded asserts (a) first Ship returns dial/write error, (b)
state transitions Healthy → Degraded, (c) subsequent ShipEntry is
rejected at peer without touching the wire. This closes catalogue
§3.2.1 C4 from PARTIAL to DONE.

Tests (6, all green):
  - TestReplicaPeer_ShipEntry_Happy — byte-exact arrival, state
    stays Healthy.
  - TestReplicaPeer_ShipEntry_ConnFailure_MarksDegraded — CARRY-1
    pin.
  - TestReplicaPeer_Invalidate_MovesToDegraded — authority-driven
    path.
  - TestReplicaPeer_Close_Idempotent — double-Close is safe;
    post-Close ShipEntry errors with "closed".
  - TestReplicaPeer_NewReplicaPeer_RejectsNilExecutor.
  - TestReplicaPeer_NewReplicaPeer_RejectsZeroAuthority — fails fast
    at construction rather than at first ship when lineage would be
    rejected by replica's acceptMutationLineage.

Per T4a-3 context note: tests drive against a real
*transport.BlockExecutor + real *transport.ReplicaListener, not
against a ReplicationVolume caller stub (Opt-4 leaf ordering).

Full core/transport + core/replication + core/adapter suites green.
G-3 preserved.
2026-04-23 14:44:35 -07:00