Skip to content

feat(acp): emit subagent lifecycle events and support per-child cancel - #1913

Merged
addyCooks merged 2 commits into
Nano-Collective:mainfrom
addyCooks:feat/acp-subagent-lifecycle
Oct 29, 2026
Merged

addyCooks merged 2 commits into
Nano-Collective:mainfrom
addyCooks:feat/acp-subagent-lifecycle

Conversation

@addyCooks

Copy link
Copy Markdown
Collaborator

Description

Over ACP a subagent run was visible only as the parent's agent tool call: no child run ID, no per-child status or result, and the only cancel was the whole turn.

  • Each subagent run now sends a _nanocoder/subagent notification as it starts, progresses and ends (completed, failed or cancelled). It carries sessionId, the parent agent toolCallId, a stable childRunId, parentRunId (empty for a child of the turn), name, status, tokenCount, toolCallCount, lastTool, and the result or error.
  • _nanocoder/cancelSubagent {sessionId, childRunId} cancels one run through its own abort controller under the turn's signal. The run reports cancelled, the parent agent call 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.
  • The permission request for a subagent's tool call now names its run under _meta as nanocoder/childRunId, passed through the per-session bridge from fix(acp): route subagent tool calls through a per-session bridge #1904.
  • The notification and the method are listed in agentCapabilities._meta.nanocoder.
  • Clients that ignore the notification see the same behaviour as before: the polled agent card title and the subagent: approvals are unchanged.

Events are scoped by session, so overlapping sessions don't see each other's runs. cancelSubagent has 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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

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
@github-actions github-actions Bot added area:tools Tool implementations and tool-calling area:docs Documentation labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: comments — 1 nit

@addyCooks — a few things worth a look, none blocking.

The PR adds the _nanocoder/subagent notification and the _nanocoder/cancelSubagent method on top of the session-keyed sub-agent bridge, with a per-run AbortController derived from the turn's signal so one child can be cancelled without ending the turn. The core paths are correct and well tested: the per-run controller is registered under the run's randomUUID and deregistered in a finally, cancelSubagentRun refuses a run belonging to another session, turn-level cancel still reaches every child, events are filtered by sessionId, and the notification listener is unsubscribed and drained before the turn returns. The alias split (ACP_EXT_ALIASES vs ACP_EXT_METHODS) correctly gives cancelSubagent a prefixed name only, matching the docs. One documentation inconsistency stands out: the new field table says toolCallCount and lastTool are present on completed events, but the implementation only puts them on progress.

⚪ nit · completeness · docs/features/acp.md

The new field table states that tokenCount, toolCallCount and lastTool are present "on progress and completed events", but the implementation does not send them on completed:

// source/subagents/subagent-executor.ts
emitRun?.('completed', {tokenCount: finalTokenCount, result: output});

toolCallCount and lastTool are only ever set by the progress emit, so a client that follows the table and reads them off the completed event will get undefined for both. The desktop this feature was built for keeps one record per run, so it is exactly the kind of client that will read the final counts from the terminal event. Either add toolCallCount and lastTool to the completed payload, or correct the table to say the three fields are on progress and only tokenCount is on completed.


🔴 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 /re-review.

@github-actions github-actions Bot added the agent:comments nc-review left non-blocking findings label Oct 29, 2026
… 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.
@addyCooks
addyCooks merged commit e30cc60 into Nano-Collective:main Oct 29, 2026
18 checks passed
addyCooks added a commit to addyCooks/nanocoder that referenced this pull request Oct 29, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:comments nc-review left non-blocking findings area:docs Documentation area:tools Tool implementations and tool-calling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Emit subagent lifecycle events over ACP (child run IDs, per-child status and result) and support per-child cancel

1 participant