Skip to content

Commit ad00ba8

Browse files
authored
fix(agents): stop queued Swarm collectors with their parent (#133076)
* fix(agents): stop queued Swarm collectors with their parent Preserve exact parent-run ownership independently of completion delivery. Hold selected queue reservations before cancellation, retain lexical ownership through recovery and retirement, and publish task results only while that owner remains current. Bind first-turn chat cancellation to the prepared canonical session and preserve original transcript incarnations. Keep foreign and replacement work untouched, initiate native and ACP cancellation together, and report incomplete cancellation truthfully. Fixes #131553 * fix(tasks): keep cancellation contracts out of runtime cycles * test(ui): wait for responsive attachment layout * fix(agents): expose and cancel queued Swarm collectors Persist child labels at creation and project exact scheduler-owned queued work without inventing an execution context or start clock. Preserve operator renames when delayed launches begin. Route direct queued-child Stop through the existing fenced kill owner and shared Gateway cancellation plan. Preserve requester ownership, canonical abort markers, coexisting work, synchronous publication, and the original Stop reason during native preaccept admission draining. Finalize captured chat output even when later collector cancellation loses authority, and report incomplete cancellation instead of success when other owners keep the selected collector queued. Keep transcript snapshots and persistence in the existing transcript owner, with a lazy placement boundary instead of loading the cancellation owner. Cover session lists, history, events, typed Stop, exact Stop, native preaccept admission, replacement, retirement, and foreign requester cases. Consolidate the attachment layout regression with the upstream readiness fix while retaining desktop materialization and strict geometry checks. * test(gateway): repair session lifecycle fixtures * test(gateway): align cancellation fixtures with lifecycle cleanup
1 parent d8fe500 commit ad00ba8

93 files changed

Lines changed: 11183 additions & 2185 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/tools/subagents.md‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,9 @@ from a single orchestrator.
535535

536536
### Cascade stop
537537

538-
Stopping a depth-1 orchestrator automatically stops all its depth-2
539-
children:
540-
541-
- `/stop` in the main chat stops all depth-1 agents and cascades to their depth-2 children.
538+
Explicit cancellation of a depth-1 orchestrator cascades to its depth-2
539+
children. `/stop` in the main chat applies to that requester's child tree.
540+
See [Stopping](/tools/subagents#stopping) for scope and incomplete-cancellation behavior.
542541

543542
## Authentication
544543

@@ -734,7 +733,31 @@ still need normal device approval for scope upgrades.
734733

735734
## Stopping
736735

737-
- Sending `/stop` in the requester chat aborts the requester session and stops any active sub-agent runs spawned from it, cascading to nested children.
736+
An explicit Stop targeting a parent run cancels the children associated with that
737+
run and their descendants, including ordinary sub-agents and [Swarm](/tools/swarm)
738+
collectors. Successful cancellation keeps selected queued collectors from
739+
starting while running children stop. Exact-run cancellation does not cancel
740+
unrelated turns or clear unrelated session-wide queues.
741+
742+
For Gateway callers, `chat.abort` with a `runId` uses this exact-parent scope.
743+
`sessions.abort` with a `runId` also targets that run. When it resolves a recovered
744+
native run without a chat controller, it cancels children only if the captured
745+
active parent accepts Stop; a declined or no-active-run result, including an
746+
already-finalizing parent, leaves those children alone.
747+
748+
Sending `/stop` in the requester chat has broader scope: it aborts requester
749+
session work, clears its queues, and cancels its active child tree. Session-wide
750+
`sessions.abort` also requests descendant cancellation; clearing queued follow-ups
751+
requires `clearQueued: true`. Ordinary `chat.abort` without a `runId` does not
752+
cascade to children. These operations retain their normal authorization checks.
753+
754+
Incomplete cancellation is reported as an error, not a clean success. `/stop`
755+
reports actual stopped and failed child counts. Inspect the remaining
756+
[background tasks](/automation/tasks#control-ui) and retry their cancellation;
757+
request acknowledgment does not mean all runtime cleanup is instantaneous.
758+
759+
Accepted children remain independent after ordinary parent completion, yield, or
760+
timeout. Those events do not automatically cancel them.
738761

739762
## Limitations
740763

‎docs/tools/swarm.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,24 @@ Collector results remain waitable until their group is archived. After every
324324
member reaches its retention deadline, OpenClaw archives the group's children
325325
as a batch so completed swarms do not remain in the live session tree.
326326

327+
## Stop a Swarm
328+
329+
Use **Stop** in the parent chat to cancel a running swarm. A Stop targeting a
330+
specific parent run also cancels its associated collector children and their
331+
nested descendants. Collector mode changes result delivery, not cancellation
332+
scope. Successful cancellation prevents selected queued children from starting
333+
as running siblings stop; it does not cancel work from unrelated parent turns.
334+
335+
If Stop reports incomplete descendant cancellation, inspect the remaining work
336+
on the [Tasks page](/automation/tasks#control-ui) and retry cancellation for
337+
those children. A stopped parent alone does not confirm that every child stopped,
338+
and a cancellation acknowledgment does not promise instantaneous runtime cleanup.
339+
340+
Already-accepted children remain independent when the parent completes normally,
341+
yields, or times out. If the parent is no longer active, cancel the child tasks
342+
directly. See [Sub-agent stopping](/tools/subagents#stopping) for exact-run and
343+
session-wide Stop scopes.
344+
327345
## Use Swarm from other harnesses
328346

329347
You can use Swarm without OpenClaw Code Mode. Its core tools are

‎docs/web/control-ui.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,15 @@ Chat error banners, including cloud runner failures, keep a compact preview. Ope
635635
</Accordion>
636636
<Accordion title="Stop and abort">
637637
- Click **Stop**. Runs with an exact local run ID call `chat.abort`; when selected-session state reports active work but the Control UI has no local run ID, it calls `sessions.abort` instead. For non-global sessions, that selected-session path also discards queued follow-ups so they cannot restart work after the stop.
638+
- Exact-run Stop cancels that parent's associated sub-agents and Swarm collectors, including their descendants. Successful cancellation prevents selected queued children from starting while running siblings stop; it leaves unrelated parent turns and session-wide queues alone.
639+
- If Stop reports incomplete descendant cancellation, inspect **Tasks** and retry cancellation for the remaining children. Do not treat the parent's stopped state as confirmation that every child stopped or that runtime cleanup was instantaneous. See [Sub-agent stopping](/tools/subagents#stopping) for scope details.
638640
- While a run is active, normal follow-ups use the Gateway's effective `messages.queue` mode. `steer` injects into the running turn; other modes keep the browser's durable queued delivery. Steering rejection also falls back to that queue. Click **Steer** on a queued message to inject it manually. Text already streamed in an open chat stays before the steering message across history refreshes and reconnects; subsequent updates show only the continuation below it.
639641
- With **Settings → Appearance → Send shortcut** set to **Enter**, **Cmd/Ctrl+Enter** submits the opposite follow-up action while connected to an active run: queue when Enter steers, or steer when Enter queues (including inherited `collect` and `followup` modes). The send button tooltip shows both actions for the current follow-up setting. This affects only that message, not your saved preference. With the **Cmd/Ctrl+Enter** send shortcut selected, modified Enter remains the normal send action and plain Enter inserts a newline. Interrupt mode keeps its normal behavior.
640642
- Reorder the queue from the handle on the left of a queued message: drag it, or focus it and press the up and down arrow keys. The position is stored with the message, so it survives a reload and decides delivery order, not just what the list looks like. Rows already handed to a run — sending, steering, running a command, awaiting settings, or waiting on an uncertain delivery — hold their place and split the queue: a message moves only among the rows between two of them, so it can never reach the Gateway ahead of work already handed over.
641643
- Edit a queued message with the pencil on its row, or by double-clicking the row. The row becomes its own textarea and stays in place while the main composer remains independent, including any separate draft and attachments. Submit replaces the row in the same slot and preserves its attachments; Cancel or Escape discards the row-local draft and restores the queued message. A normal composer send remains a separate queued item even while a row edit is open. The queue behind an edited row waits rather than delivering a message you are still rewriting, so that row splits the queue for reordering the same way an in-flight row does. Queued slash commands keep the discard-and-retype flow.
642644
- **Settings → Appearance → Chat → Follow-ups while the agent is working** can override that server default for the current browser. The page marks an override explicitly and offers **Reset to server default**. `Steer into the active run` sends follow-ups immediately, while `Queue until the run ends` holds them until the run finishes.
643645
- Type `/stop` (or standalone abort phrases like `stop`, `stop action`, `stop run`, `stop openclaw`, `please stop`) to abort out-of-band.
644-
- `chat.abort` supports `{ sessionKey }` (no `runId`) to abort all active runs for that session. The Control UI uses `sessions.abort` when it has no local run ID.
646+
- `chat.abort` supports `{ sessionKey }` (no `runId`) to abort authorized active runs for that session without cascading to children. The Control UI uses the broader `sessions.abort` path when it has no local run ID.
645647

646648
</Accordion>
647649
<Accordion title="Abort partial retention">

‎src/agents/agent-tool-source-execution-guard.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import { copyAgentToolMetadata } from "./agent-tool-metadata.js";
22
import type { AnyAgentTool } from "./agent-tools.types.js";
3+
import { getGatewayToolCallerIdentity } from "./tools/gateway-caller-context.js";
4+
5+
/** Freeze the invocation's operational fence before asynchronous source work. */
6+
export function captureAgentToolSourceExecutionGuard(signal?: AbortSignal): () => void {
7+
// This host closure checks the exact delegated claim, even with audit disabled;
8+
// neither diagnostic identity tokens nor their collection grant authority.
9+
const authority = getGatewayToolCallerIdentity()?.receiptAuthority;
10+
return () => {
11+
signal?.throwIfAborted();
12+
if (authority?.() === false) {
13+
throw new Error("tool invocation authority is no longer active");
14+
}
15+
};
16+
}
317

418
const sourceExecutionGuards = new WeakMap<AnyAgentTool, () => void>();
519

0 commit comments

Comments
 (0)