Repository navigation
fix(acp): route subagent tool calls through a per-session bridge - #1904
Conversation
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
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: 🟠 important · The bridge is settled with 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 The fix is to mirror the top-level check when computing the flag passed to ⚪ nit · The bridge is set up after three early returns in 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". ⚪ nit · The PR makes the approval decision follow the session's mode ( So in a plan-mode ACP session the top-level agent is offered no mutating tools at all, while its subagents are still offered 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 |
… 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.
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.
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.
…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.
Description
Subagent tool calls reached an ACP client only when they needed approval, and an approved call was marked
completedat 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.
SubagentExecutornow:failed.Card ids are scoped per subagent (
subagent:<agentId>:<callId>), so two subagents that name a callcall_1can'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
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist