Repository navigation
fix: stop a finished subagent's leftover processes and its parent's spinner - #201157
Conversation
A hidden subagent whose task ended and an archived chat no longer hold background services or leftover processes. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
…pinner OpenClaw-Publication: 24ad1b6a-89a6-80ca-a39b-fdb63e069304
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Detailed evidenceStep 0: source facts the fix relies on (verified on origin/main c8da4b7)
EvidenceContract tests (real child processes, red on base, green on this branch).
Phase-1 fault matrix, rerun on isolated Gateways (
|
…eanup A retained terminal row can outlive a reset of its child session. Bound the task-end stop by the task's recorded end so a later publication of the old row never stops processes the replacement session started afterwards. Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: ab2d2636-afec-8781-9afd-535090138b4d
|
Codex review: needs changes before merge. What this changesThis PR stops ordinary processes when hidden subagents end or chats are archived, and changes how child activity animates parent rows. Example: A hidden subagent starts an HTTP server and a nohup process, then is killed.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep open: this PR addresses a demonstrated cleanup failure, but it also hides persistent children's background activity from collapsed sections and leaves existing cancellation tests failing. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherThe subagent registry publishes terminal run facts, the existing exec owner stops matching processes, and the Control UI derives session and ancestor activity from Gateway rows. flowchart TD
A[Subagent terminal publication] --> C[Existing exec cleanup owner]
B[Chat archive request] --> C
C --> D[Scoped process registry]
D --> E[Gateway session rows]
E --> F[Sidebar activity summaries]
Technical reviewBest possible solution: Keep cleanup in the existing exec owner, preserve persistent-child background aggregates, and update the cancellation suite to the accepted service lifetime. Do we have a high-confidence way to reproduce the issue? Current-main source lacks both cleanup calls, and the supplied isolated-Gateway process traces demonstrate surviving services before the fix; no target code was executed during this review. Is this the best way to solve the issue? Reusing terminal publications and stopSessionExecProcesses is a focused repair, but the activity predicate must preserve ordinary children's background aggregates. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2f5bb506ef61. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +116, Tests +370, Docs +7. Total +493 across 14 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 18, 2026, 6:56 AM ET / 11:56 UTC. |
The Stop result still reports only request-owned commands; the service it leaves now stops when the hidden child's task ends. Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: 864eec57-c154-898d-b099-29ea080a7e53
|
Landed in cf21361.
Follow-ups (PR 2 and 3) are listed under "Left for later" in the body. |
…pinner (openclaw#201157) Related: openclaw#199079 ## What Problem This Solves When a hidden subagent finishes, fails, times out or is stopped, the servers and `nohup … &` processes it started keep running, with nothing left to manage them. Its parent's sidebar row keeps spinning, because the leftover processes still count on the dead child. Archiving a chat had the same gap. On 2026-11-18 a stopped worker left an isolated Gateway, a mock server and an HTTP server running until someone killed them by hand. The process-lifetime audit reproduced this on every subagent end path and on archive. ## User Impact - A hidden subagent's `yieldMs` commands, `background: true` services and leftover processes (`cmd &`, `nohup`) stop when its task ends: it finishes, fails, times out or is stopped. A subagent waiting in `sessions_yield` keeps the command it waits on, and that command's exit still wakes it. - Archiving a chat stops its processes, as reset and delete already do. If the stop cannot be confirmed, the archive fails with a retryable error and the chat stays unarchived. - The parent row and the agent header stop spinning once the child's own run ends. A child's processes still show on its own row. - **Behavior change:** to keep a service after a subagent ends, use `durable: true` or start it from the parent. Main chats, visible spawned sessions and the one-shot `agent --local` hand-off are unchanged. ## Why This Change Was Made The chat stays the only owner of its processes (openclaw#199079, openclaw#200097), and `stopSessionExecProcesses` stays the only stop. Two chat ends never called it: - **Subagent task end:** one subscriber on the registry's persistence publication derives "task ended" from the stored rows. All rows ended; none yielded, steer-restart or a visible session. It then stops the child's scope keys (key and session id, the same keys the row counts). Every end path writes its terminal row through that bus, so a new end path is covered automatically. - **Archive:** calls the same stop after the lifecycle drain. - **Sidebar:** one helper, `childShowsParentWorking`, replaces the two duplicated fold rules (session tree and team header). A child folds into its parent only while its run is visible, or while it is a yielded subagent waiting on its own command. No protocol change. - **Text:** the `background` exec description and the background-process and subagent docs. ## Evidence - **Contract table** (`subagent-task-end-processes.lifecycle.test.ts`, real processes: a service, a hand-off and a survivor per row). Complete, error, timeout, killed, and parent reset of a yielded child: base fails all 5, the branch passes. The yielded child and the visible-session child keep their processes on both. About 20 s of test time. - **Archive** (`server.sessions.archive-lifecycle.test.ts -t "archive stops the chat"`): both processes stop; an unconfirmed stop returns retryable `UNAVAILABLE` and does not archive. Base fails, the branch passes. - **Sidebar** (`app-sidebar-session-tree.test.ts`): a `historical` child with processes does not spin its parent or the team header; `paused` and `active` children do. Base fails, the branch passes. - tsgo core/ui/core-test, oxlint, format and `agent-tools.prefix-stability.test.ts`: green. **Fault matrix rerun** (isolated Gateways, `env -i`, service marker set, scripted model; base `70d9c782b6ca` → this branch). R2 = `yieldMs`, R3 = `background:true`, R4 = `nohup &`. L = alive and counted, C = clean. | Cell | Base R2/R3/R4 | Head R2/R3/R4 | |---|---|---| | Subagent normal completion | L/L/L | **C/C/C** | | Subagent model failure (400) | L/L/L | **C/C/C** | | Subagent kill | C/L/L | **C/C/C** | | Parent delete, child running | C/L/L | **C/C/C** | | Parent delete, child completed | C/L/L | **C/C/C** | | Archive | C/L/L | **C/C/C** | | Subagent yielded on its hand-off | kept | kept (`paused`, count 1; exit resumes it) | | Main chat: completion / abort / failure | L/L/L | unchanged by design | A `setsid` double fork stays untracked on macOS, unchanged (follow-up). **Real model** (`openai/gpt-6.2-sol`, this branch): a hidden subagent started a `background:true` HTTP server and a `nohup` process and was then killed. Both processes were gone afterwards, and the child row went from count 2 to no count. **Control UI**, screenshot taken 12 s after the kill without a reload (base used the scripted model): | Before (base) | After (this branch) | | --- | --- | |  |  | |  |  | ## Merge danger and blast radius - Two-way door: no stored rows, schema, config or protocol change; a revert fully restores the old lifetime. - Hidden subagents that start services meant to outlive them now lose them at task end. Archive stops a chat's dev server. - The stop touches only an ended hidden child's scope, and its `assertCurrent` re-derives the condition, so a resumed child is not stopped. An unconfirmed stop is logged and retried on the next publication for that child; a publication never throws. - Cost: one map lookup per changed run per registry publication. - Size: production +134/−18. The design estimated about +60 of logic; the rest is import formatting, the hoisted archive key list and the review fix that bounds the stop by the task's end time (a reset child key keeps its later processes). Tests: +376/−4. ## Left for later PR 2: group kill for adopted survivors, the relay on macOS without the marker, a required `scopeKey` with a single factory and a teardown census, cron run sessions, `canStop: false` on killed children. PR 3: crash recovery for adopted survivors (needs approval) and Linux `cgroup.kill`. Co-authored-by: Ayaan Zaidi <[email protected]>
…pinner (#201157) Related: #199079 ## What Problem This Solves When a hidden subagent finishes, fails, times out or is stopped, the servers and `nohup … &` processes it started keep running, with nothing left to manage them. Its parent's sidebar row keeps spinning, because the leftover processes still count on the dead child. Archiving a chat had the same gap. On 2026-11-18 a stopped worker left an isolated Gateway, a mock server and an HTTP server running until someone killed them by hand. The process-lifetime audit reproduced this on every subagent end path and on archive. ## User Impact - A hidden subagent's `yieldMs` commands, `background: true` services and leftover processes (`cmd &`, `nohup`) stop when its task ends: it finishes, fails, times out or is stopped. A subagent waiting in `sessions_yield` keeps the command it waits on, and that command's exit still wakes it. - Archiving a chat stops its processes, as reset and delete already do. If the stop cannot be confirmed, the archive fails with a retryable error and the chat stays unarchived. - The parent row and the agent header stop spinning once the child's own run ends. A child's processes still show on its own row. - **Behavior change:** to keep a service after a subagent ends, use `durable: true` or start it from the parent. Main chats, visible spawned sessions and the one-shot `agent --local` hand-off are unchanged. ## Why This Change Was Made The chat stays the only owner of its processes (#199079, #200097), and `stopSessionExecProcesses` stays the only stop. Two chat ends never called it: - **Subagent task end:** one subscriber on the registry's persistence publication derives "task ended" from the stored rows. All rows ended; none yielded, steer-restart or a visible session. It then stops the child's scope keys (key and session id, the same keys the row counts). Every end path writes its terminal row through that bus, so a new end path is covered automatically. - **Archive:** calls the same stop after the lifecycle drain. - **Sidebar:** one helper, `childShowsParentWorking`, replaces the two duplicated fold rules (session tree and team header). A child folds into its parent only while its run is visible, or while it is a yielded subagent waiting on its own command. No protocol change. - **Text:** the `background` exec description and the background-process and subagent docs. ## Evidence - **Contract table** (`subagent-task-end-processes.lifecycle.test.ts`, real processes: a service, a hand-off and a survivor per row). Complete, error, timeout, killed, and parent reset of a yielded child: base fails all 5, the branch passes. The yielded child and the visible-session child keep their processes on both. About 20 s of test time. - **Archive** (`server.sessions.archive-lifecycle.test.ts -t "archive stops the chat"`): both processes stop; an unconfirmed stop returns retryable `UNAVAILABLE` and does not archive. Base fails, the branch passes. - **Sidebar** (`app-sidebar-session-tree.test.ts`): a `historical` child with processes does not spin its parent or the team header; `paused` and `active` children do. Base fails, the branch passes. - tsgo core/ui/core-test, oxlint, format and `agent-tools.prefix-stability.test.ts`: green. **Fault matrix rerun** (isolated Gateways, `env -i`, service marker set, scripted model; base `c8da4b7fbc40` → this branch). R2 = `yieldMs`, R3 = `background:true`, R4 = `nohup &`. L = alive and counted, C = clean. | Cell | Base R2/R3/R4 | Head R2/R3/R4 | |---|---|---| | Subagent normal completion | L/L/L | **C/C/C** | | Subagent model failure (400) | L/L/L | **C/C/C** | | Subagent kill | C/L/L | **C/C/C** | | Parent delete, child running | C/L/L | **C/C/C** | | Parent delete, child completed | C/L/L | **C/C/C** | | Archive | C/L/L | **C/C/C** | | Subagent yielded on its hand-off | kept | kept (`paused`, count 1; exit resumes it) | | Main chat: completion / abort / failure | L/L/L | unchanged by design | A `setsid` double fork stays untracked on macOS, unchanged (follow-up). **Real model** (`openai/gpt-6.2-sol`, this branch): a hidden subagent started a `background:true` HTTP server and a `nohup` process and was then killed. Both processes were gone afterwards, and the child row went from count 2 to no count. **Control UI**, screenshot taken 12 s after the kill without a reload (base used the scripted model): | Before (base) | After (this branch) | | --- | --- | |  |  | |  |  | ## Merge danger and blast radius - Two-way door: no stored rows, schema, config or protocol change; a revert fully restores the old lifetime. - Hidden subagents that start services meant to outlive them now lose them at task end. Archive stops a chat's dev server. - The stop touches only an ended hidden child's scope, and its `assertCurrent` re-derives the condition, so a resumed child is not stopped. An unconfirmed stop is logged and retried on the next publication for that child; a publication never throws. - Cost: one map lookup per changed run per registry publication. - Size: production +134/−18. The design estimated about +60 of logic; the rest is import formatting, the hoisted archive key list and the review fix that bounds the stop by the task's end time (a reset child key keeps its later processes). Tests: +376/−4. ## Left for later PR 2: group kill for adopted survivors, the relay on macOS without the marker, a required `scopeKey` with a single factory and a teardown census, cron run sessions, `canStop: false` on killed children. PR 3: crash recovery for adopted survivors (needs approval) and Linux `cgroup.kill`. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit cf21361) Release adaptation: Preserve stable process capacity and receipt documentation. The acquired archive drain fences the captured process scope without adding turn-time authority rechecks. Companion audit: #199079 and #200097 process owners are present. 8d21848 is archive fixture isolation only, 0a26c24 changes unrelated sidebar semantics, and later retained-work/worker changes are independent. Co-authored-by: RomneyDa <[email protected]>
Related: #199079
What Problem This Solves
When a hidden subagent finishes, fails, times out or is stopped, the servers and
nohup … &processes it started keep running, with nothing left to manage them. Its parent's sidebar row keeps spinning, because the leftover processes still count on the dead child. Archiving a chat had the same gap. On 2026-11-18 a stopped worker left an isolated Gateway, a mock server and an HTTP server running until someone killed them by hand. The process-lifetime audit reproduced this on every subagent end path and on archive.User Impact
yieldMscommands,background: trueservices and leftover processes (cmd &,nohup) stop when its task ends: it finishes, fails, times out or is stopped. A subagent waiting insessions_yieldkeeps the command it waits on, and that command's exit still wakes it.durable: trueor start it from the parent. Main chats, visible spawned sessions and the one-shotagent --localhand-off are unchanged.Why This Change Was Made
The chat stays the only owner of its processes (#199079, #200097), and
stopSessionExecProcessesstays the only stop. Two chat ends never called it:childShowsParentWorking, replaces the two duplicated fold rules (session tree and team header). A child folds into its parent only while its run is visible, or while it is a yielded subagent waiting on its own command. No protocol change.backgroundexec description and the background-process and subagent docs.Evidence
Step 0,
psexcerpts and the real-model output: see the evidence comment below.subagent-task-end-processes.lifecycle.test.ts, real processes: a service, a hand-off and a survivor per row). Complete, error, timeout, killed, and parent reset of a yielded child: base fails all 5, the branch passes. The yielded child and the visible-session child keep their processes on both. About 20 s of test time.server.sessions.archive-lifecycle.test.ts -t "archive stops the chat"): both processes stop; an unconfirmed stop returns retryableUNAVAILABLEand does not archive. Base fails, the branch passes.app-sidebar-session-tree.test.ts): ahistoricalchild with processes does not spin its parent or the team header;pausedandactivechildren do. Base fails, the branch passes.agent-tools.prefix-stability.test.ts: green.Fault matrix rerun (isolated Gateways,
env -i, service marker set, scripted model; basec8da4b7fbc40→ this branch). R2 =yieldMs, R3 =background:true, R4 =nohup &. L = alive and counted, C = clean.paused, count 1; exit resumes it)A
setsiddouble fork stays untracked on macOS, unchanged (follow-up).Real model (
openai/gpt-6.2-sol, this branch): a hidden subagent started abackground:trueHTTP server and anohupprocess and was then killed. Both processes were gone afterwards, and the child row went from count 2 to no count.Control UI, screenshot taken 12 s after the kill without a reload (base used the scripted model):
Merge danger and blast radius
assertCurrentre-derives the condition, so a resumed child is not stopped. An unconfirmed stop is logged and retried on the next publication for that child; a publication never throws.Left for later
PR 2: group kill for adopted survivors, the relay on macOS without the marker, a required
scopeKeywith a single factory and a teardown census, cron run sessions,canStop: falseon killed children. PR 3: crash recovery for adopted survivors (needs approval) and Linuxcgroup.kill.