Repository navigation
Forward a client's cancellation to vMCP backends - #7342
Merged
Merged
Conversation
When a call to a Legacy backend was cancelled, the vMCP closed its per-request backend client before go-sdk had sent notifications/cancelled from its background goroutine, so the notice was dropped and the backend tool ran to completion. Keep a cancelled request's client open long enough for the notice to go out, then close it in the background. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7342 +/- ##
==========================================
+ Coverage 82.40% 82.42% +0.02%
==========================================
Files 937 937
Lines 95821 95844 +23
==========================================
+ Hits 78962 79002 +40
+ Misses 16854 16837 -17
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
approved these changes
Nov 26, 2026
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a client cancels a tool call, the vMCP now passes the cancellation on to the backend, so the backend tool stops instead of running to completion.
Before: the client sends
notifications/cancelled(Legacy) or closes its request (Modern). The vMCP cancels its own handler and answerscontext canceled, but the backend's tool never sees its context cancelled. With separate processes this happened every time; in-process it was intermittent.After: the backend tool's context is cancelled, on Legacy and on Modern.
Cause
For a Legacy backend, the vMCP opens a client per request and closes it when the request returns. When the request's context is cancelled, go-sdk (v1.8.0, and still in v1.9.0-pre.1) retires the call at once and sends
notifications/cancelledfrom a background goroutine, so the caller is not held up. The vMCP's deferredClose()ran immediately; once closing has started and no call is in flight, go-sdk'sNotifyrefuses to write, and the notice was dropped.A Modern client hits the same path whenever the backend is Legacy: closing the request cancels the vMCP handler, which cancels the Legacy backend call.
Fix
closePerCallClientreplaces the deferredClose()on the five Legacy per-request paths (list, call, read, prompt, complete). A request that ended normally closes its client at once, as before. A cancelled one closes it in the background after 6 seconds, which is longer than go-sdk's 5-second budget for sending the notice. The vMCP's reply is not delayed; the cost is a backend connection kept open for up to 6 seconds after a cancellation.The pinned per-session backend client (
pkg/vmcp/session/internal/backend) is long-lived and not closed after each call, so it is unaffected.A cleaner fix belongs in go-sdk:
Close()could send pending cancel notices before closing. If that lands, the delay can go.Testing
pkg/vmcp/server/cancellation_realbackend_integration_test.go: a real Legacy backend whose tool blocks until cancelled, behind the real vMCP server and backend client. One test cancels through a Legacy client (notifications/cancelled), the other closes a Modern request; each repeats 5 times. Both fail onmainin the first round and pass with the fix.go test -race ./pkg/vmcp/...task lint🤖 Generated with Claude Code