nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Parallel subagents hang the turn, a second approval request overwrites the first

Open addyCooks opened this issue 3 months ago • 1 comments

Description

All three "ask the user" queues store exactly one resolver in a useRef. A second concurrent signal() overwrites it before the first has been answered, and that first promise is orphaned permanently nothing can ever resolve it.

This is reachable through ordinary use: tool-executor starts up to MAX_CONCURRENT_AGENTS (5) subagents at once, and each can call a tool that needs approval. Because the batch is awaited with Promise.allSettled, one orphaned promise means the batch never settles and the turn never ends.

Environment

  • OS: all (no platform-specific code involved)
  • Node version: v22.22.3
  • Nanocoder version: 1.30.0
  • Provider: any
  • Model: any

Steps to Reproduce

  1. In normal mode, have the model emit two or more agent tool calls in one turn.
  2. Have both subagents call a tool that needs approval (write_file, execute_bash).
  3. Answer the single prompt that appears.

Expected Behavior

Each approval request is queued and presented in turn, and every subagent promise settles approved, denied, or cancelled.

Actual Behavior

Only the most recent request is answerable. Earlier ones never settle, and the turn hangs forever. Escape does not help: the stranded subagent is parked inside an await that is not abort-aware. Recovery requires killing the process.

agent-A promise settled          : false
agent-B promise settled          : true
Promise.all([A,B]) outcome       : TIMEOUT, a promise never settled

(Driven against the real useGlobalHandlerQueues hook through ink-testing-library, firing two signalToolApproval calls before answering. AVA additionally reported Failed to exit for the run the orphaned promise kept the worker alive.)

Logs/Screenshots

  • source/app/hooks/useGlobalHandlerQueues.tsx:41,65,92, one resolver ref per queue
  • source/app/hooks/useGlobalHandlerQueues.tsx:46,74,101, xResolverRef.current = resolve, assigned unconditionally, so a second caller overwrites the first
  • source/app/hooks/useGlobalHandlerQueues.tsx:75, setPendingSubagentApproval(approval) also overwrites the visible prompt, so the user never sees the request they strand
  • source/subagents/subagent-executor.ts:65, MAX_CONCURRENT_AGENTS = 5
  • source/subagents/subagent-executor.ts:739, await signalToolApproval(...), no AbortSignal
  • source/hooks/chat-handler/conversation/tool-executor.tsx:360, await Promise.allSettled(...)
  • source/utils/global-handler-slot.ts, the slot holds one handler; the single-resolver problem is in the hook above it, not here

Additional Context

The same single-slot design backs ask_user (question-queue) and the main agent's tool confirmation (tool-confirm-queue), so the defect is not specific to subagent approvals subagents are just the path that reaches it routinely.

Suggested fix: replace the single resolver ref in each of the three slots with a FIFO of {id, input, resolve}. Render the head of the queue, resolve by id, and show a "1 of N" indicator. Make signal() accept an AbortSignal and reject on abort so cancelling a turn drains the queue instead of stranding it.

Related but distinct: #1019 covered the ACP failure of the same module (no handler installed, so the fallback denied silently) and is closed. This is the TUI failure a handler exists, but concurrent callers overwrite each other's resolvers. The in-progress sub-agent tool bridge work also does not cover this: that channel is registered per session on the ACP path, and the TUI still goes through signalToolApproval and the single-resolver hook.

  • [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 avatar Sep 02 '26 12:09 addyCooks

hey @akramcodez! could you assign this one to me?

addyCooks avatar Sep 02 '26 12:09 addyCooks