nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

Abort-aware draining for the approval/question queues (queued prompts survive a cancelled turn)

Open addyCooks opened this issue 2 months ago • 2 comments

Description

Follow-up to #1156 / #1159. #1159 replaced the single-resolver useRef in each of the three "ask the user" slots (question-queue, tool-approval-queue, tool-confirm-queue) with a FIFO, so concurrent callers no longer overwrite each other's resolver and every caller settles.

What #1159 deliberately left out: the queue is not abort-aware. If a turn is cancelled while requests are queued, those entries are not drained — they stay queued and keep being presented, so after cancellation the user is still asked to answer prompts for a turn that is already dead.

The old single-resolver code accidentally "self-healed" here: a stray answer after cancellation just clobbered whatever resolver happened to be installed, so it went unnoticed. The new FIFO code queues correctly instead of clobbering, which makes the missing drain-on-abort behavior visible for the first time.

Suggested Fix

From #1156's original suggested fix: make signal() accept an AbortSignal and reject on abort, so cancelling a turn drains that slot's queue instead of leaving stale entries behind.

This touches createGlobalHandlerSlot's signature (source/utils/global-handler-slot.ts) and every call site, notably source/subagents/subagent-executor.ts:739 (await signalToolApproval(...)), which the in-progress sub-agent tool bridge work (#1105) is also editing — coordinate with that PR to avoid a signature conflict.

Related

  • #1156 (original bug)
  • #1159 (fix: FIFO queuing) — review comment calling this out as a follow-up
  • #1105 (sub-agent tool bridge — touches the same call site)

addyCooks avatar Sep 07 '26 16:09 addyCooks

Hi @akramcodez, would you mind assigning this one to me? Happy to take it on.

Had a look and the gap is still there: signal() in global-handler-slot.ts takes only (input), and there's no abort/drain handling in any of the queue modules, so queued entries still outlive a cancelled turn. I'd follow the suggested fix, thread an AbortSignal through signal(), reject and drain on abort, with tests per slot.

Small note: the call site referenced in the description has moved, it's subagent-executor.ts:847 now, not 739.

@will-lamerton, has #1105 landed yet? It touches that same signalToolApproval(...) call site, so I'd rather sequence behind it than risk a signature conflict. Thanks!

addyCooks avatar Sep 19 '26 18:09 addyCooks

Fixed in 428c0850: queued approvals and questions are now released when the turn is cancelled.

Closing as part of a backlog tidy-up. Reopen it if anything here is still broken.

will-lamerton avatar Oct 07 '26 10:10 will-lamerton