Skip to content

fix(subagents): notify the parent agent when Stop cancels sub-agents - #205641

Merged
vyctorbrzezowski merged 6 commits into
mainfrom
vyctor/stop-subagents-visible
Nov 29, 2026
Merged

vyctorbrzezowski merged 6 commits into
mainfrom
vyctor/stop-subagents-visible

Conversation

@vyctorbrzezowski

@vyctorbrzezowski vyctorbrzezowski commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

When a person presses Stop in the Control UI (or the macOS app that hosts it) while the agent itself is idle but its sub-agents are still working, the app sends a session-wide sessions.abort. That Stop also cancels every running sub-agent of the session, which is the documented behavior. But canceled children never deliver a completion, and nothing else tells the parent agent what happened, so the agent keeps waiting for results that will never come, or later sees only bare process-exit failures. An orchestrator running several long sub-agents loses hours of work with no trace of why.

Why This Change Was Made

Stop keeps its current meaning; the defect is the silence. Every explicit Stop that cancels sub-agents now queues one system notice for the parent session. It names the canceled sub-agents, says the Stop was deliberate and what kind it was, and tells the agent not to restart the work unless the user asks:

An explicit session Stop from a connected app canceled 2 running sub-agents: slow-a, slow-b. They won't report back. Check their sessions before relying on any partial work, and don't restart them unless the user asks.

For a single sub-agent the sentence is singular ("It won't report back. Check its session…"). Empty labels are skipped, and names beyond the first ten are counted ("slow-a and 2 more").

  • New src/agents/subagents/registry/subagent-stop-notice.ts builds the notice and enqueues it through the existing system-event owner (enqueueSystemEvent). Zero kills queue nothing; labels are normalized, empty ones dropped, and at most 10 are named.
  • The Gateway cancellation owner, abortControlledSubagents, calls it once per request after the cascade settles, when the caller passes an explicit stopSource: session-wide sessions.abort (client-session, "An explicit session Stop from a connected app"), exact-run chat.abort / sessions.abort (client-run, "An explicit Stop of your turn"). An exact-run sessions.abort either stops an embedded run directly or forwards to the chat.abort handler; both paths pass client-run. A session-wide sessions.abort that lands on an active embedded run takes the same turn-scoped path, so its notice reads as a Stop of that turn.
  • Chat /stop (stopSubagentsForRequester) uses the same helper (channel-user, "A user /stop command"). It already replied "Stopped N sub-agents" to the person; now the agent learns it too.
  • The notice is a queued system event: it doesn't start a turn and doesn't touch the stable prompt prefix; the parent's next turn reads it.
  • Docs: docs/tools/subagents/operations.md ("Stopping").

No protocol, schema or config change. Which sub-agents a Stop selects is unchanged.

User Impact

After an explicit Stop, the parent agent's next turn says which sub-agents were canceled and by what kind of Stop, so it stops waiting for them, can inspect their sessions, and does not restart work a person just stopped. Non-explicit cancellations (shutdown, timeouts) are unchanged.

Not in this PR: whether the Control UI should offer a session-wide Stop (or map Escape to it) when only sub-agents are running. That is a product decision and is left for a follow-up.

Evidence

  • Regression test: src/gateway/server-methods/chat.abort-cascade.test.ts "tells the requester's next turn which children a session/exact run Stop canceled" — red on the base, green with the fix. src/agents/subagents/registry/subagent-stop-notice.test.ts covers the singular sentence, an empty label, one name with more remaining, and two names with more remaining.
  • Consumer tests: all chat.abort*, sessions.abort*, agent.abort* suites in src/gateway/server-methods plus subagent-control.test.ts and the auto-reply abort tests pass (32 files on the final head). oxlint and oxfmt clean on touched files; git diff --check clean.
  • End to end, isolated Gateway (own state and port), real agent on a real model (openai/gpt-6.1-sol through the Codex runtime): the parent spawns two sub-agents that run sleep 900, ends its turn, then the script sends exactly what the Control UI Stop sends when no local run id is known: sessions.abort {key, clearQueued: true, userInitiated: true}. Both runs: the sub-agents are killed and their processes are gone. Then the parent is asked whether its sub-agents are still running.
    • Base: "There is no system notice about their running status in this turn."
    • Fix: quoted the notice verbatim and answered that they were canceled.
    • This run used the earlier notice wording (it said "cancelled" and suggested spawning replacements). The wording was revised after review and was not rerun end to end; the unit and Gateway tests above cover the final text.
  • Local review: autoreview (Codex) on the committed branch range against origin/main, P0 and P2 thresholds: no findings (the reviewer saw the diff only). I checked by hand that the two sessions.abort branches are exclusive, so one request queues one notice.

🦞 Made with OpenClaw

@clawsweeper

clawsweeper Bot commented Nov 25, 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: S labels Nov 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 74e858c1fb72a8148dbbac53eb9da909f604e759, but the PR head is now 7008981077d856ca6c371508913620480c60ecb9. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-26T00:11:57.351Z sha 74e858c :: needs changes before merge. :: [P2] [P2] Include native-child identities in the Stop notice

@vyctorbrzezowski vyctorbrzezowski changed the title fix: tell the agent which sub-agents a Stop cancelled fix(subagents): notify the parent agent when Stop cancels sub-agents Nov 26, 2026
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 27, 2026
@vyctorbrzezowski vyctorbrzezowski self-assigned this Nov 28, 2026
Preserve the subagent runtime cancellation owner and opt into the existing notice only from explicit Stop adapters. Access-loss cancellation retains its own notification behavior.
@vyctorbrzezowski
vyctorbrzezowski marked this pull request as ready for review November 29, 2026 17:22
@vyctorbrzezowski
vyctorbrzezowski merged commit 50016b3 into main Nov 29, 2026
106 of 109 checks passed
@vyctorbrzezowski
vyctorbrzezowski deleted the vyctor/stop-subagents-visible branch November 29, 2026 17:23
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…205641)

* fix(gateway): tell the requester which sub-agents a Stop cancelled

* fix(subagents): share the Stop notice with chat /stop

* fix(subagents): clarify the Stop notice

* test(gateway): match the clarified Stop notice

* fix(subagents): match the Stop notice to reviewed wording

(cherry picked from commit 50016b3)

Release adaptation: Keep the beta Gateway cancellation owner and its existing authority fences; only explicit Stop entry points opt into a notice after cancellation settles.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…penclaw#205641)

* fix(gateway): tell the requester which sub-agents a Stop cancelled

* fix(subagents): share the Stop notice with chat /stop

* fix(subagents): clarify the Stop notice

* test(gateway): match the clarified Stop notice

* fix(subagents): match the Stop notice to reviewed wording
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 impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant