Skip to content

feat(vmcp): let backends opt out of list_changed propagation - #6635

Closed
aron-muon wants to merge 2 commits into
stacklok:mainfrom
aron-muon:fix/vmcp-list-changed-optout
Closed

aron-muon wants to merge 2 commits into
stacklok:mainfrom
aron-muon:fix/vmcp-list-changed-optout

Conversation

@aron-muon

Copy link
Copy Markdown
Contributor

Summary

Background: subscribing to a backend's list_changed notifications opens a standalone notification stream, and that happens inside session initialize. A backend that accepts the subscribe and then never services it stalls the handshake for the whole init allowance, and clients with their own connect timeout give up first.

The gate for this already exists. createMCPClient only sets WithContinuousListening() when the sink is non-nil, and the comment there is explicit about why:

Gated strictly on sink != nil: some backends hang when this stream is opened against them (#5748 R3), so it must stay opt-in.

In practice it isn't opt-in, though - server.go builds a sink for every session, so every backend gets subscribed and that safety valve is unreachable from a running deployment.

This PR:

  • added operational.listChanged, with enabled and disabledWorkloads
  • added session.WithListChangedFilter, a per-backend predicate. When it returns false the factory drops the sink for that backend only, which is what stops the connector opening the stream
  • prefer disabledWorkloads for the common case - one bad backend shouldn't cost the other 14 their live propagation
  • default is unchanged. No config means every backend is subscribed exactly as before, and a nil filter leaves the dial path identical

An excluded backend loses live propagation and nothing else. Its tools are still aggregated and callable, and they refresh on the next session.

This is the follow-up to #6633, which bounds the same stall with a configurable init timeout. That one caps the damage, this one removes the dependency - they're independent and either is useful on its own.

Type of change

  • New feature

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)
  • Manual testing (describe below)

go test ./pkg/vmcp/... and the operator unit tests pass. golangci-lint run ./pkg/vmcp/... is clean at 0 issues. Regenerated with task operator-generate, task operator-manifests and task crdref-gen; task gen and task license-check leave the tree clean.

New tests: TestSessionFactory_ListChangedFilter asserts the connector receives a sink for subscribed backends and nil for excluded ones (that nil is the whole mechanism), plus a case proving a nil-sink caller is unaffected by the filter. TestListChangedFilter covers the config to predicate mapping including enabled: false winning over an exclusion list.

Manual: hit this on 0.47.1 against Grafana Cloud's hosted MCP, which is stateless and mandates per-user auth. Its own audit log shows the handshake succeeding and then the stream sitting there until the client gives up at exactly 30s:

12:45:01  detected initialize method call
12:45:01  upstream response received  status: 200  mcp_session_id: mcp-session-6ae468e9-...
12:45:01  AUDIT mcp_initialize  outcome: success
12:45:01  outbound request to upstream  GET /mcp  accept: text/event-stream
12:45:31  http: proxy error: context canceled
12:45:31  AUDIT sse_connection  outcome: error

vMCP's own log stops after creating session-scoped backends and never reaches the Failed to initialise backend warning, because the client has already gone.

Worth noting why that backend can't dodge this on its own: it's Modern, so initOneBackend would skip the connect entirely, but the revision probe runs unauthenticated from the health monitor, gets a 401, and probeRevision quite reasonably leaves a 401 uncached as a transient auth blip. So it never classifies, and because no session ever completes, no authenticated call reaches dispatch to warm the cache either.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

listChanged is a new optional field on OperationalConfig. Nothing is removed or retyped.

Does this introduce a user-facing change?

Yes. New optional operational.listChanged, letting an operator exclude backends from live list_changed propagation. Unset keeps today's behaviour.

Special notes for reviewers

I went with config rather than making it automatic on purpose - I couldn't find a signal that reliably separates "will never service this stream" from "is just slow right now", and guessing wrong silently drops propagation. If you'd rather infer it, or put the switch somewhere other than operational, happy to move it.

The deeper fix is presumably for the stream to not gate initialize at all, but that sits in mcpcompat/go-sdk rather than here, so this is the smallest thing that makes session init independent of it.

Subscribing to a backend's list_changed notifications opens a standalone
notification stream during session initialization. A backend that accepts
the subscribe and then never services it stalls the handshake until the
init deadline, and clients with their own connect timeout give up first.

The connector already treats a nil sink as "do not subscribe" and the
comment there says the stream must stay opt-in because some backends hang
on it, but the server supplies a sink for every session, so in production
that gate was unreachable.

Add operational.listChanged, and a WithListChangedFilter factory option,
so a single misbehaving backend can be excluded while the rest keep live
propagation. An excluded backend loses only that: its tools are still
aggregated and callable, and they refresh on the next session.

Default is unchanged. With no config every backend is subscribed exactly
as before.
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.95%. Comparing base (c25e508) to head (203fa28).

Files with missing lines Patch % Lines
pkg/vmcp/cli/serve.go 86.66% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6635   +/-   ##
=======================================
  Coverage   78.94%   78.95%           
=======================================
  Files         781      781           
  Lines       77784    77811   +27     
=======================================
+ Hits        61410    61439   +29     
+ Misses      16369    16367    -2     
  Partials        5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

crd-schema-checker's ListsMustHaveSSATags rejects an array with no
x-kubernetes-list-type. Matches MCPGroup.Servers, the closest analogue:
an unordered list of workload names where duplicates are meaningless.
@aron-muon

Copy link
Copy Markdown
Contributor Author

Folded into #6633. These conflicted with each other - same three source files plus the same generated CRDs - and they're two ends of one bug, so reviewing them together is easier than landing one and rebasing the other.

@aron-muon aron-muon closed this Sep 10, 2026
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.

1 participant