Repository navigation
[ENG-16829] fix(auto-reply): shell commands keep running after /stop - #272
Conversation
/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.
There was a problem hiding this comment.
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
/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.
There was a problem hiding this comment.
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
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.
There was a problem hiding this comment.
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
- Process Tree & Supervisor Cancellation (
src/agents/bash-process-abort.ts,bash-process-registry.ts):killExecProcessesForSessionsterminates all active foreground/background bash processes tied to session or scope keys.- Sets
session.exitNotified = trueprior to cancellation/SIGKILL, preventing late exit system events or heartbeat wake cycles.
- Post-Abort Spawn Guard (
src/agents/tools/sessions-spawn-tool.ts):- Inspects
signal.abortedwhen a spawn request is accepted; immediately invokeskillSubagentRunAdminand setsnotifyPolicy: "silent"for any subagent spawned while parent/stopis in flight.
- Inspects
- Subagent Task Silencing on Abort (
src/auto-reply/reply/abort.ts):- Tracks and returns all cascaded
childSessionKeysfromstopSubagentsForRequester. - 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.
- Tracks and returns all cascaded
- Task Registry Export (
src/tasks/runtime-internal.ts):- Re-exports
findTaskByRunIdto allow task lookup by run identifier across subagent modules.
- Re-exports
Verification & Testing
- Unit tests added in
src/agents/bash-process-abort.test.ts,src/agents/tools/sessions-spawn-tool.test.ts, andsrc/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
…-> 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.
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 backgroundedexecprocess 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
/stopfor the thread's session. It needs/stopto end every process of the run.Why This Change Was Made
When a fast abort stops a session, OpenClaw now also cancels every running
execprocess owned by: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
/stopand/newno longer post "Background task cancelled" for them.sessions_spawnregisters a new sub-agent only after it starts it. A/stopthat 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/stopdoes. This coversruntime="subagent". ACP children are not stopped by/stoptoday, and this PR does not change that.stopSubagentsForRequesternow returns the child session keys next to thestoppedcount. The count and the/stopreply text do not change. Every caller reads onlystopped. The new kill and task-update code runs insidetry/catchand only logs at verbose level, so a failure there cannot change the/stopreply.User Impact
/stopand the abort words now end the session's shell commands too, including commands that earlier turns started in the background./stopor/newkilled./stopruns no longer survives the stop.Evidence
Focused tests:
Channel suites, run against this change:
channel.actions.test.ts > exposes pinnedMessageId in the tool schemafails the same way on the base commit, so it is not from this change.Local end-to-end run on
1c8090609ecwith the Boon Web Stop button, which sends/stopfor 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
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
/procevery 10 ms.sleep 100, 2 sub-agents each onsleep 300sleep 300killed./stopran 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:
sleep 300: the process was gone 245 to 274 ms after Stop.sleep 300: all 3 processes gone within 3 s. No late message.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/sdkbump in build(deps): bump @modelcontextprotocol/sdk from 1.29.0 to 1.31.0 #268 updatedpnpm-lock.yamlto 1.31.0, butnpm-shrinkwrap.jsonstill pins 1.29.0. The test fails the same way onboonat 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/stopis in flight./stopand/newno longer post "Background task cancelled".sessions_spawnaccepted after the parent's stop signal is killed immediately, along with its descendants.Written for commit 1c80906. Summary will update on new commits.