Skip to content

feat(core): E5 — e2e crash-resume proof with golden-file comparison - #19

Merged
ajianaz merged 2 commits into
developfrom
feat/e5-e2e-crash-resume
Aug 26, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/e5-e2e-crash-resume

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What (description of the change)

Epic E5, the last of Phase 1b: prove that a turn interrupted by a real crash resumes to the exact same durable content as an uninterrupted run.

  • Layer 1 (deterministic cut points): run a reference session, truncate its JSONL to header+k lines (k = 0..=10) — a faithful crash state since every commit is one fsynced line — reopen, resume_turn, and compare canonicalised content against the golden reference. Every cut point recovers identical content.
  • Layer 2 (real SIGKILL): child process parks inside the effect window (intent durable, settlement not) via --exact re-exec + env-controlled hang tool; parent SIGKILLs it, reopens the session, resumes, and the recovered content equals the reference.
  • resume_turn: new public API driving the recovery protocol from durable state: pending cell → replay/settle per the intent's recorded ReplaySafety; pc Settling → finish; pc Planning → continue; pc ToolCall without pending (the crash window between the transition commit and begin) → legal replan.
  • State machine: (ToolCall, Planning) added to the transition table — a decision that never became durable has only one honest exit: replanning.
  • Guarded replay enforced: Resume::ReExecute with safety = Guarded requires a fresh approval before re-execution; otherwise durable ApprovalRequired abort with the pending cell preserved for a host re-approval + retry.

Why (the problem you're solving)

The whole point of the durable log + effect sandwich design is crash safety, but until now it was only proven at the sandwich level (E2) — never end-to-end at the turn-loop level. E5 closes that gap with a golden-file proof: for every possible crash point, the recovered session content equals the reference run. This also surfaced two real bugs fixed here: the Planning→ToolCall crash window left the machine in a dead state (no legal exit), and resume_turn originally replayed Guarded effects blind (double-fire risk for Write/Destructive tools).

Testing (how you verified this works)

  • 56/56 green (2 new e2e tests + 1 guarded-replay regression), clippy 0 warnings
  • Layer 1: every k = 0..=10 truncation recovers to golden-identical content
  • Layer 2: real SIGKILL mid-effect-window; recovered == reference
  • Regression: Guarded bomb tool (panics if replayed) surfaces ApprovalRequired, pending cell survives for host re-approval
  • Cora review: 1 finding verified as false positive (settle_err transitions directly to Planning — machine.rs:185), dismissed with evidence

Closes #5

- Layer 1: deterministic cut points — truncate reference JSONL to
  header+k lines (faithful crash state, one fsynced line per commit),
  reopen, resume, compare golden content for every k in 0..=10.
- Layer 2: real SIGKILL — child process parks inside the effect window
  (intent durable, settlement not), parent kills it and resumes the
  same session file; recovered content equals the reference.
- resume_turn: new public API for crash recovery; handles pc=ToolCall
  without pending intent (crash window) by legal replan.
- state: (ToolCall, Planning) added to the transition table — decision
  not yet durable means replanning is the only honest exit.
- Golden compare canonicalises wall-clock timestamps only; ids, seqs,
  kinds, payloads must match exactly.
Pre-commit cora review caught a MAJOR: Resume::ReExecute ignored the
intent's recorded safety contract, so a Guarded (Write/Destructive)
effect could double-fire when a crash landed before the effect ran
(the intent was durable but the side effect had not happened yet).

resume_turn now gates Guarded intents behind a fresh approval:
- unregistered tool -> durable UnknownTool abort (wiring changed)
- non-ReadOnly risk without a resolvable gate -> durable
  ApprovalRequired abort; the pending cell survives so the host may
  re-approve and resume again
- ReadOnly tools replay freely (guard is trivially satisfied)

Regression test: a Guarded bomb tool that panics if replayed must
surface ApprovalRequired, and the pending cell must remain set.
safety,
} => {
// The intent's recorded replay contract decides the guard:
// `Guarded` effects require a fresh approval before replay —
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • crates/cora-agent-core/src/turn.rs:130 — In resume_turn's Resume::ReExecute branch, the Ok path calls settle_ok(s, &handle, o)? followed by finish(s)?, but the Err path calls only settle_err(s, &handle, &e)? with no finish. If settle_err does not itself transition out of Settling to Planning (as finish does per machine.rs:191-195), the subsequent drive() will start its loop with pc stuck at Settling, and the first commit in drive will fail the transition table (Settling → ... is not a legal source except back to Planning). Verify settle_err's terminal pc; if it lands at Settling, the Err path needs finish(s)? too.

Review powered by cora-code · BYOK · MIT

@ajianaz

ajianaz commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Handled the CodeCora annotation — verified as a false positive:

settle_err lands directly at Pc::Planning (machine.rs:185): its commit carries .transition(StateTransition::from(seq, Pc::Planning)) with no Settling hop — the error settlement is the transition out. The finish(s)?-less Err path is therefore correct, and identical to the proven pattern in drive() (14 green E3 tests + E5 golden-file resume proofs cover this exact path).

The finding's own condition ("If settle_err does not itself transition...") does not hold. Dismissing as won't-fix.

@ajianaz
ajianaz merged commit 7e2a4f5 into develop Aug 26, 2026
13 of 15 checks passed
@ajianaz
ajianaz deleted the feat/e5-e2e-crash-resume branch August 26, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E5: End-to-end single turn + crash-resume test

2 participants