feat(round-recover): cross-process round recovery — RECOVER + STATUS + GoalLock (SHAPE-1, LD3-LD11)

Merged
BU
4mo ago
+3467-1

What

Implements the round-recovery feature (SHAPE-1) per the locked decisions LD3–LD11
from flow/findings/round-recovery/2026-07-12-locked-decisions.yaml. Adds two new CLI
subcommands and an exclusive goal lock so that when jewilo is killed mid-round, its
already-spawned verifier orphans' verdicts can be harvested instead of discarded.

Closes the round-recovery exploration (10/10 threads resolved, 11 locked decisions).

Why

jewilo blocks at a gather barrier while m verifier backends run. If jewilo is killed
mid-round (TTY SIGINT, non-TTY SIGTERM, supervisor restart, OOM), the spawned verifier
children are orphaned. Today the only path is RESUME N+1, which increments the round,
re-captures the snapshot, re-renders the prompt, and mints fresh signing keys —
discarding any in-flight verdict the orphans are about to write. There is also no
machine-readable STATUS and no mutual exclusion to prevent two concurrent operations
from corrupting the same goal.

Changes

New module src/round_recover (95.60% line coverage):

  • GoalLock (LD5) — RAII guard over an exclusive flock on
    goals/<goalId>/.lock, held by NEW/RESUME/RECOVER for their full duration. Fail-fast
    try_lock → a concurrent op exits non-zero with a goal busy message. Drop releases;
    advisory locks survive no process crash.
  • status (LD7) — read-only probe (no lock) emitting {goalId, round, state, needs, slots} JSON. state ∈ {new, in_progress, consensus_pass, consensus_fail};
    needs ∈ {done, recover, resume}. Every slot always carries a verdict field (null
    included). Distinguishes interrupted-pass (all-APPROVE, no completion → recover) from
    decided-failed (below n → resume).
  • recover (LD8/LD10/LD11) — wait-only: polls verdict.json for the current round,
    reuses consensus::evaluate + compute_hash + write_completion unchanged (the
    verdict file is the resumption contract). NEVER spawns, kills, re-renders, or
    re-captures (the signature takes no prompt/snapshot). Dead-null slot after timeout →
    StillNullAfter with RESUME N+1 guidance (no key minted, fail-closed D9). Decided-
    failed round returns RoundDecidedNoConsensus promptly without the full timeout.

CLI wiring (LD3):

  • RECOVER <goalId> and STATUS <goalId> subcommands.
  • RECOVER on a complete round warns use RESUME N+1 and exits 0.
  • RESUME on a round with null verdicts warns about RECOVER (symmetric) but proceeds.
  • run_new/run_resume/run_recover all acquire GoalLock.

Vocabulary (LD4): recover (cross-process, this module) vs compaction_recover
(within-round same-process, already in the spawn orchestrator).

No threat-model regression

Per-slot signing secrets stay unpersisted (live only in the original child env).
RECOVER never mints, reads, or needs them. No PID file (LD9). No snapshot TTL (LD11).
The frozen-snapshot-per-round invariant holds (LD10). See design.md §Threat model.

Verification

  • Verifier loop: 2/2 unanimous APPROVE (round 2). Completion hash 071126-a9b37324,
    fullDigest in completion.json for goal dfe264a1. Round 1 was a REJECT (3 findings
    W1/W2/W3, all fixed in a6bd30e); round 2 approved.
  • Tests: 343 green (16 new: 12 lib in tests/round_recover.rs + 6 CLI e2e in
    tests/round_recover_cli.rs [one shared with STATUS]). Includes the e2e-surfaced
    STATUS interrupted-pass fix (ae87fe9).
  • Coverage: cargo llvm-cov --fail-under-lines 80 = EXIT 0; round_recover/mod.rs
    95.60% lines.
  • jewilo-dev e2e kill/resume/pickup: built the worktree as jewilo-dev, ran NEW
    with a slow stub, killed mid-round via SIGTERM → orphan stubs survived (LD6) and wrote
    signed APPROVE verdicts → STATUS reported needs: recover → RECOVER harvested
    both verdicts and wrote completion.json (hash 071126-f4ba80f6) → STATUS reported
    done. The exact kill/RESUME/pickup cycle from the objective.

Spec

openspec/changes/add-round-recovery/ — proposal.md, design.md, tasks.md, and specs:
round-recovery, goal-status, goal-lifecycle (MODIFIED delta).

Out of scope

PID files (LD9), secret persistence (LD8 path-b rejected), snapshot TTL (LD11), re-render
in RECOVER (LD10), OT1/OT2/OT6 (existing non-goals).


Summary by cubic

Adds cross-process round recovery to verifier-loop so in-flight verdicts aren’t lost when jewilo is killed mid-round. Implements SHAPE-1 (LD3–LD11) with RECOVER, STATUS, and an exclusive goal lock; after an interruption run STATUS, then RECOVER or RESUME as directed.

  • New Features

    • GoalLock — exclusive lock at goals/<goalId>/.lock held by NEW/RESUME/RECOVER; concurrent commands fail fast with “goal busy”.
    • STATUS <goalId> — read-only JSON: goalId, round, state, needs (done | recover | resume), and slots (each has a verdict, null included). Distinguishes interrupted-pass from consensus-fail.
    • RECOVER <goalId> — wait-only: polls per-slot verdict.json, reuses consensus + hash, never spawns/kills/re-renders/re-captures. If a slot stays null, exits with RESUME N+1 guidance; if already decided-fail, exits quickly.
  • Bug Fixes

    • GoalLock now maps only “WouldBlock” to “goal busy”; other lock errors surface their real I/O cause.
    • GoalLock validates the goal exists before locking and returns GoalNotFound (no phantom goal dir with only .lock).
    • Polling clamps sleep to remaining time before the deadline so timeouts aren’t overshot.
    • CLI RECOVER fails fast on needs: "resume" (guidance + non-zero), warns and exits on done, proceeds only on recover.

Summary by CodeRabbit

  • New Features
    • Added RECOVER <goalId> for wait-only same-round recovery by polling existing per-slot verdicts and re-running consensus evaluation.
    • Added STATUS <goalId> returning read-only, machine-readable JSON (round/state, next action, and per-slot verdicts).
    • Added goal-lock concurrency protection to prevent simultaneous round-changing operations and return clear “busy” errors.
    • Added guidance behavior to choose between RECOVER and RESUME based on current slot status.
  • Bug Fixes
    • Fail-closed recovery: does not write incomplete completion output when verdicts remain unavailable.
  • Tests
    • Added end-to-end coverage for CLI NEW/STATUS/RECOVER/RESUME, locking, polling-based recovery, and failure scenarios.