Repository navigation
fix: resume running channel threads after graceful restarts - #188402
Conversation
Keep ordinary main and channel-thread sessions in their own agent when recording restart work, including sessions previously targeted by sessions_send. Only actual subagent keys traverse requester ancestry. Use the lifecycle shutdown deadline for marker writes and remove the upfront store-discovery pass. Report per-agent marker/resume outcomes and skip reasons so an incomplete snapshot is visible. Prove the lost-marker failures on the base with a real SIGTERM writer stall and a non-default main/thread session pointing to a cron requester. Preserve existing marker consumption, queued-input ordering, delivery context, and the legacy upgrade bridge. No persisted shape changes.
|
🦞👀 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: needs changes before merge. What this changesThis PR preserves ordinary conversations as their own restart targets, gives marker writes the process shutdown budget, and logs recovery outcomes. Example: Restart while agent:other:main:thread:123.456 is running and its session database writer is held for 1.4 seconds.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Needs changes before merge - 1 item remains This PR addresses source-confirmed restart failures and merits keeping open, but the shared-store fault fixture needs a focused repair before merge. Priority: P1 Before merge
Findings
Agent review detailsHow this fits togetherGateway shutdown captures live session work into existing SQLite session markers; startup consumes those markers through ordinary session-event admission and queued-input recovery. flowchart TD
A[Live conversation work] --> B[Resolve root conversation]
B --> C[Persist restart marker]
C --> D[Process shutdown deadline]
C --> E[Startup recovery]
E --> F[Current session authority]
F --> G[Resume input and queued messages]
Technical reviewBest possible solution: Keep the existing recovery owners and production fix, and make the fault fixture acquire its SQLite lock with a bounded wait before signaling shutdown. Do we have a high-confidence way to reproduce the issue? Current-main source exposes both lost-marker paths, and the PR records baseline failures; this read-only review ran no target code. Is this the best way to solve the issue? Restricting ancestry traversal and reusing the lifecycle deadline fixes the responsible owners without adding recovery machinery; the test lock acquisition needs correction. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 63dbee6a5145. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +78, Tests 0, Docs +3. Total +81 across 8 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 October 30, 2026, 10:20 AM ET / 14:20 UTC. |
|
The original PostgreSQL conformance (2/3) failure is inherited from main, independently of the restart fixture failure being repaired here. Matching main evidence: run 41063477930 / job 124089262163, head Main already contains 34a4e118dc1d, which explicitly records reproduction of this case on main and passing proof for all four PostgreSQL archive-restore cases. It repairs resolved config-alias reads while preserving the guarded publication path. This PR does not change those config/backup owners. No PostgreSQL retry or unrelated repair is being added here. |
Give the external fault-injection connection bounded native busy handling before BEGIN IMMEDIATE. Its zero default could race an active Gateway write and fail before SIGTERM, preventing the intended shutdown fault. Keep the 1.4-second hold after acquisition and all marker, exactly-once, FIFO, and shutdown assertions unchanged. Bun and Node each pass all 13 requested cases; the stock main Bun case also passes. No test-line growth.
Keep request and channel admission fenced while marker persistence owns its lifecycle deadline. Start the close prelude and database cleanup from the existing post-persistence run-shutdown callback instead of the CLI. Idle agent executors now retire on cleanup rather than restart drain. Extend the existing process proof to require marker persistence before worker clean-close receipts. Preserve marker, exactly-once resume, queue ordering, and deadline assertions; keep test lines net negative.
…penclaw#188402) On Team (2026-10-30 15:24Z stop) restart resume produced nothing: marker persistence hit a hard 1000 ms cutoff while the close prelude was already releasing agent databases (roboclaw clean-close began 15 ms in), so no session got resumeAfterRestart and five running sessions ended killed. Channel/thread and non-default-agent sessions were also lost because shutdown followed sessions_send requester ancestry into excluded cron roots. Shutdown now fences admission (requests, scheduler, cron) immediately but starts database and plugin cleanup only after marker persistence settles; persistence is bounded by the lifecycle cleanup deadline instead of 1 s and failures are logged. Resume root resolution follows only subagent ancestry, so ordinary conversations keep their own marker. Shutdown and startup log per-agent marker outcomes. Crashes without committed markers remain lossy by design.
Backport the bounded marker-persistence deadline and regression from #188402 (e051130). Retain existing failure and cancellation semantics; broader shutdown ordering is not included. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit 5e10588f32a38612bc354de8f69e0c76a7005ec3)
Backport the bounded cleanup-ordering slice of #188402 (e051130). Keep candidate admission, mention inbox, and observer fences immediate while postponing idle-store retirement until restart marker persistence settles. Regression: idle stores previously retired at drain; now 15 owner/kernel/real queued-input restart tests pass, plus 162 CLI and state-ownership tests. Core and gateway test types, typed lint, and format pass. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit 7e916fe0e58347aaa279aa948465fa1ffd9ac8d0)
Complete the shutdown-phase fixture migration from #188402. Preserve blocked-writer settlement and physical lease assertions for all four ending paths. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
…ned children (#201970) Problem: after a Gateway restart, OpenClaw stops running subagents and resumes only their ordinary root, which re-instructs its children. Root discovery walked up the ancestry only while the session key looked like a hidden subagent. A visible spawned child (a dashboard session from sessions_spawn visible:true) stopped the walk, its restart marker was rejected as a spawned child, and the real root was never marked. On a live Gateway a root chat -> visible coordinator -> hidden workers tree stalled after a restart until a human wrote. Fix: follow recorded native spawn ownership (session spawnedBy, or createdVia spawn with parent/controller/requester fallback) up to the ordinary root, for visible and hidden native children, keeping the cycle guard, the recorded child-authority check and the session-incarnation match. sessions_send edges carry no spawn metadata and stay independent roots, which keeps the case #188402 protected. Selection snapshots live owners before the worker reads, keeps live-root-before-parked precedence, and stays inside the existing shutdown persistence budget. User impact: a root whose work runs through a visible spawned coordinator or worker is resumed after a restart and can re-instruct its children, instead of stalling until someone writes. Proof: new ancestry regression (hidden worker under a visible coordinator; visible worker under the root) red on unchanged main and green with the fix through a real shutdown marker and startup enqueue; 11 restart-resume and registry files (110 tests); tsgo, test types, type-aware oxlint, format and the line-cap ratchet; ocx build --dts plus a packed install smoke on the head. Co-authored-by: Ayaan Zaidi <[email protected]>
…ned children (openclaw#201970) Problem: after a Gateway restart, OpenClaw stops running subagents and resumes only their ordinary root, which re-instructs its children. Root discovery walked up the ancestry only while the session key looked like a hidden subagent. A visible spawned child (a dashboard session from sessions_spawn visible:true) stopped the walk, its restart marker was rejected as a spawned child, and the real root was never marked. On a live Gateway a root chat -> visible coordinator -> hidden workers tree stalled after a restart until a human wrote. Fix: follow recorded native spawn ownership (session spawnedBy, or createdVia spawn with parent/controller/requester fallback) up to the ordinary root, for visible and hidden native children, keeping the cycle guard, the recorded child-authority check and the session-incarnation match. sessions_send edges carry no spawn metadata and stay independent roots, which keeps the case openclaw#188402 protected. Selection snapshots live owners before the worker reads, keeps live-root-before-parked precedence, and stays inside the existing shutdown persistence budget. User impact: a root whose work runs through a visible spawned coordinator or worker is resumed after a restart and can re-instruct its children, instead of stalling until someone writes. Proof: new ancestry regression (hidden worker under a visible coordinator; visible worker under the root) red on unchanged main and green with the fix through a real shutdown marker and startup enqueue; 11 restart-resume and registry files (110 tests); tsgo, test types, type-aware oxlint, format and the line-cap ratchet; ocx build --dts plus a packed install smoke on the head. Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#188402) On Team (2026-10-30 15:24Z stop) restart resume produced nothing: marker persistence hit a hard 1000 ms cutoff while the close prelude was already releasing agent databases (roboclaw clean-close began 15 ms in), so no session got resumeAfterRestart and five running sessions ended killed. Channel/thread and non-default-agent sessions were also lost because shutdown followed sessions_send requester ancestry into excluded cron roots. Shutdown now fences admission (requests, scheduler, cron) immediately but starts database and plugin cleanup only after marker persistence settles; persistence is bounded by the lifecycle cleanup deadline instead of 1 s and failures are logged. Resume root resolution follows only subagent ancestry, so ordinary conversations keep their own marker. Shutdown and startup log per-agent marker outcomes. Crashes without committed markers remain lossy by design. (cherry picked from commit e051130) Private LOCAL11.8 preparation; canonical integration pending. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 6ddb173d0115eb412b00cfb688cd0f0c871f10dd)
What Problem This Solves
Fixes missing restart continuations for running main and channel-thread conversations when shutdown closes agent databases before marker persistence, session writes take more than one second, or
sessions_sendancestry redirects an ordinary conversation to an excluded session.User Impact
Running conversations in non-default agents retain their own restart continuation and recorded reply route. Shutdown reports per-agent marked/skipped counts; startup reports resumed/skipped counts as each physical store becomes ready.
Crashes and SIGKILL without a completed marker remain intentionally lossy. A blocked writer can still exhaust the lifecycle deadline, which is now reported. Embedded shutdown callers without a process cleanup budget retain their existing one-second fallback. Cron and externally owned sessions keep their existing exclusions. No configuration, schema, dependency, or migration changes.
Why This Change Was Made
Only actual subagent keys should traverse requester ancestry: ordinary main and thread sessions own their own resume, even if previously targeted by
sessions_send. Marker persistence now shares the lifecycle owner's absolute shutdown deadline. Admission fences synchronously; the lifecycle starts its cleanup prelude and releases database retention only after marker persistence settles or reaches that deadline. Idle executors follow this cleanup phase instead of the earlier drain signal. The session replacement owner resolves and writes each selector without an upfront discovery pass over every store; shared stores can receive one commit per logical selector.The existing session-event owner still consumes markers, checks current authority, carries the recorded channel/account/recipient/thread, and preserves queued-input order. The legacy upgrade bridge remains intact. Production +74 LOC (including outcome logging), tests net zero LOC, docs +3 LOC.
Evidence
bffe87c77f90495888101edc0e019a01645a668a: the real-Gateway SIGTERM case with a 1.4-second session writer hold exited withShutdown session persistence did not settle within 1000ms; the non-default thread marker was absent. The owner regression also lost non-default ordinary-session markers through a cron requester.git diff --check: pass.The process tests use an isolated real Gateway/agent with a synthetic provider and thread session keys. Slack service delivery was not exercised; reply routing reuses the unchanged recorded-delivery-context path. No live Gateway or real user state was accessed.
Bun CI repair — 34d66bd
The original
checks-node-changed-4failure occurred in the fixture'sBEGIN IMMEDIATE, before SIGTERM. Its external fault-injection connection used the native zero busy timeout and could race an active Gateway writer. The one-line repair sets a bounded native busy timeout before acquisition. The 1.4-second hold still starts after acquisition; marker, exactly-once, FIFO, and shutdown assertions are unchanged. No sleeps, JavaScript retries, production changes, or test-line growth were added.The targeted old-head Bun run passed locally, confirming the failure is intermittent rather than claiming a passing replay proves a repair. A controlled held-writer probe reproduced the zero-timeout acquisition failure on both pinned Bun and Node, and verified successful acquisition after the existing writer released with the bounded policy. The unmodified main Bun case passed at
66004e076d4dcfb7e6d1ff14c1a894a03f475908after preparing that checkout's frozen dependencies; the PR install was then restored from its own frozen lockfile.At
34d66bd8b8e0, the repaired process suite and both requested owner suites passed 13/13 cases under Bun and 13/13 under Node, each withnice -n 5and--maxWorkers=1:Targeted lint, formatting,
git diff --check, and fresh isolated autoreview through P2 pass. The original PostgreSQL conformance failure is proven inherited, with a matching main CI signature and an already-landed config-owner repair. Exact-head CI run 41077232850 completed SUCCESS for34d66bd8b8e014e79bceb822b495a4d9b31e7df2. Both reported requiredopenclaw/ci-gateentries are SUCCESS. The bounded watcher used a 600-second polling interval. No CI rerun or further push was needed.Shutdown ordering repair — 1fb7145
The coordinator supplied a second Team journal from 2026-10-30, release
5ed4aa23without this PR:The affected agent database was 50 GB. Five running sessions were killed; no restart markers or resume inputs appeared, and the process exited with status 1.
Source tracing found an additional early-close trigger before the prelude:
run-loop.ts:721signaled shutdown cleanup before server close.gateway-work-admission.ts:298aborts the cleanup signal; the agent database lifecycle queues an idle native close (openclaw-agent-db-lifecycle.ts:223–265), which checkpoints, closes, and releases its lease (openclaw-agent-db-close.ts:36–80). The receipt is emitted after that close. Idle executors separately retired on the earlier restart-drain signal.The prelude does not directly call the agent database close owner, but it starts cleanup that can settle final speech (
talk/session-registry.ts:148–167) and cancels scheduler/model/account owners. Both the prelude and database cleanup now start from the existing run-shutdown callback after marker persistence settles or reaches its lifecycle deadline, before received work is cancelled. Request and channel admission still fence synchronously before persistence. Idle executors use this same cleanup signal, preserving their existing bounded pool through persistence. No new protocol, option, schema, or retry was added.The existing process case now reads the isolated file log, including worker close receipts, and requires the marker summary before the first clean-close receipt. Existing physical-marker, exactly-once resume, queue ordering, and shutdown assertions remain. Both Bun and Node fail this regression on prior PR head
34d66bd8b8e014e79bceb822b495a4d9b31e7df2for an actual pre-marker clean close during managed SIGTERM. Console-only diagnostic attempts did not expose worker receipts and are not counted as red proof.Prior ordering proof on
1fb7145ebfbf7a07acfce0f9017c2199937731f5: 45/45 cases pass under Bun and 45/45 under Node. This includes both requested owner suites, both real-process cases, idle executor retention, worker-store persistence/cleanup, and Gateway catalog/workspace/OAuth cleanup. The process suite took 78.7 seconds under Bun (84.5 seconds Vitest wall time) and 133.0 seconds under Node (143.0 seconds wall time). Whole wrapper runs took 895.7 seconds and 342.7 seconds respectively; Bun included a fresh Gateway build. The existing process suite needs real process stops and restarts to exercise this lifecycle boundary; no process, timer, or size budget was raised.Delayed-writer SIGTERM persisted markers in 1456.4ms / 1557.8ms and exited in 1892ms / 2002ms (Bun / Node). Managed restart persisted markers before clean-close receipts and exited in 1181ms / 665ms. Targeted source/test lint, formatting, core typecheck,
git diff --check, and fresh isolated Codex autoreview through P2 all pass. This repair changes six files with 47 additions and 52 deletions: production −4 LOC, tests −1 LOC. The complete PR is 13 files, 418 additions and 342 deletions: production +74, tests −1, docs +3.CI run 41087819764 completed FAILURE with three attributable jobs, repaired below. No CI rerun was issued. The repair was committed once and pushed once; no merge, deployment, live-state access, dependency change, or budget increase was performed.
Ordering CI repair — ec720b1
Run 41087819764 failed
checks-node-changed-compact-small-15(two kernel close cases),checks-node-changed-compact-large-15(managed SIGTERM lease case), andchecks-node-changed-compact-large-23(rewind close case). All four cases reproduced locally at the prior head. These failures are attributable to this PR; none is classified inherited.The lifecycle now aborts the scheduler and invalidates cron reconciliation synchronously with request admission. Database/resource cleanup still starts only after marker persistence settles or exhausts the lifecycle deadline, but uses the existing subagent-termination callback before run claims are released. The public-close fixture waits for the actual reload-stop event rather than one event-loop turn. The managed SIGTERM fixture settles the membership projection created by its setup before stopping; that existing read was retaining the native handle. Its empty-leases assertion remains before the blocked sidecar settles. The same test now runs on macOS and Linux. No sleeps, polling retries, SQLite error masking, or weakened assertions were added.
Current local proof on
ec720b1303066184c20726681e665dc4d5dbcc56: 59/59 cases pass under Bun and 59/59 under Node, including all three previously failing suites and both real-process restart cases:The delayed-writer SIGTERM marker/exit times were 1536.5ms/1936ms under Bun and 1476.0ms/1888ms under Node. Managed marker/exit times were 36.3ms/512ms and 41.1ms/454ms. The process suite took 65.20s under Bun and 96.85s under Node (Vitest wall time); wrapper totals were 518.81s including a rebuild, and 282.30s. Core typecheck, targeted source/test lint, formatting,
git diff --check, and fresh isolated Codex autoreview through P2 pass. The repair is one new commit and one push. Complete PR: 15 files, 433 additions and 356 deletions; production 284+/210− (net +74), tests 146+/146− (net zero), docs +3. No caps, baselines, or budgets changed.Exact-head CI run 41094977806 completed SUCCESS for
ec720b1303066184c20726681e665dc4d5dbcc56. Both requiredopenclaw/ci-gateentries are SUCCESS: the CI workflow gate and the status gate in run 41097856777. No failed jobs remain on this head. The watcher polled at 600-second intervals and exited green; no CI rerun, further push, or merge was issued. The PR remains open, ready, and mergeable for coordinator review.