Repository navigation
fix: prevent restarts from reviving abandoned sessions - #190995
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: blocked before merge. What this changesThis PR limits automatic crash recovery to the preceding Gateway lifetime and settles older unfinished runs without resuming them. Example: A Gateway starts at 200 with a crashed predecessor that started at 100, while an abandoned session started at 1.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness⛔ Blocked before merge - 2 items remain Keep open: this PR addresses a current-main recovery defect, but its exact-head clean-restart regression is failing and needs attribution before merge. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherCLI startup obtains predecessor facts from the shared-state boot ledger, passes them into session recovery, and uses existing session writers and ordinary input admission to settle or resume persisted runs. flowchart TD
A[CLI startup] --> B[Boot ledger worker]
B --> C[Predecessor interval]
C --> D[Session recovery owner]
E[Persisted session entries] --> D
D --> F[Canonical terminal settlement]
D --> G[Ordinary resume admission]
Technical reviewBest possible solution: Use the existing boot ledger for predecessor selection and the existing lifecycle projection for terminal settlement, preserving graceful markers and ordinary admission. Do we have a high-confidence way to reproduce the issue? Current-main source admits ownerless unfinished runs without a predecessor bound, and the body records a red-on-parent Gateway regression; this review executed no target code. Is this the best way to solve the issue? The patch follows the smallest complete owner-based repair: derive one boot fact, carry it through startup, and reuse canonical lifecycle settlement without another recovery subsystem. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bccddc9413b5. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +69, Tests +194, Docs +7, Other +132. Total +402 across 13 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 2, 2026, 4:40 AM ET / 09:40 UTC. |
|
Merged via squash.
|
* fix: prevent restarts from reviving abandoned sessions * style: satisfy restart recovery lint checks * fix(gateway): honor restart markers across prepared stores
What Problem This Solves
Fixes #190964 reviving abandoned sessions from older Gateway lifetimes when their persisted runs were still unfinished.
User Impact
Crash recovery resumes only work from the immediately preceding Gateway lifetime. Any recorded shutdown completion uses its explicit markers; markers in any agent store also take precedence after a partially completed shutdown; older orphaned runs are recorded as stopped for restart and cannot be adopted again. No schema, configuration, or prompt/tool changes. The existing consume-before-admit crash window remains; recovery does not promise external tool effects exactly once.
Why This Change Was Made
An unfinished run identity does not identify its owning Gateway. Capture the predecessor's exact interval from the existing boot ledger before pruning, including safe-mode segments of the same incarnation, and compare the run's start time against that interval. A recent session edit is not evidence of live work. Missing boot history does not authorize unmarked recovery. Feed this fact into the existing startup decision and reuse the canonical cancellation projection to settle stale runs.
The change adds 113 production lines for the missing boot fact, its delivery to recovery, terminal settlement, and the Gateway-wide marker decision; it introduces no parallel recovery path, cache, or new persisted state. The CLI retains the boot owner's result instead of a separate copied decision. When no marker is known, crash adoption waits for existing database preparation to establish global marker absence; recorded preparation failures veto adoption. Known markers keep the immediate recovery path. Prepared stores reuse the snapshot already owned by database startup, removing a duplicate summary/orphan read; the existing input-recovery promise preserves FIFO admission before reconnecting sends.
Evidence
71e516af03a11fb1e309ff4fd2a0b8dccee506da: the stale run receives a new continuation instead of terminal settlement. With the fix, the killed predecessor resumes once, the older row is settled without a restart input, and a subsequent deliberately interrupted shutdown resumes only its marked turn despite old and same-predecessor unmarked rows in another agent store. Existing graceful sibling tests retain their marked-session contract.gpt-4.1-mini: one automatic continuation completes 15.648 seconds after SIGKILL. The seeded stale session gets zero continuations and retains its original run identity as killed. All owned Gateway and checkpoint processes were verified gone.Synthetic measurement uses 35.13 GiB, 10,000 sessions, 1,000,000 transcript events, and 62,000 workspace files / 1.116 GB on macOS/APFS. Five counterbalanced pairs, ten calls per timing batch and three per allocation batch. The real recovery owner and native SQLite reads/writes run; only model admission is counted instead of executed. No production data.
A/A median variation: wall -22.70%, process CPU -10.06%, main CPU -15.48%, allocation +1.38%. The shared host remained loaded (one-minute load 28.47–30.33 during timing controls), despite pausing lane-owned heavy jobs. Timing and CPU differences are not separable from that control variation; no speedup or neutral-CPU claim is made. Sampled host allocation decreased 13.35%, with a much smaller allocation control difference. Counts are stable in every run. Sampling excludes worker/native allocations, model execution, cold integrity checks, and btrfs. Boot-ledger lookup and waits for deferred database preparation were not separately timed. The committed measurement script reproduces the owner comparison.
The final full Gateway replay had one 120-second whole-test timeout waiting for the third boot’s marked continuation; both graceful siblings passed. Its log shows over 90 seconds elapsed before the partial-kill checkpoint. The unchanged runtime passed the focused replay in 26.877 seconds. The fixture now uses the existing siblings’ 180-second budget and retains phase timings plus bounded failure logs. The original exact admission delay was not captured; this is not classified as an inherited main failure or a proven product deadlock. The final focused replay passes in 35.566 seconds: first boot at 6.977s, crash continuation at 22.671s, partial kill at 24.247s, and marked continuation at 35.228s.
Inherited main regressions
pnpm check:changedran completely. After correcting and rerunning this patch's lint failures, its remaining failure is three unused plugin-hook exports. Exact-parent production Knip reproduces the same three symbols; #190906 (71e516af03a11fb1e309ff4fd2a0b8dccee506da) introduced them. These are an unresolved main regression, not passing checks or noise.The macOS browser test
view.invalidation.browser.test.tsxfails identically on the exact parent because #173115 (19ac02afebec06357762f80db0749e058bfa5e64) hardcodes Control+Z for native Undo. A one-lineControlOrMetacausal control gives 3/3 passing without weakening assertions. This lane leaves UI source unchanged; the actual Gateway UI E2E passes.