Repository navigation
fix(vmcp): bound initialize to healthCheckTimeout - #6380
RaviTharuma wants to merge 23 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Automated fix: rebased onto main (20 commits). Remaining golangci findings are in operator files this PR does not touch (gci/staticcheck SA1019). |
72f5609 to
880e09d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6380 +/- ##
=======================================
Coverage 79.64% 79.65%
=======================================
Files 816 816
Lines 83168 83201 +33
=======================================
+ Hits 66242 66275 +33
Misses 16921 16921
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e14a014 to
cdf9562
Compare
cdf9562 to
6f61794
Compare
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent vMCP client-facing initialize from hanging past typical gateway/client timeouts while /health and the VirtualMCPServer Ready signal remain green, by introducing an overall session initialization budget tied to healthCheckTimeout and documenting the distinction between liveness, readiness, and session init.
Changes:
- Add an overall
sessionInitTimeoutbudget to the vMCP session factory to boundMakeSessioninitialization time (best-effort: slow backends are skipped). - Wire
failureHandling.healthCheckTimeoutinto the session factory as the initialize budget (default remains 10s). - Document Health vs Ready vs
initialize, and propagate updated field descriptions into generated/operator docs and CRDs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/vmcp/session/factory.go | Introduces default session init budget + option, applies timeout context, and logs when budget expires. |
| pkg/vmcp/session/default_session_test.go | Adds unit tests for the new session init timeout option and bounding behavior. |
| pkg/vmcp/server/server.go | Clarifies /health as liveness-only and distinguishes it from readiness/session init. |
| pkg/vmcp/config/config.go | Documents that healthCheckTimeout also bounds client session initialize across backends. |
| pkg/vmcp/cli/serve.go | Plumbs failureHandling.healthCheckTimeout into WithSessionInitTimeout. |
| docs/operator/virtualmcpserver-api.md | Adds operator-facing documentation on Health vs Ready vs initialize semantics. |
| docs/operator/crd-api.md | Updates CRD API docs to reflect the expanded meaning of healthCheckTimeout. |
| deploy/charts/operator-crds/templates/toolhive.stacklok.dev_virtualmcpservers.yaml | Updates chart CRD template descriptions for healthCheckTimeout. |
| deploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_virtualmcpservers.yaml | Updates packaged CRD descriptions for healthCheckTimeout. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
191387a to
02a515e
Compare
|
Gentle ping — |
|
I was taking another look and I think we shouldn't bind it to the healhchecks, typically healthchecks timeouts are shorter and should be simple, I think this could cause issues. Below some options: Good fix — bounding One change I'd like before merge: give Please add a dedicated field (e.g. |
A new session waited on every backend's 30s init timeout, so initialize could hang past gateway limits while Ready and /health stayed OK. Cap MakeSession to healthCheckTimeout (default 10s) and document the three signals. Fixes stacklok#6345
Signed-off-by: Ravi Tharuma <[email protected]>
Queued backend init must not block on the semaphore after the session budget expires. Warn only on deadline exceeded; log caller cancel at debug. Co-authored-by: Ravi Tharuma <[email protected]>
sessionFactoryOptions now wires WithSessionInitTimeout from healthCheckTimeout; cover that branch in the option-count tests. Co-authored-by: Ravi Tharuma <[email protected]>
55fd597 to
f5d80f5
Compare
|
@reyortiz3 thanks — agreed that coupling initialize to I'll add a dedicated |
Initialize must not share healthCheckTimeout so tuning health-check cadence does not skip backends on new sessions. Unset values inherit healthCheckTimeout. CRD and validator updated. Co-authored-by: Ravi Tharuma <[email protected]>
|
@reyortiz3 dedicated |
|
@reyortiz3 friendly ping — dedicated |
|
@reyortiz3 gentle ping — dedicated |
|
@reyortiz3 gentle ping — dedicated |
aponcedeleonch
left a comment
There was a problem hiding this comment.
Thanks for adding the dedicated field, @RaviTharuma, and sorry this sat so long after your pings. I went through the current head. The cancellation side looks good: the deadline is scoped to the backend fan-out, the semaphore acquire honors the context, and nothing leaks. I left a few inline comments on things I'd like to sort out before merging.
On tests, I'd like to see the combination with backendInit and the request-timeout resolver, mixed fast and slow backends (asserting the fast ones are kept), and the restore path.
On the housekeeping side, the PR description still describes the healthCheckTimeout wiring and no CRD change, and 22 of 23 commits are missing the DCO Signed-off-by. A squash with a sign-off would cover both.
| // typical client/gateway timeouts while Ready and /health stayed OK | ||
| // (#6345). 10s matches the HealthCheckTimeout CRD default, which | ||
| // sessionInitTimeout inherits when unset. | ||
| defaultSessionInitTimeout = 10 * time.Second |
There was a problem hiding this comment.
This default is always on, which changes behavior from main. Today there's no session-level cap: each backend gets 30s by default, extended by the workload request timeout, and #6633 added operational.timeouts.backendInit on top. Since every per-backend context derives from this one, the effective budget becomes the lower of the two. A backend with a legitimate 10-30s handshake (cold start, token exchange) gets dropped from every session, and any backendInit above 10s stops having an effect. I'd rather have no overall cap unless it's configured.
| if f.sessionInitTimeout > 0 { | ||
| var cancel context.CancelFunc | ||
| ctx, cancel = context.WithTimeout(ctx, f.sessionInitTimeout) | ||
| defer cancel() | ||
| } |
There was a problem hiding this comment.
makeBaseSession is shared with RestoreSession, so restores are capped too, which isn't documented or tested. Also, a backend skipped here is left out of the session's backend IDs, so it won't be reconnected on a later restore and the session loses list_changed from it for good. Worth documenting, ideally with a test.
| // keep current behavior. Set this independently when health-check cadence | ||
| // should not affect how long a new session waits for backends. | ||
| // +optional | ||
| SessionInitTimeout Duration `json:"sessionInitTimeout,omitempty" yaml:"sessionInitTimeout,omitempty"` |
There was a problem hiding this comment.
Now that #6633 added operational.timeouts.backendInit, I think timeouts.sessionInit is a better home for this than failureHandling. It keeps the two init budgets next to each other and makes it easier to document how they combine.
| if fh.HealthCheckTimeout > 0 { | ||
| return time.Duration(fh.HealthCheckTimeout) | ||
| } |
There was a problem hiding this comment.
I'd drop this fallback. It keeps the coupling with the probe timeout we wanted to avoid: someone with a 2s healthCheckTimeout would end up with a 2s initialize budget. Also, the doc comment says existing configs keep current behavior, but main has no session-level cap today, so they don't.
| // Validate session initialize timeout. Zero means unset and inherits | ||
| // HealthCheckTimeout at runtime; negative values are invalid. | ||
| sessionInitTimeout := time.Duration(fh.SessionInitTimeout) | ||
| if sessionInitTimeout < 0 { |
There was a problem hiding this comment.
If we keep both settings, it'd be good to validate how they relate here, e.g. warn or reject when backendInit is above sessionInit, since that per-backend value can never be reached.
| | --- | --- | --- | | ||
| | `GET /health` | Process is up (liveness). Always 200 if the HTTP server answers. | A new MCP session can `initialize` before your gateway times out. | | ||
| | CR `Ready` / backend `Healthy` | Last `ListCapabilities` probe succeeded within `healthCheckTimeout`. | The next client `initialize` will finish in that same budget. | | ||
| | Client `initialize` | A new session connected to backends (best-effort). Bounded by `sessionInitTimeout` (defaults to `healthCheckTimeout`, then 10s). | Every backend completed the full handshake. Slow ones are skipped when the budget expires. | |
There was a problem hiding this comment.
This overstates what's bounded. Only the backend fan-out in CreateSession is covered. Capability aggregation and the per-session optimizer setup (which can do an embedding round-trip per tool) run afterwards during session registration and aren't bounded by this. Same for the summary on line 391 and the comment in server.go. Either scope the docs to the backend fan-out, or move the bound so it wraps the whole registration.
Cross-links
Summary
VirtualMCPServer Ready and
GET /healthcould stay OK while a new client'sinitializehung past typical gateway timeouts (12s) with a 0-byte response.Those signals are different operations:
/healthis liveness, Ready is thelast
ListCapabilitiesprobe, and initialize waits on backend handshakes(per-backend 30s, concurrency 10). This does not flip Ready/
/healthoninitialize failure (that would flap). It bounds the handshake.
MakeSessionbudget defaults to 10s (same as CRDhealthCheckTimeout)WithSessionInitTimeoutfromfailureHandling.healthCheckTimeoutwhen set
Fixes #6345
Type of change
Test plan
go test -ldflags=-extldflags=-Wl,-w ./pkg/vmcp/session/ -run 'TestWithSessionInitTimeout|TestNewSessionFactory_SessionInitTimeout|TestNewSessionFactory_BackendInitTimeout|TestNewSessionFactory_AllBackendsFail'healthCheckTimeout;/healthremains liveness-onlyAPI Compatibility
This does not change the CRD schema.
healthCheckTimeoutalready exists; itnow also bounds session initialize.
Does this introduce a user-facing change?
Yes. New vMCP sessions finish initialize within
healthCheckTimeout(default 10s). Slow backends are omitted from that session instead of
blocking the client.
/healthis documented as liveness only.Special notes for reviewers
Direction from #6345: Ready is ListCapabilities, initialize is a different
handshake. Bounding + documenting is the agreed path; a separate SessionReady
signal is left for a follow-up if you want it.