Skip to content

fix(acp): route subagent tool calls through a per-session bridge - #1904

Merged
akramcodez merged 4 commits into
Nano-Collective:mainfrom
addyCooks:fix/acp-subagent-tool-bridge
Oct 29, 2026
Merged

akramcodez merged 4 commits into
Nano-Collective:mainfrom
addyCooks:fix/acp-subagent-tool-bridge

Conversation

@addyCooks

Copy link
Copy Markdown
Collaborator

Description

Subagent tool calls reached an ACP client only when they needed approval, and an approved call was marked completed at approval time instead of when it ran. Approvals ignored the session's mode, and one process-wide slot served every session, so two sessions mid-turn could answer each other's prompts.

This registers a bridge under the session id for the length of a turn. SubagentExecutor now:

  • announces every tool call through it, not only the ones needing approval;
  • asks it for approval using the session's own mode, the same rules the top-level loop uses;
  • settles each call with its real result, so a call that fails after approval shows as failed.

Card ids are scoped per subagent (subagent:<agentId>:<callId>), so two subagents that name a call call_1 can't overwrite each other's card. Calls without a bridge, such as the Ink UI and headless runs, still use the global approval slot, so their behavior is unchanged.

Also removes the matching limitation from docs/features/acp.md.

Closes #1105

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)

An ACP client only saw the subagent tool calls that needed approval, and
those were marked completed when approved rather than when they ran.
Approvals ignored the session's mode, and one process-wide slot served
every session, so two sessions mid-turn could answer each other's prompts.

Register a bridge under the session id for the length of a turn. The
subagent executor announces every call through it, asks it for approval
using the session's own mode, and settles each call with its real result.
Calls without a bridge, such as the Ink UI, still use the global slot.

Closes Nano-Collective#1105
@github-actions github-actions Bot added the area:docs Documentation label Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

nc-review: comments — 1 important, 2 nits

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

The PR replaces ACP's process-wide subagent approval slot with a per-session bridge, so every subagent tool call is announced, approved under the session's own mode, and settled with the tool's real outcome. The wiring is correct: processToolUse passes sessionId through to the agent tool, the executor looks the bridge up by that id, the bridge reads session.developmentMode live, and the subagent:<agentId>:<callId> id scoping keeps concurrent subagents from overwriting each other's cards. The three problems in #1105 (missing announcement, completed at approval time, cross-session approval) are addressed. One real gap remains: the bridge's failed flag only recognises structured isError results, so the several built-in tools that signal failure by returning a plain "Error: ..." string still settle their card as completed — the same tools the top-level ACP path handles with a content.startsWith('Error') check.

🟠 important · correctness · source/subagents/subagent-executor.ts

The bridge is settled with !!failed, and failed is computed as typeof result !== 'string' && 'isError' in result && result.isError. Several built-in tools signal failure by returning a plain string that starts with "Error: " instead of a structured isError result — git_status (source/tools/git/git-status.tsx:222), git_log, git_diff, git_add, git_commit, git_pr, file_op (source/tools/file-ops/file-op.tsx:39) and search_file_contents (source/tools/search-file-contents.tsx:40,57,62) all do. For those, failed is false, so the ACP card settles as completed even though the call failed.

This is the same class of bug the PR exists to fix, and it is inconsistent with the top-level ACP path, which checks both signals:

// source/acp/acp-conversation.ts
const status: ToolCallStatus =
    toolResult.isError || toolResult.content.startsWith('Error')
        ? 'failed'
        : 'completed';

So in one client, a failing search_file_contents inside a subagent shows a green completed card while the same tool called at the top level shows failed. A subagent searching an invalid path, or running git_status outside a repository, hits this on a routine basis, and the error text is the only signal that anything went wrong.

The fix is to mirror the top-level check when computing the flag passed to finish, e.g. const failed = structured isError || content.startsWith('Error'). The PR's own tests cover the thrown-error path and a structured isError, so a regression test for the plain-string case would be worth adding alongside the fix.

⚪ nit · completeness · source/subagents/subagent-executor.ts

The bridge is set up after three early returns in executeToolCall — the signal?.aborted check, the "Tool '' is not available to this subagent" check, and the "Tool '' not found" check. Calls that hit those paths return before bridge.begin() is called, so they are never announced to the client and never settled: a subagent that hallucinates a tool name, or one that is denied a tool by its own instructions, leaves no trace in the ACP client at all.

This is not a regression (the pre-PR code only ever announced approval-gated calls), but it does leave a hole in the PR's stated goal that "every tool call is announced". begin() needs the parsed ToolCall, which is built after the allow-list check, so closing this means constructing the ToolCall earlier or moving the bridge lookup above the early returns — worth deciding deliberately rather than leaving it implicit.

⚪ nit · completeness · source/subagents/subagent-executor.ts

The PR makes the approval decision follow the session's mode (bridge.getMode()), but the subagent's tool set is still filtered by the executor's own mode: getAvailableToolNames(config) is filtered with this.currentMode() at the top of execute(), and the ACP executor is built in source/plain/initialize.ts:121 with parentMode: 'normal' and no mode resolver (only the Ink app calls setModeResolver).

So in a plan-mode ACP session the top-level agent is offered no mutating tools at all, while its subagents are still offered write_file, string_replace, execute_bash and git_pr — and, now that the approval decision uses the session's plan mode, those calls still prompt rather than being structurally excluded.

This is pre-existing and unchanged by the diff, and #1105 only asked about the prompting symptom, so it is not a reason to hold this PR. Flagging it because the PR took on "mode" as part of the issue and a plan-mode ACP subagent is still strictly more capable than a plan-mode top-level agent. The same applies to the plain (non-ACP) shell, which has no bridge and so keeps the executor's static mode for both filtering and approval.


🔴 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 27, 2026
… session mode

Address review feedback on the subagent tool bridge:

- A tool that reports failure as plain "Error..." text now settles its
  card as failed, matching the top-level ACP path, not only structured
  isError results.
- A call refused before it runs (cancelled, tool not offered to the
  subagent, tool not found) is announced and settled as failed instead of
  leaving no trace in the client.
- A subagent in an ACP session is offered, and held to, the tools of that
  session's mode rather than the shared executor's static mode.
The plain shell built its subagent executor in a fixed 'normal' mode, so
a plan or headless run offered its subagents tools the main agent is not
offered. Pass the run's mode through initializePlain so subagent tool
filtering and approval match the main agent.

The ACP server and verify keep the 'normal' default; ACP sessions get
their mode from the per-session bridge instead.
@akramcodez
akramcodez merged commit 6493fe0 into Nano-Collective:main Oct 29, 2026
18 checks passed
diyaavirmani added a commit to diyaavirmani/nanocoder that referenced this pull request Nov 2, 2026
Resolves the conflict in the subagent tool loop with Nano-Collective#1904, which scopes
a subagent's tool call ids and adds subagentRunId to its execution
context: the refusal of a call with unparsable arguments is kept, and
the call to executeToolCall takes upstream's id and context.
diyaavirmani added a commit to diyaavirmani/nanocoder that referenced this pull request Nov 2, 2026
Since Nano-Collective#1904 a client that takes subagent tool calls (ACP) is shown every
call, including one refused before it runs, so a bad call leaves a trace.
The refusal of a call with unparsable arguments ran in the loop, before
executeToolCall, so the client never saw that call. It now runs inside
executeToolCall after the bridge is told the call began, and the call is
settled as failed with the parse error.
addyCooks pushed a commit that referenced this pull request Nov 6, 2026
…id JSON (#1855) (#1901)

* fix(ai-sdk-client): stop hidden SDK retries of a tool call with invalid JSON

When a native tool call's arguments weren't valid JSON (a typo, or a call
cut off at the output-token limit), the AI SDK answered it with an
automatic error and asked the model again, up to MAX_TOOL_STEPS (10)
times inside one chat() call. stopOnUnknownTool only stopped that for
unknown tools, so these requests were missing from steps and usage, and
the retry limits only applied after each hidden batch. The broken call
then came back with its raw text as the arguments, was executed as
"Invalid tool arguments" and was replayed to the provider double-encoded.

The step loop now stops on any call the SDK marks invalid
(stopOnInvalidToolCall). A call whose input isn't a JSON object is
converted with `{}` as its arguments and the parse error in a new
ToolCall.argumentsError. The shared partition used by the TUI, plain and
ACP loops rejects such a call like an unknown tool: it isn't run or
offered for approval, the model is told what was wrong, and the turn
counts toward maxRepeatedToolCalls. processToolUse and the subagent
executor refuse it too, so no path runs a tool with the `{}` placeholder.

Closes #1855.

* fix(subagents): let a bridge see a call refused for unparsable arguments

Since #1904 a client that takes subagent tool calls (ACP) is shown every
call, including one refused before it runs, so a bad call leaves a trace.
The refusal of a call with unparsable arguments ran in the loop, before
executeToolCall, so the client never saw that call. It now runs inside
executeToolCall after the bridge is told the call began, and the call is
settled as failed with the parse error.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP: thread sub-agent tool results back so every call is announced and settles with its real status

2 participants