nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] ACP ignores session/set_mode sent during a turn; tools keep the old mode's approval rules

Open diyaavirmani opened this issue 1 month ago • 2 comments

Description

In ACP mode, a session/set_mode sent while a prompt is running is accepted ({} is returned), but the running turn ignores it. Tools keep using the old mode's availability and approval rules until the whole prompt ends.

So if you notice the agent doing something you don't like in yolo or auto-accept and switch to normal in the VS Code sidebar, the next bash commands and file edits in that same turn still run with no permission prompt. The mode dropdown stays enabled during a turn, so this is easy to do.

The TUI already handles this: it reads the mode live on every tool call, so a mid-turn switch takes effect right away (source/hooks/chat-handler/conversation/conversation-loop.tsx:143-149). ACP doesn't.

Environment

  • OS: macOS (Darwin 25.6.0, x86_64)
  • Node version: 22.23.3
  • Nanocoder version: main at ef4e79ec, and v1.31.0
  • Provider: a local OpenAI-compatible test server with scripted responses
  • Model: n/a (scripted)
  • Client: a script using @agentclientprotocol/sdk 1.4.0 (the repo's locked version) over stdio against nanocoder --acp

Steps to Reproduce

The client denies every session/request_permission, so a tool can only run if nanocoder skips the prompt.

  1. Start nanocoder --acp, create a session and set its mode to yolo.
  2. Send a prompt. The model calls execute_bash to create first.txt, waits 3 seconds, then calls execute_bash to create second.txt.
  3. As soon as the first call reaches completed, send session/set_mode with modeId: "normal". It returns {}.
  4. Let the turn finish and check for second.txt.
  5. Repeat with auto-accept and write_file instead of yolo and execute_bash.

Expected Behavior

After set_mode returns, the next tool call follows the new mode. In normal mode that means a permission request, which this client denies, so second.txt is never created.

The ACP SDK says setting the mode "can be called at any time during a session, whether the Agent is idle or actively generating a turn" (Agent.setSessionMode in @agentclientprotocol/sdk), and normal mode is "Confirm each tool before execution".

Actual Behavior

Case Permission requests the client saw second.txt created
yolo, switched to normal mid-turn (execute_bash) none yes
switched to normal before the prompt (control) call_1, call_2 no (denied)
auto-accept, switched to normal mid-turn (write_file) none yes
switched to normal before the prompt (control) call_1, call_2 no (denied)

Same result on main ef4e79ec and on v1.31.0.

Logs/Screenshots

What I think is going on:

  • runTurn reads the mode once per prompt: const {developmentMode, abortController} = session; (source/acp/acp-conversation.ts:211).
  • Every later step in that prompt uses this copy, both for which tools are offered (getAvailableToolNames(..., developmentMode), acp-conversation.ts:305-307) and for approval (evaluateNeedsApproval(..., developmentMode), acp-conversation.ts:568-572).
  • setSessionMode updates session.developmentMode and rebuilds the system prompt (source/acp/acp-agent.ts:531-547), and the loop re-reads the system prompt on every step (acp-conversation.ts:350). So after a mid-turn switch to plan, the model is told it's in plan mode but still has the editing tools, under the old approval rules.

Additional Context

Proposed fix (happy to adjust): read session.developmentMode live on each step and each tool call instead of once per prompt, like the TUI's developmentModeRef. The tool list for the next model request and every approval decision would then follow the latest mode. A tool call that's already running wouldn't change; the switch would apply to the next one.

For tests: an ACP conversation spec that switches from yolo to normal between two tool calls and expects a permission request for the second call, plus the reverse switch (normal to yolo), where the second call runs without a prompt.

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

@addyCooks could you take a look when you have a moment? I'd like to work on this one, so please assign it to me if that works for you.

diyaavirmani avatar Oct 19 '26 22:10 diyaavirmani

Hi @addyCooks, I'd like to work on this issue. I see the reporter also expressed interest, so could you confirm availability and assign it to @macjayz if appropriate?

I've inspected the current ACP conversation code: runTurn() captures developmentMode once and reuses it for tool availability and approval decisions. My proposed scope is to read the current session mode at the relevant execution boundaries, including tool calls already returned by the model when the mode changes.

I plan to add deterministic regression tests for yolo-to-normal, normal-to-yolo, and switching to plan mode between tool calls, verifying that denied or disallowed writes do not execute. Already-running tools would finish under their existing execution boundary. I'll also check that the change stays isolated to the correct session.

macjayz avatar Oct 23 '26 14:10 macjayz

I'm taking this one. Nanocoder Desktop (Nano-Collective/nanocoder-desktop#12, item 3) depends on it, so it's a priority.

@diyaavirmani, @macjayz: thanks for the report, the repro and the offers to help. I'm assigning this to myself so we don't duplicate work..

Findings on current main (fc01e23): const {developmentMode, abortController} = session; is still at source/acp/acp-conversation.ts:211. The captured value is used in three places:

  • tool availability (getAvailableToolNames, ~L305)
  • the plan-mode fallback (~L447)
  • approval (evaluateNeedsApproval, ~L568-572)

The fix will read session.developmentMode live in all three.

Cases the PR will cover:

  1. Tool calls the model already returned: each is checked against the live mode just before it runs, so a switch to plan keeps edit tools from running.
  2. A permission request already pending: it stays valid for that call, and the new mode applies from the next call.
  3. Subagents: I'll check whether they follow the parent session's mode, and report back here.
  4. Per-session isolation: a change in one session doesn't affect another.

Tests (in acp-conversation.spec.ts): yolo to normal, normal to yolo, a switch to plan between tool calls, a returned batch when the mode changes, and two sessions where only one changes mode.

If we ever decide not to support mid-turn changes, session/set_mode should return an error instead of {}. For now I'm applying them.

addyCooks avatar Oct 26 '26 16:10 addyCooks