Skip to content

fix(sessions): settle sessions left running after restart - #165174

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-startup-repair-marked-running-20260919
Oct 5, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-startup-repair-marked-running-20260919

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes sessions remaining marked running after restart when spawned sessions use dashboard keys, or when an archived session retains interrupted-run state.

User Impact

Ownerless spawned sessions settle as interrupted with a diagnostic transcript receipt. Archived running sessions settle as killed, 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 onto dc518bfca481; 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, profile openclaw-check, leases tbx_01m44ax2hjc3qmbmfxw88796rb and tbx_01m44ev07c2kt1haw5f888ne7a.

  • Completed-history regression: the first candidate leaves 1 stale row when the fixture adds two delivered, fully cleaned-up child records; expected failure in 7.24 s Vitest wall time. Final refinement passes: 0 stale rows, completed child history unchanged, five live controls unchanged; mixed-roster test 0.950 s.
  • Old-code archive regressions: two expected assertion failures, retaining running instead of killed; two other archive cases passed (25.32 s Vitest wall time).
  • Old-code mixed-roster regression: expected failure, 20 inactive-running rows remain; 14.01 s Vitest duration (34.15 s wrapper including cold worker preparation).
  • Final recovery/registry run: 211 tests passed in eight files, including resident/SQLite history, pending cleanup, retained wake/requester/collector custody, and malformed-descendant controls. The main-recovery file passed all 151 cases in 148.59 s.
  • Recovery/lifecycle suites: 262 tests passed in 10 files, using 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).
  • GitHub CI run 37241674245 caught 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 scoped check-changed --staged gate 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.
  • Runtime-timeout CI repair: the restored-requester E2E intermittently reported failed after a recorded timeout. Instrumented Testbox proof reproduced Persisted user turn changed before replay admission on both the candidate and original main base dc518bfca481. 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 lease tbx_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 fresh pnpm build qaRuntime; the combined baseline/regression/build/E2E command passed in 3m28.7s. The scoped node scripts/check-changed.mjs --staged --timed gate 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.
  • Independent Codex review: final scoped-clean, no actionable P0–P2 findings, including the completed-history refinement.

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 as 20a0c950fb7f4e876831c31e422de0cd71ef59cf.

LOC: production +138/-62 = +76; tests and test support +430 net; docs +11 net. A stat filter excluding *.test.ts and *test-support* also includes the 289-line .test-harness.ts test 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
node scripts/run-vitest.mjs \
  src/agents/main-session-recovery/main-session-restart-recovery.test.ts \
  src/gateway/session-startup-orphans.test.ts \
  src/gateway/session-startup-orphan-races.test.ts \
  src/gateway/session-startup-orphan-admission.test.ts \
  src/gateway/session-startup-migration.test.ts \
  src/gateway/server-methods/sessions-mutations.archive-attribution.test.ts \
  src/gateway/server.sessions.archive-lifecycle.test.ts \
  src/gateway/session-lifecycle-state.test.ts \
  src/gateway/session-lifecycle-state.recovery.test.ts \
  src/gateway/session-lifecycle-state.persistence.test.ts \
  --maxWorkers=1

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.

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 4, 2026
@steipete
steipete marked this pull request as ready for review October 4, 2026 22:52
@steipete
steipete enabled auto-merge (squash) October 4, 2026 22:55
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 9:22 PM ET / October 5, 2026, 01:22 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: 6bf0555da9c1a8dadc6a71a587997715303a7e5f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with meaningful compatibility and race coverage and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a MEMBER author, so ordinary external-contributor proof is exempt. Inspected SQLite/startup and archive-RPC fixtures cover the changed settlement owners; the body additionally reports built-Gateway timeout E2E success. Existing-state compatibility is supported by preserved metadata and ownership controls without a schema change; exact live-incident clearance is not claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a MEMBER author, so ordinary external-contributor proof is exempt. Inspected SQLite/startup and archive-RPC fixtures cover the changed settlement owners; the body additionally reports built-Gateway timeout E2E success. Existing-state compatibility is supported by preserved metadata and ownership controls without a schema change; exact live-incident clearance is not claimed.
Evidence reviewed 10 items Pinned introduced changes: Reviewed the merge-base-to-head delta rather than endpoint drift. Raw head parentage matches the supplied original-head identity; the latest commit changes only timeout classification and its tests.
Still necessary on current main: Fetched main still selects only subagent-shaped keys and excludes aborted/safe-tools rows. Its timeout mapper also lacks canonical terminal-outcome discovery.
Latest release retains the defect: The supplied latest release v2026.9.8 also has the key-only startup selection and abort/safe-tools exclusions; the central repair is not present there.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +76, Tests +430, Docs +11. Total +517 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 6 138 62 +76
Tests 9 534 104 +430
Docs 1 13 2 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 685 168 +517

Review metrics

Metric Value Why it matters
Production versus test growth production +76 net; tests and support +430 net Production growth is justified by shared settlement and custody checks; the 289-line test harness contains fixtures and test registration.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/gateway/server-startup-session-migration.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs stale session status after restart and archive with a bounded recovery impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a MEMBER author, so ordinary external-contributor proof is exempt. Inspected SQLite/startup and archive-RPC fixtures cover the changed settlement owners; the body additionally reports built-Gateway timeout E2E success. Existing-state compatibility is supported by preserved metadata and ownership controls without a schema change; exact live-incident clearance is not claimed.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-04T22:58:03.465Z sha 7b69ef4bdeeaade1064b1eb87ff8db4bf0e0ab90 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T00:10:24.193Z sha eab8962 :: needs maintainer review before merge. :: none

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.
@steipete
steipete force-pushed the steipete/perf-micro-startup-repair-marked-running-20260919 branch from 7b69ef4 to eab8962 Compare October 5, 2026 00:01
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
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.
@steipete
steipete merged commit 20a0c95 into main Oct 5, 2026
126 checks passed
@steipete
steipete deleted the steipete/perf-micro-startup-repair-marked-running-20260919 branch October 5, 2026 01:25
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant