Skip to content

fix: drain native subagent commands on parent stop - #166832

Merged
shakkernerd merged 1 commit into
mainfrom
fix/stop-native-descendants
Oct 8, 2026
Merged

shakkernerd merged 1 commit into
mainfrom
fix/stop-native-descendants

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A parent Stop could leave an ordinary command running after its native subagent completed its model response. Active child cancellation could also lose a command-cleanup failure and report success without confirming termination. Children started by a continuation routed into another session were absent from the original request's selection, including after heartbeat consumed the completion notification.

An awaited channel-binding lookup exposed another selection race: selecting children afterward could include later human work, while merely freezing the earlier list missed a child accepted by the original request during that lookup.

User Impact

Parent Stop drains ordinary commands belonging to its selected native child tree, including completed children and nested descendants. Session Stop and channel /stop can select that request's bound native children after the continuation and notification finish. Children accepted by the captured original request during Stop preparation join the same cancellation scope; later human work stays outside it.

Completed child results stay completed, and command-only cleanup adds no canceled model runs. Explicit background: true services, unrelated work, replacement generations, current caller authority, administrative-root behavior and managed-worker behavior are preserved. Historical exact-run requests remain inactive after their original active, process and event ownership has ended. No configuration, protocol or storage migration is introduced.

Related: #160742. This is the native descendant contribution and depends on the command and continuation cancellation contracts in #166764 and #166775.

Why This Change Was Made

The native kill owner captures ordinary command ownership before awaited checks and observes the same native runtime again before signaling it. This covers commands and request owners created after selection. Accepted cleanup is joined on every exit, including caller revocation, replacement and process-output eviction. A committed model-kill result is recorded before later command checks can fail, preserving truthful counts while fencing further effects after an ownership failure.

Successful native registration binds the runtime to the actual original request owner. Exact-run selection requires current request custody; fresh session selection can use the retained binding under the original session's current authority and generation. The existing registry publication listener admits new native roots only through captured owner objects during preparation, acquiring their queued holds synchronously. Observation ends before parent effects and is disposed on failure. This preserves FIFO scheduling without broad session reselection or persistent ancestry.

Gateway and channel callers retain descendant command acceptance and cleanup errors separately from model-run counts. Supported native records without an optional requester-agent field use the existing canonical controller ownership check.

Evidence

The original regression reproduced omitted completed-child cleanup and false success for uncertain, failed or evicted cleanup. Separate failures demonstrated consumed-notification selection loss and lost kill counts after accepted cancellation. The channel lookup probes reproduced both later-human over-selection and omission of a newly accepted original child. The corrected cases exercise real request ownership, native registration, scheduler holds and cancellation rather than accepting ancestry identifiers as authority.

On the tested dependency composition, 114 cases across the native cancellation, ordinary-command cleanup, Gateway authorization and normal Stop owners passed, followed by all eight routed cases. These include failure/revocation, replacement, independent-service and later-human controls. Changed formatting/lint, current compiler discovery and affected production/test graphs passed. The five remaining static owners, including the complete architecture aggregate, passed in 260.57 seconds. The full private-QA build, including declarations, passed in 199.75 seconds. Earlier unaffected compiler, boundary and selected hosted results remain retained at their actual inputs.

The matching real-Gateway browser runs below start a native child through the actual model tool path, wait for its successful model completion, then click parent Stop. Before the change, the ordinary PID/socket remained live and its process panel read Running. Afterward the PID was extinct, the socket closed and the panel read Stopped. Both runs preserved the completed receipt, explicit background service, parent-only aborted model IDs and a later human reply. Model responses were synthetic over loopback. The candidate scenario took 28.93 seconds and the baseline 30.23 seconds, including setup; each case body took about 12.6 seconds.

The four new lookup cases took 17.83 seconds through pnpm test src/agents/subagents/registry/subagent-control.test.ts --maxWorkers=1 -t 'tracks only the original request|channel ACP lookup', including preparation, with 3.89 summed case seconds on macOS. Their estimated incremental CI case cost is about four seconds; shared startup is additional. Earlier Linux runs measured 56.6 summed case seconds for the 27 native/routed cases and 52.99/51.72 seconds for their single-worker commands. Physical cleanup and native lifecycle boundaries require these owner-level cases.

The command and continuation prerequisites are now delivered on main. This PR applies the byte-identical native patch tested at 689c128bb6f10f0890bb66720f851295c2699f4b to that delivered base; all 35 changed files retain their tested contents. The newer admission, storage and claim-settlement changes were checked against the affected cancellation contracts. The media retains its actual runtime identities. Current-head CI completed with 56 successful jobs and 23 unselected jobs. Selected type, lint, boundary, Node and browser checks passed, as did launcher and built-CLI smoke checks. Independent review is complete; the later recovery-owner change on main was qualified against the same cancellation contracts without relabeling the earlier runtime proof.

Visual evidence

Open preview

Before After
Before: the child result is complete but its ordinary command remains Running after parent Stop After: the child result remains complete and its ordinary command is Stopped after parent Stop

Parent Stop, later human reply and native child process inspection

[email protected]

Visual verification

  • Baseline: 2137b3a13982e8edf4996aeae51058cbc7bec717
  • Exact head: 689c128bb6f10f0890bb66720f851295c2699f4b
  • Scenario: A browser parent starts a native child. The child finishes with an ordinary command and an explicit background service still running. Stop the parent, send a new instruction, then inspect the child process.
  • Runtime/build: OpenClaw 2026.9.8; isolated built Gateway and matching Control UI on macOS26.5; Node24.21.0; Chromium
  • Ordinary child process: Running after Stop before the change; PID extinct and socket closed afterward
  • Preserved behavior: Background service remains running; completed receipt is unchanged; later human reply completes
  • Abort result: Parent model run only; child command cleanup adds no canceled model run
  • Both variants use real native spawn, ordinary command processes and browser Stop
  • Model responses are synthetic and loopback-only
  • Clean Git HEAD, native prebuilt generation and served UI asset bytes are checked
  • Captures and recording inspected; source recordings and receipts retained

@clawsweeper

clawsweeper Bot commented Oct 8, 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 gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 8, 2026
@shakkernerd shakkernerd self-assigned this Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 2:23 AM ET / 06:23 UTC (Revision 5).

ClawSweeper review

What this changes

Parent Stop drains ordinary commands owned by selected native subagents, including completed and routed children, while preserving completed results and independent background services.

Example: The user stops a parent after its native child finishes its model reply.

  • Before: The child's ordinary command remains Running despite parent Stop.
  • After: The ordinary command becomes Stopped while the completed child result remains available.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, coherent repair with real entry-point evidence, meaningful ownership controls, and no open correctness finding.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied real-Gateway browser comparison exercises native spawn and parent Stop, showing Running before and Stopped afterward with recorded PID extinction and socket closure. Production-boundary controls cover forbidden callers, generation replacement, revocation, and later work. Video and historical-composition inspection limitations are disclosed in evidence. Request bindings are process-local and introduce no stored-data migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes
User problem: Stop can leave a completed helper's ordinary command running or report success without confirming its cleanup.
Reason: Stopping selected delegated work is an established contract, and the existing area's contributor supplies this focused repair. The broader controller issue is correctly referenced as related.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main does not drain commands retained by completed native children. The prior conflict blocker is resolved, the supplied behavior proof supports the repair, and no actionable patch defect was found.

Priority: P2
Reviewed head: 0358bd39859071505e1fc1afacb14c288007323d

Before merge

None.

Findings

None.

Agent review details

How this fits together

Native subagents perform delegated work and can leave shell commands running after their model replies finish. The cancellation owner receives authorized Stop requests, selects the owned child tree, and reports model cancellation and physical command cleanup separately.

flowchart TD
  A[Parent Stop request] --> B[Current caller and session authority]
  B --> C[Capture original request ownership]
  C --> D[Select native child tree]
  D --> E[Cancel ordinary commands]
  E --> F[Join physical cleanup]
  F --> G[Report cancellation or cleanup failure]
  D --> H[Preserve completed results and independent services]
Loading

Technical review

Best possible solution:

Keep native descendant cleanup within the existing cancellation owner, using captured request custody and current generation checks while preserving completed receipts and explicit background services.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main source omits completed children retaining ordinary commands, and the supplied real-Gateway comparison demonstrates that failure. This read-only review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: the patch extends the existing native cancellation and request-ownership contracts, with final-effect controls for foreign callers, replacement generations, revocation, and later human work.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2b988ee83444.

Provenance checked

  • src/agents/subagents/registry/subagent-control-kill.ts and subagent-control-kill-runtime.ts keeps the original intent (fix(swarm): wait for owned cleanup when stopping children #163558: Retain selected children through owned preparation, terminal persistence, and disposal while reporting cleanup failures.)
  • src/agents/subagents/registry/subagent-control-kill-scope.ts keeps the original intent (fix(agents): stop queued Swarm collectors with their parent #133076: Capture the exact cancellation tree and hold queued reservations before cancellation signals release capacity.)
  • src/agents/subagents/registry/subagent-control-scope.ts keeps the original intent (fix: prevent helper completions from restarting stopped work #156124: Select completed children with pending requester wakes while preserving exact completion identity and current ownership checks.)
  • src/agents/spawn-pipeline.ts keeps the original intent (c1e714e: Share spawn orchestration behind backend adapters while preserving backend failure, progress, and requester-agent contracts.)
  • src/agents/tools/sessions-spawn-tool.ts and sessions-spawn-visible.ts keeps the original intent (feat(agents): session self-service tools #107471: Create real visible child sessions through existing session creation, admission, policy, and subagent completion owners.)
  • src/gateway/server-methods/chat-abort-runtime.ts and chat-abort-descendants.ts keeps the original intent (fix: stop yielded commands with their Gateway request #166753: Capture request-owned ordinary commands before asynchronous cancellation, join physical cleanup, and preserve independent services and completed model receipts.)
  • src/auto-reply/reply/abort-operation.ts and commands-session-abort.ts keeps the original intent (fix: stop yielded commands from channel /stop #166764: Capture parent runs, command owners, and queued input before descendant preparation so later human work remains outside Stop.)

Testing

Proof path: shipped entry point. Added test files: 12.

Security

None.

Evidence

What I checked:

  • Current main still needs the repair: The current-main traversal visits active execution, pending cleanup, yielded sessions, and completion wakes, but does not select a completed child solely because it retains ordinary commands. (src/agents/subagents/registry/subagent-control-kill.ts:269, 2b988ee83444)
  • Owned command cancellation and settlement: The introduced traversal captures child command owners, observes them again before cancellation, joins cleanup on exceptional exits, and records committed model-kill counts before later failures. (src/agents/subagents/registry/subagent-control-kill.ts:300, 0358bd398590)
  • Routed selection and upgrade compatibility: Registration binds actual request-owner objects to the native runtime through a WeakMap. Fresh session selection prepares the original session generation before effects; no schema, serialized field, configuration option, or public plugin API changes. (src/agents/subagents/registry/subagent-exec-request-ownership.ts:18, 0358bd398590)
  • Authority and final-effect controls: The retained production-boundary cases exercise real native registration and supervised processes: another connection leaves the command alive, original-generation replacement refuses cancellation, accepted cancellation joins cleanup after caller revocation, and later human commands and independent services survive. The PR reports the routed cases passing; this review inspected their implementation without executing tests. (src/agents/subagents/spawn/subagent-spawn.request-custody-completed.test-support.ts:388, 0358bd398590)
  • Inspected real-Gateway before/after proof: Downloaded screenshots visibly show the same completed child result with Running before and Stopped/manual-cancel afterward. The captured PR body, sourceRevision 24ecfda0f4544f0a2b2d51ef11a1d405decfbfa851f960b89cf351d91d490afe, records real browser Stop, native spawn, PID extinction, socket closure, preserved background service, and a later human reply on macOS with synthetic loopback model responses. The runtime source was 689c128bb6f10f0890bb66720f851295c2699f4b; the contributor identifies the current patch as byte-identical.
  • Reviewer inspection limitations: Video preparation failed with 'ffprobe failed: spawnSync ffprobe ENOENT'; browser fallback failed with Cache miss. The historical runtime composition SHA was unavailable locally and GitHub returned HTTP 422, so its claimed byte identity was not independently verified. These limitations do not negate the independently inspected screenshots, recorded runtime observations, and authority-boundary evidence.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +729, Tests +1964, Docs +12. Total +2705 across 35 files.

View PR surface stats
Area Files Added Removed Net
Source 22 1048 319 +729
Tests 12 2104 140 +1964
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 35 3164 459 +2705

Review metrics

Metric Value Why it matters
Production versus test growth production +729 net lines; tests and support +1,964 net lines Production growth implements retained request selection and cleanup settlement; most added coverage exercises ownership races and physical process outcomes.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This repairs bounded native-subagent Stop behavior and truthful cleanup reporting without evidence of a current core-runtime emergency.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-08T00:12:30.980Z sha d8a6537 :: needs changes before merge. :: none
  • reviewed 2026-10-08T00:21:50.921Z sha d8a6537 :: blocked before merge. :: [P2] Preserve routed-child selection after original custody is consumed
  • reviewed 2026-10-08T02:20:37.945Z sha 4b9d1caea08d9c7708ce6b6502f8a43be05ec2bd :: blocked before merge. :: none
  • reviewed 2026-10-08T06:13:15.280Z sha 4b9d1caea08d9c7708ce6b6502f8a43be05ec2bd :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 8, 2026
@shakkernerd
shakkernerd force-pushed the fix/stop-command-continuations branch from 17f964a to 5323982 Compare October 8, 2026 00:40
@shakkernerd
shakkernerd force-pushed the fix/stop-native-descendants branch from d8a6537 to 4b9d1ca Compare October 8, 2026 02:14
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 8, 2026
@shakkernerd
shakkernerd force-pushed the fix/stop-command-continuations branch 2 times, most recently from 9945186 to 71e3277 Compare October 8, 2026 05:38
Base automatically changed from fix/stop-command-continuations to main October 8, 2026 06:04
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Oct 8, 2026
@shakkernerd
shakkernerd force-pushed the fix/stop-native-descendants branch from 4b9d1ca to 0358bd3 Compare October 8, 2026 06:15
@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Oct 8, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 8, 2026
@shakkernerd
shakkernerd merged commit f61b347 into main Oct 8, 2026
153 checks passed
@shakkernerd
shakkernerd deleted the fix/stop-native-descendants branch October 8, 2026 06:29
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: parent Stop drains selected native subagent commands while preserving completed results and independent services.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
Parent Stop drains ordinary commands from selected native subagents, including completed and routed children, while preserving completed results and independent services.

Refs openclaw#160742.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 13, 2026
…166832 et al.)

Conflicts: spawn-pipeline + subagent-spawn + run-launch (openclaw#166832 exec-request
owners ride our ownership-checked registration and acceptance hold), queue
types (upstream retired skillWorkshopProposalRevision; ours kept), plugin-sdk
surface budget 3641 upstream + 11 feature = 3652 (measured), generated
inventory/config baseline regenerated.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant