pingqiuandClaude Opus 4.7 028ea64fc6 T4d-4 part B: engine-driven recovery wiring + rebuild-on-exhaustion + G5-DECISION-001 serializability
Per T4d mini-plan v0.5 §2.4 (architect round-47 expanded scope).
Closes 3 of 4 HARD CLOSE GATE items (#1 #2 #4); #3 full L2 matrix
+ QA #8 LastSentMonotonic full form deferred to part C with
substrate fault injection.

ROUND-47 ENGINE CHANGE — catchup-exhaustion escalates to rebuild:
- core/engine/apply.go applySessionFailed: catch-up budget exhaustion
  now DIRECTLY emits StartRebuild (Decision flips to Rebuild,
  StartRebuild command emitted with current Recovery.H as TargetLSN).
  Pre-round-47: cleared Decision + emitted PublishDegraded; rebuild
  only fired if a fresh probe arrived. Round-47: rebuild path becomes
  engine-driven end-to-end without probe dependency.
- Rebuild has MaxRetries=0 per DefaultRuntimePolicyFor; rebuild
  failure terminates (Decision cleared, PublishDegraded emitted).
  Pinned by INV-REPL-CATCHUP-EXHAUSTION-ESCALATES-TO-REBUILD +
  INV-REPL-REBUILD-FAILURE-TERMINAL.
- Existing TestSessionFailed_NonRecycled_RetriesUntilBudget updated
  for round-47 escalation (asserts StartRebuild emit on attempt #4
  + Decision=Rebuild + DecisionReason="catchup_budget_exhausted").

WITHENGINEDRIVENRECOVERY() REAL — round-47 HARD GATE #1 + #2:
- core/replication/component/cluster.go: WithEngineDrivenRecovery()
  now installs ONE VolumeReplicaAdapter per replica at Start.
  Adapters are wired to executors via the constructor's
  executor-callback registration (existing adapter ctor behavior).
- New PrimaryNode.adapters field + Cluster.Adapter(idx) accessor.
- New Cluster.DriveAssignment / Cluster.DriveProbeResult helpers
  for test scenarios driving engine state through real adapter.
- Stub warning text + log message removed; engine-driven recovery
  is now the real path when opted in.

G5-DECISION-001 SERIALIZABILITY — round-47 obligation:
- core/engine/g5_decision_001_serializability_test.go pins that
  engine.ReplicaState (+ all nested truth structs) round-trips
  through encoding/json cleanly. T4d-4 obligation: keep struct
  serializable so G5 can choose Path A (persist recovery state
  across primary restart) without structural rewrite.
- 2 tests: full-state round-trip + zero-value round-trip
- T4d-4 does NOT implement persistence — just maintains the
  serializability property.

NEW TESTS (9):
core/engine/recovery_test.go (2 new + 1 updated):
- TestT4d4_CatchupExhaustionEscalatesToRebuild (round-47 #4 pin)
- TestT4d4_RebuildExhaustionIsTerminal (rebuild MaxRetries=0
  termination)
- (existing) TestSessionFailed_NonRecycled_RetriesUntilBudget
  updated for round-47 escalation semantic

core/engine/g5_decision_001_serializability_test.go (2):
- TestG5Decision001_ReplicaState_RoundTripJSON
- TestG5Decision001_ReplicaState_ZeroValueStable

core/replication/component/t4d4_engine_driven_test.go (5):
- TestT4d4_WithEngineDrivenRecovery_IsReal (HARD GATE #1)
- TestT4d4_AdapterWithoutWithEngineDrivenRecovery_IsNil (fence)
- TestT4d4_DriveAssignment_EngineEmitsProbeReplica
- TestT4d4_RoundTrip_AssignmentToProbeToCatchUp_EngineDriven
- TestT4d4_CatchupBudgetExhausted_EngineEmitsRebuild

Existing test updated for round-47:
- core/adapter/adapter_test.go
  TestPreparedNeverStarted_FailsClosedOnImmediateStartError:
  set rebuildErr matching catchUpErr; assert chain ends at
  Degraded after retry+escalate+rebuild-terminal (was: assert
  PhaseFailed after first attempt — round-47 makes that
  intermediate not terminal).

NOT in part B (deferred to part C):
- HARD GATE #3: Full L2 matrix incl QA #8 LastSentMonotonic full form
  — needs substrate fault injection wrapping engine-driven flow
- Windows TempDir cleanup race + sessionID coordination + test rename

Forward-carry status:
- Round-47 engine change preserves all prior round-43/44/46
  invariants (lane purity, stale-skip, no per-LBA regression)
- T4d-1 typed-kind contract: forward-carries
- T4d-2 lane-pure apply gate: forward-carries
- T4d-3 R+1 threading: forward-carries
- T4d-4 part A (RecoveryMode + Stop lifecycle): forward-carries
- 22 packages green; 0 failures

Refs: T4d mini-plan v0.5 §2.4 (architect-ratified expanded scope);
round-47 architect ruling (catchup-exhaustion escalates to rebuild +
G5-DECISION-001); G-1 sign 80036404c (G-1 v0.2).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 23:05:00 -07:00
Languages
Go 84.7%
Rust 7.7%
Shell 2.7%
templ 1.5%
Java 1%
Other 2.1%