Repository navigation
Description
Description
Over ACP, a subagent run is visible only as the parent's agent tool call. The client gets no child run ID, no parent link, no per-child status or result, and cannot cancel one child. The only cancel is the whole turn.
I'd like Nanocoder to emit subagent lifecycle events to ACP clients and accept a per-child cancel, in a way clients can detect, and without changing what clients that ignore the events see today.
This issue is about the child run itself: its identity, status, final result and cancel. The results of tool calls inside a subagent, and routing subagent approvals by session, are tracked in #1105.
Tracked from Nano-Collective/nanocoder-desktop#12 (item 5). Related: #1105, #1156, #1080 and #1019 (earlier subagent approval fixes).
Use Case
Nanocoder Desktop's success item SP-05 is "delegate a bounded subtask, observe the child run, and stop it when needed". It wants to show each child as its own run with live status, attribute approval requests to the right child, and let the user stop one child without cancelling the whole turn. The desktop stores one record per run (child ID, parent run, subagent name, status), so it needs those four fields from Nanocoder.
Today:
- Progress reaches the client as a polled title on the parent's
agentcard, refreshed every 1.5 seconds. - When several subagents run at once, the card shows only the one with the most tokens.
- There is no ID that ties a
subagent:-prefixed permission request to a particular child. - "Stop" on a child can only cancel the whole turn.
Any ACP client that shows subagents has the same limits. The desktop ships a fallback that renders plain tool cards, so this is not blocking. It is needed for the full SP-05 experience, which the desktop plans by its Milestone 1.
Proposed Solution
All of this is additive and ignorable by clients that don't know about it.
- A subagent notification. For example
_nanocoder/subagent(ACP reserves the underscore prefix for custom methods), carrying:- the
sessionId - the parent tool call ID
- a child run ID
- a parent run ID, empty for children of the root turn, so nested subagents form a tree
- the subagent name
- a status:
started,progress,completed,failedorcancelled - progress fields (token count, tool call count, last tool)
- on completion, the result or error summary
- the
- Per-child cancel. An extension method such as
_nanocoder/cancelSubagent {sessionId, childRunId}, backed by a per-child abort controller derived from the turn's signal. Cancelling the whole turn still aborts every child. A cancelled child returns a "cancelled" result to the parent so the parent can continue. - Attribution of approvals. Include the child run ID in the
_metaof the existingsubagent:permission requests. - Capability advertising. List the extension under
_metainagentCapabilities, so clients detect support from the capability and never need to compare Nanocoder versions. - Unchanged for other clients. Keep the existing polled title and
subagent:-prefixed approvals as they are.
Alternatives Considered
- Do nothing. Clients keep a tool-card fallback and whole-turn cancel.
- Make each child its own ACP session with a parent link. That would let the existing
session/cancelwork per child, but it is a much larger change and affects session storage and retention. - Only add child IDs to the existing polled card title. Cheap, but it gives no status events or per-child cancel, and clients would have to parse text.
Additional Context
- I have searched existing issues to ensure this is not a duplicate
- This feature aligns with the project's goals (local-first AI assistance)
Current behavior, checked against main at fc01e23:
source/acp/acp-conversation.ts(~L667-704): while anagenttool call runs, a 1.5 s interval readsgetAllSubagentProgress(), picks the entry with the highesttokenCount, and updates the parent card's title. Progress entries from earlier calls are skipped.source/tools/agent-tool.tsxcreates arandomUUID()agent ID for every subagent (~L68 for parallel runs, ~L138 for single runs) and passes it to the executor. It is never sent to the client.source/subagents/subagent-executor.ts: subagents receive the turn's abort signal (~L223, L635, L798), so cancel is whole-turn only.MAX_SUBAGENT_DEPTH = 2andMAX_CONCURRENT_AGENTS = 5.source/utils/tool-approval-queue.ts: one process-wide approval slot, with "last writer wins".acp-conversation.ts(~L166-177) documents that overlapping sessions can answer each other's approvals. ACP: thread sub-agent tool results back so every call is announced and settles with its real status #1105 tracks fixing this.source/acp/acp-conversation.ts(~L98-161): an approved subagent call is marked completed at approval time, before it runs. ACP: thread sub-agent tool results back so every call is announced and settles with its real status #1105 tracks fixing this too.docs/features/acp.mdlists these as known limitations.
Implementation Notes (optional)
This overlaps with #1105. Its session-keyed bridge, with begin and end callbacks around each subagent tool call, is the natural place to emit events, and it also fixes the approval routing that attribution depends on. I'd suggest landing #1105 first and building this on top of it.
The child ID already exists (agentId), and the executor already updates per-agent progress (updateSubagentProgressById, ~L622), so the data for started and progress events is available. The _nanocoder/subagent name and field names above are suggestions. The maintainers should decide the real shape.
Acceptance criteria:
- A subagent run emits
started,progressand a finalcompleted,failedorcancelledevent with a stable child run ID. - Events carry the
sessionIdand parent run ID, and stay correct when two sessions run subagents. - Concurrent children each emit their own events.
-
subagent:permission requests carry the child run ID. - A client can cancel one child without ending the turn, and the parent receives a "cancelled" result.
- Cancelling the turn cancels all children.
- Clients that ignore the extension see the same behavior as today.
- The extension is advertised under
_metainagentCapabilities. - Docs describe the events and the cancel method.
Test plan:
- ACP spec: a single subagent emits the full event sequence.
- ACP spec: two concurrent subagents emit separate event streams.
- ACP spec: a nested subagent reports its parent run ID.
- ACP spec: per-child cancel ends one child and the turn continues.
- ACP spec: whole-turn cancel ends all children.
- ACP spec: two sessions with subagents don't mix events.
- Regression: the polled title and approvals still work when events are ignored.
Out of scope: how a client displays children, the subagent depth and concurrency limits, tool-call results inside a subagent, and approval routing (both tracked in #1105).
Activity
feat(acp): emit subagent lifecycle events and support per-child cancel (