Repository navigation
[ENG-20801] fix(agents): resume sub-agents interrupted by a gateway restart - #266
Conversation
A gateway restart, stop or crash ended every running native sub-agent. After kill -9 the registry sweeper finalized the child about 60 s after boot with "subagent run lost active execution context". At the restart drain cap and on SIGTERM stop, the run-manager wait saw the 1012 socket close and finalized it as an error. The task registry then announced "Background task cancelled" for it. The child's work was lost and the user had to ask for a full re-run. The orphan recovery that resumes a child with abortedLastRun already exists, but restart interruptions never reached it. Make them reach it: - Mark the gateway as closing at the start of every stop or restart request. While it is closing, a non-ok, non-explicit end of a native sub-agent run keeps the run unended and sets abortedLastRun on the child session. The listener, the wait path, the timeout path and the sweeper share one predicate. Explicit kills and steers still finalize. ACP and plugin runs are excluded. - The task registry uses the same predicate. A held sub-agent task is not patched to cancelled. The cli task for the same run still is. - On boot, a restored run whose child session was left "running" by a crash is marked before boot waits are armed. Runs older than 2 h, or past their run deadline, are not resumed. A marked run gets no boot wait, so it cannot end as a timeout and then resume. - When orphan recovery replaces the run, the sub-agent task is re-keyed to the new run id. Before, the old task stayed running forever and every later restart waited the full drain deferral. - The resume prompt tells the child that tool calls may have been cut off, and to check what already ran before it repeats a side effect. - A parent resumed by main-session recovery is told which sub-agents are still running or resuming, so it does not start them again. - Log each keep, boot mark, deadline skip and age skip with the run id and the child session key. - agents.defaults.subagents.restartResume (default true) turns all of this off. Refs: ENG-20801
There was a problem hiding this comment.
All reported issues were addressed across 30 files
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
Registry restore always deferred its boot waits and the orphan scan behind the async restart-resume pass. Restores with no run that could need a resume mark paid that delay too, and the announce loop guard test timed out on a slow runner. Take the async pass only when restart resume is on and at least one restored native sub-agent run is unended and not paused by sessions_yield. Otherwise arm the boot waits synchronously. Also list the explained warning-comment suppression in the production lint-suppression allowlist. Refs: ENG-20801
|
Live check: background sub-agents through a gateway restart. Setup:
Re-check on the final code,
Known behavior:
Each case ran once. |
Document that a run past its deadline ends as a timeout, that a run a crash left running for more than 2 h is not resumed, and that after a second restart the child may not see its first resume's tool calls. Report isGatewayClosing() as false for a command queue singleton from an older restart generation that lacks the field, instead of undefined. Reset the task registry after every steer restart test, and check that the orphan scan sees the held run in the persistence test. Mark the parent note gap: it can list sub-agents that will end with an error rather than resume. Refs: ENG-20801
|
@cubic-dev-ai review |
@orswn I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 31 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
An in-process restart clears the gateway closing flag when it resets the command lanes. The registry sweeper keeps running across that reset, so a run held at close could reach its session completion check and be finalized as killed before orphan recovery resumed it. Make the sweeper leave an interrupted run whose session has abortedLastRun to orphan recovery, before it looks at the session completion. Orphan recovery resumes the run or ends it when its retry gate refuses. Replace the broad logging mock in the registry test with an explicit factory. Refs: ENG-20801
|
@cubic-dev-ai review |
@orswn I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 31 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…g them A run whose runTimeoutSeconds deadline had passed could still be held at gateway close, because the hold looked only at the closing flag. After an in-process restart the restore pass does not run again, so the sweeper then handed that run to orphan recovery and it ran past its deadline. Do not hold a run past its deadline at close; it ends as a timeout. Have the sweeper leave a held run to orphan recovery only while the run is within its deadline. Refs: ENG-20801
|
@cubic-dev-ai review |
@orswn I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 31 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
Relation to the runtime guardian design The runtime guardian design said "Do not change openclaw itself in this version." It expected an interrupted sub-agent to stop with its parent, and the continued parent turn to spawn it again. This PR changes that part. A restart dropped background sub-agent work that was already under way. Spawning the sub-agent again loses its progress and repeats its work. This PR adds:
The rest of the design is in getboon/boon#15406 and getboon/anychat-boon-web#157:
The full comparison with the design is here: https://github.com/getboon/boon/pull/15406#issuecomment-6015434868 |
…resume tests The boot restore tests compared a session updatedAt ten minutes in the past with the process start time. Fake timers do not fake process.uptime(), so in a worker that had run for over ten minutes the crash branch flipped. Pin the uptime in that block and restore it after. The repeated-resume test seeded the wedged state it was meant to produce, so it passed even with the attempt limit changed. Seed only the attempts and assert the wedge write. Correct the restart-resume module comment: the task registry only skips its own terminal patch for a held run, and the run registry's finalize settles the task. Refs: ENG-20801
|
@cubic-dev-ai review |
@orswn I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 31 files
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Fix all with cubic | Turn on auto-fix | Re-trigger cubic
The resume age read sessionStartedAt, startedAt and createdAt with plain fallbacks, so a non-finite value produced a NaN age. The stale run cutoff already uses getSubagentSessionStartedAt, which skips non-finite values. Use the same helper for the resume age, so the two 2-hour bounds read one start time. With no finite start time the age is infinite and the run is not resumed, as before. Refs: ENG-20801
|
@cubic-dev-ai review |
@orswn I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 31 files
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Fix all with cubic | Turn on auto-fix | Re-trigger cubic
…ound The stale-run check prunes a run only when it is older than two hours, but the boot pass treated a run of exactly two hours as too old. Such a run was neither pruned nor resumed. Accept the boundary, as the stale check does. Reword the boot action descriptions so "too-old" and "none" no longer read the same. Refs: ENG-20801
|
@cubic-dev-ai review |
@orswn I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 31 files
You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
Reviewed at head a9562c7c0c against origin/boon (8 commits, 31 files, +1741/-43).
Local verification (worktree at head, pnpm install --frozen-lockfile --ignore-scripts):
- All 11 touched test files pass via
node scripts/run-vitest.mjs: 6 shards, 368 tests visible in the tail, exit 0. Includessubagent-registry.test.tsboot-restore block,subagent-restart-resume.test.ts,task-registry.test.ts,command-queue.test.ts,run-loop.test.ts. - Mutation check: with the
mark-and-holdaction neutered inresolveRestoredSubagentRunResumeAction, exactly 5 tests fail acrosssubagent-restart-resume.test.tsandsubagent-registry.test.ts(incl. "marks a running session left by a crash and leaves the run to orphan recovery"). The new tests pin the resume decision. File restored after the check. pnpm tsgo:coreexit 0; scopedoxlinton changed prod files exit 0;oxfmt --checkclean;git diff --checkclean.
CI at exact head: all check-runs success except neutral CodeQL. No security-fast run exists on this head; the pnpm-audit failure the body mentions is not present at a9562c7c0c.
Cubic thread adjudication (27 resolved; 17 resolved-not-outdated re-checked against head code):
- Claimed fixes verified in the tree: lane-reset sweeper keep (
82ad500e72— theexecution.status === "interrupted" && abortedLastRun === trueguard is insweepSubagentRuns),process.uptime()stub in the boot-restore block (49ca356583, lines 3123-3137),getActiveRuns()containment assert in the persistence test, wedge gate self-tombstoning insubagent-orphan-recovery.test.ts. - "Not changing" replies hold up in code: the 2 h bound applies only to crash-left-
runningruns (resolveRestoredSubagentRunResumeActionchecks age only on themark-and-holdleg,holdis unbounded — matches the reply); the task-registry path omittingrunis settled by the run registry's finalize (safeFinalizeSubagentTaskRun/failTaskRunByRunId); explicit kills still finalize viaisExplicitAgentAbortStopReason/cause: "explicit-kill";registerSubagentRundoes create the running task (createRunningTaskRuninsubagent-registry-run-manager.ts:719), refuting the steer-restart test concern. docs/.generated/config-baseline*.jsonis tracked on this fork'sboonbranch (release commits update it), so including it is correct here.
Code reads: the close predicate (shouldKeepSubagentRunUnendedOnGatewayClose) is single-sourced across lifecycle listener, run wait, timeout, sweeper, and task registry; ok outcomes and explicit kills finalize normally; restartResume defaults to true via !== false with zod schema + docs (docs/tools/subagents.md, docs/gateway/config-tools.md) aligned; rekeySubagentTaskRunId points the live task at the replacement run. The two declared gaps (resumed turns not in the child transcript; parent note can list soon-to-timeout runs) are marked TODO(okka) and disclosed in the body.
The live-restart evidence table is the author's own box run; I did not reproduce kill -9 / drain-cap scenarios locally. Everything verifiable from the tree checks out. Approving.
…4-boon.2 (#267) Cut the fork release that ships #266 (ENG-20801), the only commit on boon since v2026.6.34-boon.1. An interrupted native sub-agent now resumes after a gateway crash, stop or restart instead of ending with a lost-context error. Bump root package.json and npm-shrinkwrap.json, all 135 plugin manifests, and the version and openclaw peer floor in every extension npm-shrinkwrap.json. Add the 2026.6.34-boon.2 CHANGELOG.md section. No dependency or source changes.




Related: ENG-20801
What Problem This Solves
Fixes an issue where background sub-agents were lost when the Gateway crashed, stopped, or restarted at the drain cap while they were running. The child ended with "subagent run lost active execution context" or "gateway closed (1012): service restart", and its work was gone. On a restart at the drain cap, the user also got a "Background task cancelled" notice and a false "My last reply to you may not have gone through" notice. The parent then offered to start the whole sub-agent again from scratch.
Why This Change Was Made
The orphan recovery that resumes a sub-agent in place already exists. It runs for a child whose run is unended and whose session has
abortedLastRun. Restart interruptions never reached that state:kill -9, the registry sweeper finalized the child about 60 s after boot;1012socket close and finalized it as an error.This change makes those interruptions reach the existing recovery path:
abortedLastRun. One predicate covers the lifecycle listener, the run wait, the run timeout and the sweeper.running, before boot waits are armed.runTimeoutSecondsdeadline are not resumed either. They end as a timeout, with one outcome.running, and every later restart waited the full deferral timeout.agents.defaults.subagents.restartResumedefaults totrue. Withfalse, interrupted runs end with an error, as before.This diverges from upstream. Upstream 2026.9.x stopped relaunching interrupted sub-agents and leaves continuation to the parent (openclaw#153243). This fork keeps the child. A resumed child repeats at most the one tool call that the restart cut, and only after it is told to check. A restart today loses the whole child. A later upstream sync must carry or drop this change.
Not in this PR:
TODO(okka)marks it.TODO(okka)marks it.User Impact
systemctl restartresumes after boot and delivers its real result. Its Work Status row stays running and closes as done.agents.defaults.subagents.restartResume: false.Evidence
node scripts/run-vitest.mjs. The CI sub-agent shard passed 5 runs in a row locally with 2 workers, and once more on the final commit (986 tests). The new tests were written first and failed before the change, or were proven by mutation.security-fast. That check fails onpnpm auditadvisories in dependencies this PR does not change. It fails the same way on [ENG-20522] fix(pdf): large plan sets read nothing past the page cap and scans get no page images #265.tsgocore and core-test,oxfmt --check,oxlint, the import-cycle check, the config baseline check andgit diff --checkall pass.node scripts/build-all.mjsexits 0.kill -9systemctl restartkill -9twice, 59 s apartkill -9,restartResume: falseParent-turn restart recovery was re-checked on the same build. It is unchanged.
The table comes from a build just before the decision logs were added. A re-check on the final code ran
kill -9, the drain cap and a cut completion turn once each. All three resumed and delivered. The keep and mark log lines appeared with their ids.Screenshots. The full table with the log lines is in a comment below.