nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Escape does not cancel in-flight MCP, fetch_url and web_search calls

Open akramcodez opened this issue 3 weeks ago • 2 comments

Description

Pressing Escape does not actually cancel tool calls that are not execute_bash or a subagent. The abort signal is not passed down to MCP tool calls, fetch_url or web_search, so the turn waits for the call to finish on its own.

From reading the code:

  • source/mcp/tool-adapter.ts defines execute: async (input, _options) and ignores the options, which is where the SDK passes abortSignal.
  • source/mcp/mcp-client.ts callTool calls client.callTool({name, arguments}) with no signal in the request options.
  • source/tools/fetch-url.tsx and source/tools/web-search.tsx only use AbortSignal.timeout(...); the user's cancellation is not combined with it.
  • processToolUse in source/message-handler.ts awaits handler(parsedArgs, options) with no race against the abort signal.
  • Only execute_bash and the agent tool consume abortSignal.

Environment

  • OS: macOS (platform independent)
  • Node version: v22.23.4
  • Nanocoder version: 1.32.0 (main at 1b6571cc)
  • Provider: any
  • Model: any

Steps to Reproduce

  1. Connect an MCP server that has a slow tool (a long query, a browser automation step, anything that takes 30 seconds or more).
  2. Ask the agent to call it.
  3. Press Escape while the tool is running.

The same applies to fetch_url against a slow or hanging server (up to its timeout).

Expected Behavior

The turn ends immediately, the in-flight request is aborted (for MCP, a cancellation notification is sent to the server), and the prompt is returned to the user.

Actual Behavior

The UI keeps waiting until the tool resolves or hits its own timeout, and the MCP server keeps doing the work. This was derived from reading the code and not reproduced end to end, so please treat the exact UI behaviour as unconfirmed.

Logs/Screenshots

Not applicable.

Additional Context

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

Suggested direction: forward options.abortSignal from the SDK tool wrapper through callTool to the MCP client's request options ({signal}), combine it with AbortSignal.any([signal, AbortSignal.timeout(...)]) in fetch_url and web_search, and make processToolUse race the handler against the signal so a tool that ignores it still cannot block the prompt.

akramcodez avatar Nov 12 '26 14:11 akramcodez

I’m taking the MCP cancellation path first: I’ll forward the turn’s abort signal through Nanocoder’s MCP adapter to the MCP SDK request and add a regression test for an in-flight cancellation. This is a scoped slice; I’ll keep the separate fetch_url/web_search paths explicitly outstanding rather than claim the full issue is resolved.

ducanhnguyen223 avatar Nov 13 '26 03:11 ducanhnguyen223

Hi @ducanhnguyen223, this is a reminder that you need to comment on an issue and be assigned to it before opening a PR. This has come up more than once now. Please follow this process going forward. If PRs keep getting opened without an assignment, we’ll restrict further contributions from your account. Thanks for understanding.

addyCooks avatar Nov 14 '26 07:11 addyCooks