Invalidate stored Degraded directly, so a NeedsRebuild peer could be
invalidated to Degraded and then set Healthy, escaping the terminal
state. Invalidate now checks replicaStateTransitionAllowed like
SetState: from NeedsRebuild the state is kept and the reason is still
logged; every other state still moves to Degraded.
Fixes#182.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Package the Kubernetes alpha into a script-based Day-1 activation loop: activate the stack, create the first PVC-backed volume, verify writer/reader data, collect product-owned observation evidence, render a local read-only report, and clean up.
Includes multi-node-safe activation defaults, first-volume example automation, read-only ops report output, README/quickstart/release note updates, and review-driven hardening for fail-fast configuration, promotion evidence, inventory fail-closed behavior, and test guards.
Validated by Day-1 activation run 20260517-205252-04e9 and read-only report run 20260517-212358-bfba. Local targeted tests passed.
Adds the beta-hardening test and operations foundation for Seaweed Block, including runner-native protocol/beta gates, CSI lifecycle and durable restart coverage, iSCSI/NVMe protocol release gates, returned-replica evidence, read-only operations status reports, OS initiator compatibility gates, and fast iSCSI L2 durable restart/reconnect coverage.
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.
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.
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).
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.
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.
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.