Skip to content

Commit 49ec295

Browse files
committed
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
1 parent 65beb1e commit 49ec295

69 files changed

Lines changed: 9423 additions & 2042 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
@@ -537,10 +537,9 @@ from a single orchestrator.
537537

538538
### Cascade stop
539539

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

545544
## Authentication
546545

@@ -736,7 +735,31 @@ still need normal device approval for scope upgrades.
736735

737736
## Stopping
738737

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

741764
## Limitations
742765

‎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)