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
Languages
Go 84.5%
Rust 7.9%
Shell 2.7%
templ 1.6%
Java 1%
Other 2%