[Bug] Escape does not cancel in-flight MCP, fetch_url and web_search calls
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.tsdefinesexecute: async (input, _options)and ignores the options, which is where the SDK passesabortSignal.source/mcp/mcp-client.tscallToolcallsclient.callTool({name, arguments})with nosignalin the request options.source/tools/fetch-url.tsxandsource/tools/web-search.tsxonly useAbortSignal.timeout(...); the user's cancellation is not combined with it.processToolUseinsource/message-handler.tsawaitshandler(parsedArgs, options)with no race against the abort signal.- Only
execute_bashand the agent tool consumeabortSignal.
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
- Connect an MCP server that has a slow tool (a long query, a browser automation step, anything that takes 30 seconds or more).
- Ask the agent to call it.
- 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.
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.
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.