Repository navigation
feat(acp): emit subagent lifecycle events and support per-child cancel - #1913
Conversation
Each subagent run now sends a _nanocoder/subagent notification as it starts, progresses and ends (completed, failed or cancelled), carrying a stable childRunId, the parentRunId, the parent agent tool call, name, progress counts and result or error. _nanocoder/cancelSubagent cancels one run through a per-child abort controller under the turn's signal, so the turn and sibling runs carry on and the parent gets a cancelled result; cancelling the turn still cancels every run. The permission request for a subagent tool call names its run under _meta. Both are advertised in agentCapabilities._meta. Closes Nano-Collective#1891
nc-review: comments — 1 nit@addyCooks — a few things worth a look, none blocking. The PR adds the ⚪ nit · The new field table states that // source/subagents/subagent-executor.ts
emitRun?.('completed', {tokenCount: finalTokenCount, result: output});
🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
… signal CI hung in the cancel test because the fake model call only listened for the abort event. A cancel that lands after the loop's aborted check but before the model call hands chat() a signal that is already aborted, which a real client rejects on and the fake never did, so the run never ended and ava killed the spec. Reject on an already-aborted signal, wait for the child's model call before cancelling in the end-to-end test, and add a regression test that cancels from the first progress event, which fires in exactly that window.
Resolves the conflicts with Nano-Collective#1913 (subagent lifecycle events), which touched the same ACP agent, subagent executor and spec files. The subagent now reads the session's mode and disabled tools from one bridge lookup before it announces itself. Also addresses the nc-review comments: the response reports only the tools actually in effect (unknown names are logged and left out), the unknown-tool test no longer matches a substring of a random UUID, and the refusal re-reads the session's list live, as the mode is.
Description
Over ACP a subagent run was visible only as the parent's
agenttool call: no child run ID, no per-child status or result, and the only cancel was the whole turn._nanocoder/subagentnotification as it starts, progresses and ends (completed,failedorcancelled). It carriessessionId, the parentagenttoolCallId, a stablechildRunId,parentRunId(empty for a child of the turn),name,status,tokenCount,toolCallCount,lastTool, and theresultorerror._nanocoder/cancelSubagent {sessionId, childRunId}cancels one run through its own abort controller under the turn's signal. The run reportscancelled, the parentagentcall gets a "Subagent was cancelled" result and carries on, and the turn and sibling runs are untouched. Cancelling the whole turn still cancels every run. It returns{cancelled: false}when the run already ended or belongs to another session._metaasnanocoder/childRunId, passed through the per-session bridge from fix(acp): route subagent tool calls through a per-session bridge #1904.agentCapabilities._meta.nanocoder.agentcard title and thesubagent:approvals are unchanged.Events are scoped by session, so overlapping sessions don't see each other's runs.
cancelSubagenthas no bare-name alias, since no older client sent it.Result threading and approval routing stay with #1105, as the issue says.
Closes #1891
Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist