Repository navigation
fix(sessions): settle sessions left running after restart - #165174
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: needs maintainer review before merge. Reviewed October 4, 2026, 9:22 PM ET / October 5, 2026, 01:22 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR settles ownerless spawned sessions after restart, marks archived running sessions as killed, releases fully settled child-history ownership, and preserves typed timeout outcomes. Merge readiness✅ Ready for maintainer review The PR remains necessary: current main and the latest release still exclude dashboard-shaped children from orphan repair. No actionable introduced correctness or security defect was found, and the related open PR only partially overlaps this work. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway stores session status separately from active execution and recovery ownership. Startup reconciliation and archive cancellation update those stored rows, which feed session lists and recovery decisions. flowchart TD
A[Stored running sessions] --> B[Startup reconciliation]
C[Live runs and retained delivery] --> B
B --> D{Current owner or main recovery?}
D -->|Yes| E[Preserve or resume work]
D -->|No| F[Settle interrupted or archived session]
G[Archive cancellation] --> F
F --> H[Updated session status and receipts]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +76, Tests +430, Docs +11. Total +517 across 16 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep session settlement with the existing startup and archive owners, preserving active execution, main-session resume, and unfinished delivery custody. Do we have a high-confidence way to reproduce the issue? Yes, from source: dashboard children are excluded from main recovery but fail current main's subagent-key orphan filter. The supplied regressions exercise this boundary; this read-only review did not execute them. Is this the best way to solve the issue? Yes. Reusing main-recovery eligibility, archive settlement, and one shared completed-history predicate repairs the ownership gap without adding another recovery system. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a2affcf76e93. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
Route ownerless spawned dashboards through startup interruption repair and settle archived runs through the archive owner. Preserve active runs and retained completion custody while allowing fully delivered, cleaned-up child history to release its requester.
Keep the lifecycle and registry assertions unchanged while checking the retained-owner count independently of the expanded startup summary format.
7b69ef4 to
eab8962
Compare
Carry the embedded runtime timeout through a thrown replay-admission error so restored requester sessions retain timeout rather than failed. Preserve caller cancellation precedence and the replay guard. Extend existing lifecycle classification coverage for direct and nested terminal-outcome errors.
…65174) * fix(sessions): settle sessions left running after restart Route ownerless spawned dashboards through startup interruption repair and settle archived runs through the archive owner. Preserve active runs and retained completion custody while allowing fully delivered, cleaned-up child history to release its requester. * test(sessions): assert retained startup ownership count Keep the lifecycle and registry assertions unchanged while checking the retained-owner count independently of the expanded startup summary format. * fix(agents): preserve typed timeout outcomes in lifecycle errors Carry the embedded runtime timeout through a thrown replay-admission error so restored requester sessions retain timeout rather than failed. Preserve caller cancellation precedence and the replay guard. Extend existing lifecycle classification coverage for direct and nested terminal-outcome errors.
What Problem This Solves
Fixes sessions remaining marked
runningafter restart when spawned sessions use dashboard keys, or when an archived session retains interrupted-run state.User Impact
Ownerless spawned sessions settle as
interruptedwith a diagnostic transcript receipt. Archived running sessions settle askilled, matching archive cancellation. Eligible main sessions still resume; live work and retained delivery obligations remain protected. Existing stores are repaired during startup without a schema change or new configuration.Why This Change Was Made
Startup repair now consumes the main recovery owner's eligibility decision instead of independently requiring a
:subagent:key. Abort and safe-tools flags alone no longer exclude ownerless children. Archive-time cancellation and historical startup repair share the same settlement operation, preserving known timestamps, terminal outcomes, and recovery/delivery metadata. Session generations and current Gateway/run/admission ownership are rechecked at settlement. Completed descendants stop retaining their requester only after delivery and cleanup finish with no outstanding requester, wake, collector, pause, kill, or restart custody; malformed records retain ownership.Production delta: +76 lines net. Of that growth, 36 lines implement shared archive cancellation and guarded startup settlement; 35 distinguish completed descendant history from retained completion custody and keep the database decision atomic. These contracts require current ownership checks and preservation of delivery/cleanup obligations. The obsolete key-only selection and unnecessary terminal-outcome construction are removed. Memory and SQLite use one completed-history predicate; direct-child ownership keeps an indexed existence read. The remaining five lines preserve the existing typed timeout outcome when an interrupted runtime attempt throws through the lifecycle boundary.
Evidence
Synthetic SQLite roster: 24 inactive-running rows plus five live controls, including a live archived control. Old code resumes four main sessions but leaves 20 stale rows. Candidate startup and recovery leave 0 stale rows: 16 archived rows become killed, four spawned dashboards become interrupted, and four main sessions resume. All five live controls remain byte-for-byte unchanged. The fixture covers 16 archived rows, four spawned dashboards, and four resumable main dashboards; the separate predecessor/successor process fixture also covers canonical subagent keys, role-marked children, shared stores, and embedded-owner exclusion.
Testbox proof used base
fdc74bfbbf06. The final branch was rebased ontodc518bfca481; SHA-256 verification confirms the validated runtime files remain unchanged. The docs also inherit unrelated upstream additions. The later assertion-only CI repair has the scoped validation below.Validation provider:
blacksmith-testbox, profileopenclaw-check, leasestbx_01m44ax2hjc3qmbmfxw88796rbandtbx_01m44ev07c2kt1haw5f888ne7a.runninginstead ofkilled; two other archive cases passed (25.32 s Vitest wall time).node scripts/run-vitest.mjs <recovery/lifecycle files> --maxWorkers=1. The new mixed-roster case took 0.933 s. The existing 151-case main-recovery file took 150.73 s; nine Gateway files took 132.01 s; total wrapper wall time was 301.10 s. This existing owner suite crosses real SQLite, restart, delivery, and lifecycle boundaries; the change adds no per-test Gateway boot.node scripts/check-changed.mjs --staged(replacement with--timed): first full gate passed in 23m46s; the final gate was interrupted when the first lease completed (exit 255, after all final tests and 19 type groups passed). Replacement-lease final gate passed in 23m14s, including all 27 test type graphs, lint, and guards. The earlier interruption reported no product/test failure. The initial gate rejected growth of an already oversized test file; extracting the coherent startup/archive cases leaves the original file six counted lines below its baseline. The extracted two cases passed in 7.57 s Vitest wall time (mixed-roster case 2.726 s in that cold run).37241674245caught one stale exact-log assertion in the restart integration test; its lifecycle and registry assertions had passed. The test now checks the retained-owner count independently of the expanded summary format. Its scopedcheck-changed --stagedgate passed on the approved Linux rig (23:33–23:46 UTC), and its separate P0–P2 review is clean. The queued follow-up Testbox lease was stopped; existing behavior proof was reused for this test-only correction. The next CI run (37245875604) exposed the inherited runtime-timeout failure described below.failedafter a recorded timeout. Instrumented Testbox proof reproducedPersisted user turn changed before replay admissionon both the candidate and original main basedc518bfca481. The runtime wrapped that error with a canonical timeout, and fallback respected it, but lifecycle mapping ignored the typed outcome. The shared mapper now preserves it while retaining caller cancellation precedence and the replay guard. On leasetbx_01m44pwqqqxxpjzwzjj7tge40w, the new direct/wrapped regression fails twice against the old mapper (9.27 s Vitest wall time); all 89 focused termination/lifecycle/fallback tests pass after the repair. The repaired shipped-Gateway E2E passes all four cases in 76.33 s after a freshpnpm build qaRuntime; the combined baseline/regression/build/E2E command passed in 3m28.7s. The scopednode scripts/check-changed.mjs --staged --timedgate passed in 22m43.7s, including all 27 test type graphs, lint, import-cycle checks, and guards. Its independent Codex review is scoped-clean with no actionable P0–P2 findings. The lease is stopped. The diagnostic repeat and gate each had one preflight-only failure caused by remote fixture/staging state; neither ran a test or check, and both were corrected by verifying exact intended bytes before continuing.Final GitHub CI: run 37250760557 passed on
6bf0555da9c1a8dadc6a71a587997715303a7e5f; the PR check rollup completed 126 checks with no failures. The maintainer auto-merge watcher merged the PR as20a0c950fb7f4e876831c31e422de0cd71ef59cf.LOC: production +138/-62 = +76; tests and test support +430 net; docs +11 net. A stat filter excluding
*.test.tsand*test-support*also includes the 289-line.test-harness.tstest module; that module contains only test registration and fixtures.The fixture uses real SQLite and recovery owners with synthetic Gateway dispatch. It does not deploy or restart a live Gateway, and makes no drain-time, RSS, or metric-gauge claim. The incident’s earlier main-recovery skip reason remains unproven. The historical census omitted some cleanup/requester-custody fields, so exact live-row clearance still requires checking those facts; uncertain custody is retained.
Focused Testbox command
The mixed-roster baseline uses the first file with
-t 'repairs a mixed restart roster'; the archive baseline uses the archive-attribution file. Both run the new tests against the original production files, restored before candidate proof. An initial partial-baseline probe failed at compilation and was discarded; the corrected baseline reaches the expected state assertions.