Skip to content

[ENG-16829] fix(auto-reply): shell commands keep running after /stop - #272

Merged
orswn merged 3 commits into
boonfrom
okka/eng-16829/stop-agent-run
Oct 8, 2026
Merged

orswn merged 3 commits into
boonfrom
okka/eng-16829/stop-agent-run

Conversation

@orswn

@orswn orswn commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: ENG-16829

What Problem This Solves

Fixes an issue where a user who sends /stop (or "stop") would see the agent stop, but the shell commands it started would keep running. A foreground or backgrounded exec process outlived the stop, and a later exit event could wake the session again. The same applied to shell commands started by the session's sub-agents.

Boon Web gets a Stop button that sends /stop for the thread's session. It needs /stop to end every process of the run.

Why This Change Was Made

When a fast abort stops a session, OpenClaw now also cancels every running exec process owned by:

  • the session itself;
  • its sub-agents that this abort stopped;
  • its sub-agents that ended earlier but left a process running.

Each process is marked exit-notified right before its kill, so the kill does not wake the session. A process that is still starting is not counted and keeps its exit notification; the exec tool kills it through the run's abort signal when the spawn resolves. Killed sub-agent tasks get the silent notify policy, so /stop and /new no longer post "Background task cancelled" for them.

sessions_spawn registers a new sub-agent only after it starts it. A /stop that lists the session's sub-agents in that window missed the new child, so it kept running. The spawn tool now checks the parent run's abort signal when the spawn is accepted. If the run was aborted, it kills the new child run and its descendants at once and silences its task, the same way /stop does. This covers runtime="subagent". ACP children are not stopped by /stop today, and this PR does not change that.

stopSubagentsForRequester now returns the child session keys next to the stopped count. The count and the /stop reply text do not change. Every caller reads only stopped. The new kill and task-update code runs inside try/catch and only logs at verbose level, so a failure there cannot change the /stop reply.

User Impact

  • On every channel, /stop and the abort words now end the session's shell commands too, including commands that earlier turns started in the background.
  • On Slack and Teams this is a behavior change: "stop" now also ends running shell commands.
  • No "Background task cancelled" message appears for sub-agents that /stop or /new killed.
  • A sub-agent spawned while /stop runs no longer survives the stop.

Evidence

Focused tests:

node scripts/run-vitest.mjs run src/auto-reply/reply/abort.test.ts src/agents/bash-process-abort.test.ts src/auto-reply/reply/commands-stop-target.test.ts src/agents/bash-process-registry.test.ts
  Test Files  2 passed (2)   Tests  39 passed (39)
  Test Files  2 passed (2)   Tests  12 passed (12)
node scripts/run-vitest.mjs src/tasks/task-boundaries.test.ts src/auto-reply/reply/abort.test.ts src/agents/tools/sessions-spawn-tool.test.ts src/agents/bash-process-abort.test.ts
  task-boundaries 4 passed, abort 36 passed, sessions-spawn-tool + bash-process-abort 63 passed
node scripts/run-tsgo.mjs   exit 0
scripts/check-import-cycles.ts   0 runtime value cycles

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, so it is not from this change.
  • Abort, reset and exec suites: 12 files, 98 tests pass.

Local end-to-end run on 1c8090609ec with the Boon Web Stop button, which sends /stop for the session. Claude Opus 4.8 at medium thinking.

Video: a request starts two background sub-agents and a foreground command. Stop ends all of them, and nothing arrives after the stop (27 s).

e1.mp4

Running, stopping, stopped, after reload

Process times in ms after the user pressed Stop. Run 1 polled the process tree every 50 ms. The other runs checked each process in /proc every 10 ms.

Scenario Processes All gone Late messages after 60 s
Parent on a foreground sleep 100, 2 sub-agents each on sleep 300 3 +135 0
Same scenario, second run 3 +110 0
One foreground sleep 300 1 +96 0
  • No "Background task cancelled" message appeared for the killed sub-agents. Their tasks ended with outcome killed.
  • A normal short turn without /stop ran as before.

Same run in the related PRs: getboon/boon#15469 (Stop button) and getboon/anychat-boon-web#163 (Boon Web stop route).

Earlier local run, on the first version of this change, paid and trial profiles:

  • Foreground sleep 300: the process was gone 245 to 274 ms after Stop.
  • Parent on a foreground sleep plus 2 sub-agents on sleep 300: all 3 processes gone within 3 s. No late message.
  • Background-only sub-agents after the turn closed: both processes gone within 2 s.

Not tested: a live Slack or Teams workspace.

CI: two checks fail on the base branch too, and this change does not touch their inputs.

  • security-fast: the production dependency audit reports advisories in existing dependencies.
  • checks-node-core-tooling: test/package-manager-config.test.ts > keeps npm shrinkwrap package versions inside the pnpm lock graph. The @modelcontextprotocol/sdk bump in build(deps): bump @modelcontextprotocol/sdk from 1.29.0 to 1.31.0 #268 updated pnpm-lock.yaml to 1.31.0, but npm-shrinkwrap.json still pins 1.29.0. The test fails the same way on boon at that commit.

Summary by cubic

Fixes /stop (and abort words) stopping the agent run but leaving the shell commands it started running. Now a stopped session also cancels every running exec process owned by the session and its sub-agents, including commands from earlier turns started in the background, and subagents spawned while /stop is in flight.

  • Applies on every channel; on Slack and Teams, "stop" now also ends running shell commands.
  • Killed sub-agent tasks get a silent notify policy, so /stop and /new no longer post "Background task cancelled".
  • A sessions_spawn accepted after the parent's stop signal is killed immediately, along with its descendants.

Written for commit 1c80906. Summary will update on new commits.

View guided diff Turn on auto-fix

/stop aborted the session's run and its sub-agents, but the exec
processes they started kept running. A foreground or backgrounded
shell command outlived the stop and could later wake the session with
an exit event.

When a fast abort stops a session, cancel every running exec process
owned by the session, by its stopped sub-agents, and by its sub-agents
that already ended. Mark each one exit-notified first, so the kill
does not wake the session. Killed sub-agent tasks get the silent
notify policy, so /stop and /new no longer post "Background task
cancelled" for them.

This applies on every channel. On Slack and Teams, "stop" or /stop now
also ends the session's shell commands, including ones that earlier
turns started in the background. A failure in the kill or the task
update is logged and does not change the /stop reply.
@orswn
orswn requested a review from a team October 8, 2026 07:34

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

cubic analysis

All reported issues were addressed across 5 files

Linked issue analysis

Linked issue: ENG-16829: [Boon Agent] Stop button: cancel the boon-core run and spawned subagents/child processes

Status Acceptance criteria Notes
✅ Cancel shell processes owned by the stopped run killExecProcessesForSessions finds running processes by session key and cancels them through the supervisor or process-tree fallback.
✅ Include shell processes owned by stopped and ended subagents stopSubagentsForRequester returns child session keys, which the abort path includes when cancelling exec processes.
⚠️ Handle cancellation races and repeated Stop requests safely The diff tests unrelated-session isolation, but does not show coverage for spawn or exit races or repeated Stop requests.

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

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

Comment thread src/agents/bash-process-abort.ts Resolved
Comment thread src/agents/bash-process-abort.ts Resolved
/stop lists the requester's subagent runs and stops each one. A
sessions_spawn call that is still in flight at that moment registers
its child only after /stop has read the list, so the child kept
running after the user stopped the parent.

When the spawn tool's abort signal has fired by the time the spawn is
accepted, kill the new child run and its descendants at once, and
silence its task the same way /stop silences a killed subagent.

Also count an exec session as stopped only when a cancel really
happened. A supervisor record that is still starting cannot be
cancelled yet, and such a session must keep its exit notification;
the tool's own abort handling kills it when the spawn resolves.

@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 4 files (changes from recent commits).

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

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

Comment thread src/agents/tools/sessions-spawn-tool.ts Resolved
The stop path and the spawn tool imported task-registry directly,
which the task boundary test allows only for the task access seams.
Export findTaskByRunId from the internal runtime facade and import
both helpers from there.

@boon-hermes-bot boon-hermes-bot 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.

Code Review: APPROVE

LGTM! Cancels running exec/bash processes and silences task notifications upon /stop or fast abort, preventing orphaned shell commands and unexpected late wakes.

Key Changes

  1. Process Tree & Supervisor Cancellation (src/agents/bash-process-abort.ts, bash-process-registry.ts):
    • killExecProcessesForSessions terminates all active foreground/background bash processes tied to session or scope keys.
    • Sets session.exitNotified = true prior to cancellation/SIGKILL, preventing late exit system events or heartbeat wake cycles.
  2. Post-Abort Spawn Guard (src/agents/tools/sessions-spawn-tool.ts):
    • Inspects signal.aborted when a spawn request is accepted; immediately invokes killSubagentRunAdmin and sets notifyPolicy: "silent" for any subagent spawned while parent /stop is in flight.
  3. Subagent Task Silencing on Abort (src/auto-reply/reply/abort.ts):
    • Tracks and returns all cascaded childSessionKeys from stopSubagentsForRequester.
    • Automatically sets notifyPolicy to silent for terminated subagent tasks to prevent spamming "Background task cancelled".
    • Kills exec processes across all target keys, source abort keys, and child sessions inside a safe try/catch error boundary.
  4. Task Registry Export (src/tasks/runtime-internal.ts):
    • Re-exports findTaskByRunId to allow task lookup by run identifier across subagent modules.

Verification & Testing

  • Unit tests added in src/agents/bash-process-abort.test.ts, src/agents/tools/sessions-spawn-tool.test.ts, and src/auto-reply/reply/abort.test.ts.
  • 144 CI check suites passed (isolated package-lock shrinkwrap failure is upstream and unrelated to PR changes).

Verdict: APPROVE

@orswn
orswn merged commit fb8a5e7 into boon Oct 8, 2026
148 of 150 checks passed
@orswn
orswn deleted the okka/eng-16829/stop-agent-run branch October 8, 2026 09:57
orswn added a commit that referenced this pull request Oct 9, 2026
…-> 2026.6.34-boon.4 (#274)

Cut the fork release that ships the three commits on boon since
v2026.6.34-boon.3. /stop now also ends the shell commands of the
session and its sub-agents (#272, ENG-16829). Registered remote-CDP
browser profiles run over Playwright for Browser Sessions (#270,
ENG-21111). @modelcontextprotocol/sdk moves to 1.31.0 (#268).

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.4 CHANGELOG.md section.

#268 changed pnpm-lock.yaml but not the npm shrinkwraps, so the root,
acpx, slack and msteams shrinkwraps still pinned the old
@modelcontextprotocol/sdk tree and the shrinkwrap lock graph test
failed on boon. Move those entries to the pnpm-lock.yaml versions:
@modelcontextprotocol/sdk 1.31.0, express-rate-limit 8.7.1,
eventsource-parser 3.1.1, content-type 2.1.0 and iconv-lite 0.7.3.
The shrinkwraps were generated with a temporary npm-only override for
the @opentelemetry packages under @sentry/node; the override is not
committed. No other 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