Skip to content

[ENG-16829] fix(agents): stopped sub-agents restart or keep running after /stop - #276

Merged
orswn merged 2 commits into
boonfrom
okka/eng-16829/stop-followup-fixes
Oct 10, 2026
Merged

orswn merged 2 commits into
boonfrom
okka/eng-16829/stop-followup-fixes

Conversation

@orswn

@orswn orswn commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: ENG-16829, follows #272

What Problem This Solves

Fixes an issue where a user who stops a run that has sub-agents would see the agent keep or restart the stopped work:

  • The parent agent said a stopped sub-agent was "still running", then reported it as timed out and started the same work again by itself.
  • A sub-agent that the user stopped right after it was spawned still started and ran its whole task.
  • After a stop, the parent agent did not know that the user had stopped anything, so it could not explain the stop or avoid repeating the work.
  • In service mode (every hosted agent), a shell command such as sleep 300 && echo done left sleep 300 running after the stop.

This affects the Boon Web Stop button and /stop or "stop" on Slack and Teams.

Why This Change Was Made

The stop already ended the parent run, its sub-agents and their exec processes. The remaining gaps were in what OpenClaw records after the stop and in two race windows:

  • Kill is kept. The killed child run still sends its own end event a moment later, with a timeout or error outcome. That event replaced the kill. The registry now keeps a user kill when a later non-success end of the same run arrives. A successful end still wins, as before. subagents list shows killed for these runs.
  • Parent is told. On /stop and the abort words, OpenClaw queues one system event for the parent session: which sub-agents the user stopped, that they will not report back, and not to restart them unless the user asks. The next turn of that session reads it. Reset does not queue it.
  • Abort note is kept. The parent's own run can report its aborted end about 2 s after the stop, as failed. That cleared the "previous agent run was aborted by the user" note before the next turn. The flag now stays set when the end says it was aborted. Sub-agent sessions and runs matched by a restart marker keep the old rule, because restart and orphan recovery read the same flag.
  • Late child does not start. A child that the stop marks as killed before its run became active now ends right before its first model request, with no model call.
  • Grandchildren are killed. In service mode exec shells are not process group leaders, so only the shell got the signal. On Linux the kill now also signals the shell's descendants, found through /proc. The gateway, its parent and init are never signaled. Detached mode and other platforms are unchanged.

Not changed: ACP children, the generic case of a stop that lands before a non-sub-agent run sends its prompt, and processes that the agent detached itself (nohup … &).

User Impact

  • After Stop, the agent no longer says a stopped sub-agent is still running and no longer restarts it unless asked.
  • The agent's next reply can tell the user what was stopped.
  • A sub-agent stopped right after it was spawned does no work.
  • Shell commands with child processes end fully on Stop on hosted agents.
  • Slack and Teams get the same behavior for /stop and "stop".

Evidence

Focused tests on the final tree: abort and stop commands, the sub-agent registry, list, control and orphan recovery, the embedded attempt abort and the new pre-prompt gate, kill-tree, the process supervisor, system events, session lifecycle state and the server-chat agent events.

node scripts/run-vitest.mjs <23 test paths>
  6 shards: 33, 310, 40, 49, 54 and 352 tests
  one case failed once: subagent-registry-lifecycle.test.ts > when attemptCount is 0
  the announce flow gets finalAttempt=false (test file not changed here)
node scripts/run-tsgo.mjs        exit 0
oxfmt --check, oxlint on the changed files: clean
git diff --check                 clean

Each new test fails without its fix. Without the abort-flag condition, 8 session lifecycle tests fail.

The finalAttempt=false case above is intermittent. It failed in 3 of about 19 runs of these files on this branch and in none of 8 runs on the base commit. It passed in the other runs, including a one-worker run of that file with the new service-mode test in both orders. The test file and the announce cleanup path it calls are not changed here.

Channel suites, run against this change:

  • Slack: 109 files, 1397 tests pass.
  • Microsoft Teams: 1090 pass, 1 fail. channel.actions.test.ts > exposes pinnedMessageId in the tool schema fails the same way on the base commit.
  • src/auto-reply/reply as one directory run fails on the base commit and on this branch, with a different set of failures each run, because the files share module state. Every file that failed only on this branch passes on its own, on both trees.

Local end-to-end run: Boon Web and a local gateway built from this change, Claude Opus 4.8 at medium thinking. The build was made before the last change, which keeps the old abort-flag rule for sub-agent sessions. That change is covered by the session lifecycle tests.

Scenario Result
Idle parent, one sub-agent writes a number to a file every second. Stop, then "is the subagent still running?" (run twice) The sub-agent's shell is gone within 1 s and the file stops changing. The registry still shows the run as killed after 5 min. The next prompt has the stop note. subagents list shows killed. The agent says the sub-agent is no longer running and does not restart it.
Parent on a foreground sleep 60 && echo, two sub-agents on sleep 300. Stop, then "status?" (run twice) All sleep processes are gone within 1 s. In the first run the parent's own aborted end arrived 2 s after the stop, and the abort flag stayed set until the next turn read it. The next prompt has the abort note and names both stopped sub-agents. Both runs stay killed.
Stop lands while the spawn tool call is still returning The child run never sends a model request, writes no file and stays killed. The parent gets the stop note.
Stop 1.2 s after the spawn, child request already sent The existing abort ends the child before any tool call. No file, run killed, stop note delivered.
Service mode: exec shell in the gateway's process group, foreground sleep 300 && echo done sleep 300 is gone within 1 s. Without the service marker (detached shell) it is also gone within 1 s.
Control: a sub-agent finishes normally The completion is announced. No stop note, no abort note. subagents list shows done.

After Stop on an idle parent, the agent reports the stopped sub-agent as killed and does not restart it. Work Status shows the row as Stopped.

Stopped sub-agent reported as killed

After Stop on a parent with a foreground command and two sub-agents, the agent reports all three as stopped.

Two stopped sub-agents and the foreground command

Not tested: a live Slack or Teams workspace.

Known limits

  • A grandchild process that ignores SIGTERM survives once its shell has exited, because the supervisor sends SIGKILL only while the shell is alive.
  • A non-sub-agent run started through the agent RPC that times out keeps the abort flag, so the next reply in that session gets one "aborted by the user" note. This needs an RPC run on a user session that times out.
  • A stop that lands on a run that also carries a restart marker does not keep the abort note.
  • A third-party plugin sub-agent that uses a non-sub-agent session key and keeps its session can be resumed after it times out and the gateway restarts within the registry archive window. Bundled plugins use sub-agent keys or delete their session.
  • On a direct-message session that shares the main session key, an isolated heartbeat turn can read the stop note before the user's next turn.
  • One production stop on an idle parent lost the abort flag. It did not reproduce locally. The stop note does not depend on the flag.
  • Boon Web: when the stop lands in the roughly 100 ms between the sub-agent spawn and the channel plugin's spawn hook, the Work Status row keeps showing the task as running. The sub-agent end event arrives before the plugin tracks the task, and the event is sent only once. The ordering is the same without this change. The fix belongs in the channel plugin.

Summary by cubic

Fixes user stops on runs with sub-agents so stopped work no longer restarts or keeps running, and adds a real-process Linux test cleanup so the new process-tree tests do not leak or flake.

  • Keeps a user kill in the sub-agent registry when the killed run later reports a timeout or error; a successful end still wins, and subagents list shows killed.
  • Queues a system event for the parent session naming the stopped sub-agents and telling it not to restart them unless asked.
  • Keeps the "aborted by the user" flag for parent sessions when the stopped run reports its own aborted end; sub-agent sessions and restart-marked runs keep the old rule.
  • Killed sub-agent attempts end before their first model request, with no model call.
  • On Linux, non-detached exec shells now signal their descendants found through /proc, so commands like sleep 300 && echo done stop fully in service mode. The gateway, its parent, and init are never signaled.

Refactors

  • Hardened the new process tests: teardown kills the shell's sleep descendants first, /proc fixture pids avoid the test process and its parent, and the Linux test runs with sh instead of bash.

Written for commit 72ec8dc. Summary will update on new commits.

View guided diff Turn on auto-fix

A user stop on a session with sub-agents left the parent model with
wrong or missing facts, and some work outlived the stop:

- A late end event of the killed child run replaced the kill with a
  timeout. `subagents list` then showed the child as timed out, and
  the parent model restarted the work on its own.
- The parent model was not told which sub-agents the user stopped.
  The one-shot "previous run was aborted" note was also lost when the
  parent run reported its own aborted end after the stop, because
  that end was recorded as failed and cleared the flag.
- A child run that was stopped before it became active still sent its
  first model request and ran its task.
- In service mode, exec shells share the gateway's process group, so
  the kill reached only the shell. Its child processes survived.

Keep a user kill in the sub-agent registry when a later timeout or
error end of the same run arrives. A successful end still wins, as
before. List killed runs as `killed`.

On /stop and the abort words, queue one system event for the parent
session that names the stopped sub-agents and says not to restart
them. Reset does not queue it.

Before the prompt is sent, end a sub-agent attempt whose registry
record is already killed, without a model request.

Keep the session abort flag when the stopped run's own end arrives
with aborted set. Sub-agent sessions and runs matched by a restart
marker keep the old rule, because restart and orphan recovery read
the same flag.

On Linux, when the exec shell is not a process group leader, signal
its descendants found through /proc before the shell. The gateway, its
parent and init are never signaled.

Related: ENG-16829
@orswn
orswn requested a review from a team October 10, 2026 03:50

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 19 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread src/agents/subagent-registry.ts Resolved
Comment thread src/auto-reply/reply/abort.ts Resolved
Comment thread src/gateway/session-lifecycle-state.ts Resolved
Comment thread src/process/kill-tree.test.ts Resolved
Comment thread src/process/kill-tree.linux.test.ts Resolved
Comment thread src/auto-reply/reply/abort.ts Resolved
The new process-tree tests could leave a `sleep 300` running or fail
by chance:

- The teardown killed only the recorded shell when the `sleep` pid
  lookup timed out, so the shell's `sleep 300` child kept running.
- The mocked /proc fixtures used fixed pids. When one matched the
  test process or its parent, the kill path skipped it on purpose and
  the assertion failed.
- The Linux test needed bash.

Kill matching descendants before the shell on teardown, pick fixture
pids outside the range of the test process and its parent, and run
the shell with sh.

Related: ENG-16829
@orswn
orswn merged commit 72c708a into boon Oct 10, 2026
145 of 152 checks passed
@orswn
orswn deleted the okka/eng-16829/stop-followup-fixes branch October 10, 2026 05:50
orswn added a commit that referenced this pull request Oct 10, 2026
…e-boon5

Bring in #276 (ENG-16829) for the 2026.6.34-boon.5 release. It changes no versioned manifest.
orswn added a commit that referenced this pull request Oct 10, 2026
#276 (ENG-16829) merged into boon after the release bump. Add its
entry: a sub-agent stopped by /stop stays killed, the parent session
gets one note that names the stopped sub-agents, and stopping a
service-mode exec shell on Linux also signals its descendants.
orswn added a commit that referenced this pull request Oct 10, 2026
…-> 2026.6.34-boon.5 (#277)

Cut the fork release that ships the two commits on boon since
v2026.6.34-boon.4. The bundled boon-pdf-prep plugin queues inbound
PDFs for background text preparation and adds a short preparation note
to the model input, and cut attachment text now says where it stops
(#273, ENG-21106). A sub-agent stopped by /stop stays killed, and
stopping a service-mode exec shell on Linux also signals its
descendants (#276, ENG-16829).

Bump root package.json and npm-shrinkwrap.json, all 136 plugin
manifests, and the version and openclaw peer floor in every extension
npm-shrinkwrap.json. Add the 2026.6.34-boon.5 CHANGELOG.md section and
the generated extensions/matrix/CHANGELOG.md entry. No dependency
changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants