Skip to content

fix(mcp): keep a cancelled call id occupied until its call finishes - #624

Closed
princejain756 wants to merge 1 commit into
vercel-labs:mainfrom
princejain756:fix/mcp-cancel-id-reuse
Closed

princejain756 wants to merge 1 commit into
vercel-labs:mainfrom
princejain756:fix/mcp-cancel-id-reuse

Conversation

@princejain756

Copy link
Copy Markdown

Fixes #599.

Calls::cancel removed the id's entry while the cancelled call was still running, so a tools/call reusing the same id was admitted and the two calls shared the registry slot: the cancelled call's thread could take the new call's child and send its output as the response, or the new call answered Cancelled for a request that was never cancelled.

The registry now keeps the id in a Cancelled state until its own call's finish frees it, so a reused id gets the existing -32600 "a call with this id is running" refusal until the cancelled call completes.

Verified over a real MCP session: cancelling desktop_wait ms:5000 (id 1) then re-sending id 1 previously answered {"id":1,"result":{"text":"Cancelled"}} from the new call's thread; now it returns {"error":{"code":-32600,"message":"Invalid Request: a call with this id is running"}}. Regression test in calls_tests.rs; cargo test --bin agent-desktop is 229 passed, clippy -D warnings clean.

Calls::cancel removed the id's entry while the cancelled call was still
running. A new tools/call reusing that id was then admitted, and the two
calls shared the registry slot: the cancelled call's thread could take the
new call's child and send its output as the response, or the new call got
no start slot and answered Cancelled for a request that was never
cancelled. Once both finished, the id could no longer be cancelled at all.

The registry now keeps the entry in a Cancelled state instead of removing
it, and finish is the only place that frees the id. A reused id gets the
existing -32600 a call with this id is running refusal until the cancelled
call itself completes. Regression test covers the sequence.
@vercel

vercel Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@princejain756 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@princejain756

Copy link
Copy Markdown
Author

Superseded: #602 landed the same fix on main (keep a cancelled call id occupied until its call finishes, Slot::Cancelled, plus a matching regression test). Closing; thanks for the reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: cancelling a call frees its id while the call is still running

1 participant