Skip to content

fix(subagents): fail children interrupted by a Gateway crash - #200807

Merged
vincentkoc merged 2 commits into
mainfrom
fix/subagent-restart-interrupted-20261117
Nov 17, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/subagent-restart-interrupted-20261117

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Problem

When the Gateway process dies without a graceful shutdown (crash, SIGKILL, stall-watchdog kill), a sub-agent that was still running is restored from SQLite as an unended row. Restore retires its completion authority and nothing reconstructs its execution, so the row never reaches a terminal state. Its requester never receives a completion and can wait indefinitely. Restart resume skips the child itself (sub-agent keys are not resumed independently), so nothing else settles it.

Graceful shutdown already ends live children through terminateLiveSubagentsForShutdown; only the crash path leaves them hanging.

Change

The registry sweeper now settles such a row as failed with an interruption error through the existing recovery completion path, so the requester is woken through normal completion delivery. The settle applies only when the row:

  • has not ended, is not yielded, and is neither live nor queued,
  • has retired completion authority, and
  • was created before the current process started (only an earlier process could have owned it).

Yielded rows keep their existing unreachable-yield handling. Docs: docs/tools/subagents/operations.md restart section.

Proof

  • New unit tests (subagent-registry-sweep-settle.restart.test.ts): settles the restored running child and leaves ended, yielded, live, queued and current-process rows alone.
  • Integration (subagent-registry.store-replaced.test.ts): a running child persisted by an earlier Gateway is restored, swept and stored as a terminal error. Fails on base with the sweeper hook reverted; passes with it.
  • Focused registry suites green: sweep-settle restart (38), store-replaced + sweeper lifecycle/recovery (35).
  • pnpm check:changed: typecheck, lint and guards pass; the dead-export scan reports only five pre-existing exports in files this PR does not touch.

Limitations

The crash path is exercised by restore + sweep tests, not by killing a live Gateway. Queued rows restored from an earlier process are deliberately left to their existing handling.

@clawsweeper

clawsweeper Bot commented Nov 17, 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 agents Agent runtime and tooling size: M labels Nov 17, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 17, 2026 21:45
@vincentkoc
vincentkoc enabled auto-merge (squash) November 17, 2026 21:52
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@vincentkoc
vincentkoc merged commit 3cce42d into main Nov 17, 2026
201 of 202 checks passed
@vincentkoc
vincentkoc deleted the fix/subagent-restart-interrupted-20261117 branch November 17, 2026 22:02
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…w#200807)

* fix(subagents): fail children interrupted by a Gateway restart

* test(subagents): keep the restart-interruption message private to its owner
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 19, 2026
…delegate before the sweeper

Upstream openclaw#200807/openclaw#200873 fail a child the earlier Gateway process left
running from the sweeper, and send its requester that failure once the
root's resume re-admits completion custody. The fork settles an
ownerless continuation delegate at registry activation instead, with no
notice: the root's resume input (or the user, after a crash) reconciles.
🌊 kept that precedence on the condition of a restart test that proves
the ordering and that the requester receives no second outcome.

The case runs the real sequence on one state directory: graceful
shutdown, a new lifecycle's activation, `resumeMarkedSessions` with a
Gateway context that can re-admit custody, then sweeps. Both children
were created before this process started and are owed to the requester:
- right after activation the delegate already carries the fork's
  interruption receipt; a sweep at that point fails nothing, because
  retired custody still owes the plain child's notice;
- after the root's resume and a sweep, the plain child (the live
  control) is failed with upstream's message and announced;
- the delegate keeps the activation receipt, upstream's settle never
  logs it, no announce or wake names it, and the requester's only input
  is the root's one resume input.

Negative controls (temporary edit, restored byte-exact): with the
activation settle removed the case is red at the post-activation
receipt (`expected { status: 'running' } to match { status: 'terminal' }`);
with that assertion also lifted it is red at the delegate's receipt,
and the run shows upstream's sweeper failing the delegate with its own
message, logging "Settling subagent interrupted by Gateway restart" and
announcing it: the second outcome this pin forbids.

No production change. The narrow guard is unchanged.

Refs: openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 19, 2026
…ttles

🌊's O3 ruling keeps H1 custody with its own owner and asks for a
separate pin against upstream's sweeper. Two settles now act on rows an
earlier Gateway process left running: upstream's sweeper (openclaw#200807,
`settleRestartInterruptedSubagentRun`) and the fork's activation settle
for ownerless continuation delegates. The fork's predicate excludes
accepted-spawn custody, and the sweeper decides armed and custody rows
in its hoisted H1 branch before it reaches the restart settle.

T3d restarts from a real armed crash image (the native spawn pipeline,
deferred confirmation) rewritten as the earlier process's row: created
before this process started, under a lifecycle this one does not own.
Two rows, one per settle: a native spawn without a completion notice
(the shape upstream's settle fails even under retired custody) and a
continuation delegate. For both, activation leaves the arm in place,
and two sweeps abort the accepted child and roll the registration back,
with no "Settling subagent interrupted by Gateway restart", no
relaunch, and no announce or wake.

Negative controls (temporary edits, restored byte-exact):
- the sweeper's H1-first branch disabled: both rows red at the abort
  (`expected [] to deeply equal ['run-acceptance']`). For the native
  row the run shows upstream's settle failing it with its own message
  while the arm stays and the accepted child is never aborted;
- the activation predicate without its H1 exclusion: only the
  continuation row is red, at the post-activation arm check, because
  activation settled it.

No production change.

Refs: openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 19, 2026
… H1 custody against the sweeper (O3)

🌊's O3 ruling pins, carried to the pure candidate (stage 2): upstream's
restart sweeper settle (openclaw#200807/openclaw#200873) arrives with the 41bdde2 merge,
and the fork's activation settle (subagent-registry-restart-custody.ts) is
the same code here, so the precedence is kept only with its restart test.

- 0019d35 (verbatim): activation settles an earlier process's delegate
  before the sweeper, and its requester gets no second outcome; a plain
  sibling is the live-sweeper control.
- decc47c: the T3d H1 rows, inserted without the staging-only T3b/T3c
  chain pins that preceded them there.

On this tree: the new restart case passes; with the activation settle call
removed it is red at the post-activation receipt (expected terminal, got
running). The H1 file is 24/24 solo twice; T9/T9b showed the documented
1-of-2 load-timing flake in one paired run and were green on the rerun.
Cases 1 and 3 of the restart-custody file stay red on the separate upstream
openclaw#201544 shutdown-outcome change, held for 🌊's ruling.

(cherry picked from commit 0019d35)
(cherry picked from commit decc47c)
Refs openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Backport #200807 to the temporary beta preparation target.

(cherry picked from commit 3cce42d)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 5d6be61533276128c75dfff6bf3860fd73986a07)
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 20, 2026
…law#200807's restart settle

Carries the T14 re-pin (64d2f41) into the shutdown follow-up lane: a
landed collector gets exactly one restart-sweeper settle with the crash
wording and a failed collectorCompletion; a not-landed twin gets no sweeper
settle and its launch owner aborts and fails it.

Refs openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 20, 2026
…tart the work survives

🌊's ruling (msg 1573128652286328963) keeps the crash-stranded outcome and
asks for crash pins kept apart from the graceful ones, plus a guard that a
recoverable or transient restart settles no delegate early.

Case 5, after a crash, for each return mode (direct, silent, silent-wake,
targeted). The delegate and a plain sibling were created and run by the
crashed process (createdAt before this process started), so upstream
openclaw#200807's restart sweeper is eligible to settle both. Then a new lifecycle,
an early sweep, startup's root resume and three sweeps:
- no root resume input (a crash writes no marker);
- exactly one interrupted outcome for the delegate, on its own route, with
  the restart-interruption text. No "Gateway stopped" appears, so neither
  the graceful stop's wording nor the sweeper's;
- the sweeper's restart settle fires for the plain sibling only, which
  ends with its own "did not survive the restart" outcome. The delegate
  keeps the receipt activation wrote, delivered, with one announce;
- never relaunched, and no longer counted as running work.
This replaces case 2's direct-only crash test, whose rows this process
created, so the sweeper never considered them.

Case 6, the recoverable guards:
- an in-process restart with a delegate the new lifecycle admitted and is
  running (live run context): activation, root resume and sweeps leave its
  row byte-for-byte as before, with no outcome and no announce. This
  replaces the weaker "current-lifecycle" check in the in-process case;
- a crash with a delegate parked in sessions_yield (waitForMessage): no
  outcome, its execution, endedReason and delivery unchanged, still
  parked.

Refs openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant