An MCP tool call interrupted with Ctrl-C is reported to the model as "Operation cancelled", although no cancellation was sent and the server completed it
What happened?
With an MCP server over streamable HTTP, we sent SIGINT (what Ctrl-C sends) to Gemini CLI in -p mode while a call to one of its tools was in flight, then resumed with gemini --resume latest -p "Continue.". The tool appends a line to a file, either at once and answering 30 s later, or 3 s after the call starts. The resumed history gives the call's result as "[Operation Cancelled] Operation cancelled." (6 of 6 runs). But Gemini CLI sent no notifications/cancelled to the server (the server logs every message), and the server's write took effect in every run, before the stop or after it. After SIGKILL instead, the resumed result is the check-first text below. For a shell command stopped the same way, Gemini CLI gives a much better result: "It may have executed partially or completed — check system state before running again."
This matters for what the model does next. Resumed against five open-weight model families (DeepSeek V4 Pro, Kimi K3.1 Pro, MiMo V2.6 Flash, MiniMax M3.1 Flash, Qwen3.8 Flash; 3 runs each, through a proxy that translates the Gemini API to an OpenAI-compatible endpoint), the model wrote the line again (with a shell command; none called the tool again) in 14 of 15 runs where the first write had landed, and read the file first in 2. With the result replaced by a text saying the server may already have completed the operation or may still be running it, and to check first, it wrote the line again in 8 of 15 and read first in 9.
What did you expect to happen?
The result should not claim the operation was cancelled: a remote call can complete after the client stops waiting, and MCP's cancellation is advisory even when it is sent. Something like the shell's text ("may have executed partially or completed — check … before running again") would be accurate.
Client information
- CLI version: 0.70.0 (npm
@google/gemini-cli), headless-pwith--yolo - Platform: Linux (Debian 12 container, aarch64), Node 22
- MCP server registered in
~/.gemini/settings.jsonwithhttpUrlandtrust: true
Login information
API key (GEMINI_API_KEY), with GOOGLE_GEMINI_BASE_URL pointing at a scripted model server for the model-free runs and at the translating proxy for the real-model runs.
Anything else we need to know?
A minimal stdlib MCP server and the runner are available if useful.
There is a problem with the Gemini CLI issue triaging. Please check the action logs for details.
This still looks reproducible at the scheduler boundary on current main: packages/core/src/scheduler/tool-executor.ts sends MCP execution through the generic createCancelledResult, which records [Operation Cancelled] ... without distinguishing local cancellation from a remote call whose outcome is unknown. DiscoveredMCPTool is already available in that module, so the change can stay scoped to MCP cancellation responses and leave shell cancellation behavior unchanged.
I can add a regression using DiscoveredMCPTool and an aborted signal, then implement the narrower uncertainty wording if this is suitable for community work. Could a maintainer please mark it help-wanted?
The two call sites in tool-executor.ts already behave differently, and that gap is the fix target.
The abort-with-result branch at 153 passes toolResult into createCancelledResult, which keeps llmContent and only injects an error marker beside it, so the model still sees what the tool produced. Your report matches the catch branch at 185 instead, where there is no toolResult and the response becomes a bare error. That branch cannot know the outcome, and the shape it emits tells the model the opposite of your measurement: an error reads as failure, which is consistent with 14 of 15 rewrites.
So the change is not the message. A remote MCP call aborted mid-flight should resolve to an indeterminate outcome, worded so a resumed session verifies before retrying, while locally executed work can keep the cancelled wording because the client really did stop it. Keeping the result when one exists is already handled and should not be touched.
The wire half is separate and real: nothing under packages/core/src sends notifications/cancelled, so the server holds a request the client stopped reading, which is why it completed the write in every run.
One thing the numbers show that the wording fix does not cover: with the better text the model still wrote the line again in 8 of 15 runs. Accurate wording lowers the repeat rate. It does not remove it.
Two additions would close more of the gap. Keep the interrupted call in the resumed history with its arguments and start time, so the model has something concrete to check against, not only a status line. And on the server side, a write tool should accept a caller key and return the stored result when it sees that key again.
A limit on the second point: in these runs the models repeated the write with a shell command, not the tool, so a key on the tool would not have caught them. It covers the model that calls the tool again. The check-first text still has to carry the rest.
Both additions point at real gaps, with one correction on the first.
The call itself already survives: the functionCall part with its name and arguments is in the model's own turn, and createCancelledResult reads startTime off the call before building the response, so the ingredients exist at the object level. What the cancelled response currently does with them is the defect, not their absence. On your 8 of 15, that means wording is an upper bound of what a text change can buy, which is why the two structural pieces matter more.
On the key: make it a normalized operation signature (tool name plus non volatile arguments), not only a caller supplied id. A per caller key cannot dedupe an agent that reconnects with a new session id, which is the common shape here.
Your shell caveat is the important limit. Nothing on the tool side catches a repeated write issued as a shell command, and no wording fixes it reliably. The partial cover is ordering: have the resumed prompt verify state with a read before any write, not after the model has already decided to retry.
A correction to the model numbers above. In those runs the task prompt asked the model to append the lines "using the shell" while the interrupted call was the MCP tool, and several models took that difference for the reason they had been stopped and wrote the line with the shell. We re-ran the cell with the prompt naming the tool (GLM-5.3 in place of Qwen3.8 Flash; 3 runs each; the first write had landed):
- After "[Operation Cancelled] Operation cancelled." the model called the tool again in 15 of 15 runs (reported: 14 of 15), none reading the file first. Every repeat now went through the tool itself, so "with a shell command; none called the tool again" came from our prompt.
- With the result replaced by the text saying the server may already have completed the operation, or may still be running it, and to check first: 1 of 15 (reported: 8 of 15), with the file read first in 14.
So the "cancelled" result leads to a duplicate write as reported, and an accurate result prevents it more clearly than we said.