Repository navigation
Settle the MCP in-flight gauge for clients that hung up before serving - #1577
Merged
Merged
Conversation
helpcodeai
enabled auto-merge (squash)
November 8, 2026 08:25
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
The
mcpRequestsInFlightgauge in thevitalsline drifted up by about 540 per container-day on Cloud while open sockets and memory stayed flat.serveStatelessadds itsres.once('close')listener only after auth, tenant checks and tool planning. When a client hangs up during those steps,closehas already fired, the listener never runs, and the decrement (and themcpAbortedTotalcount) is lost. Each jump matched a burst of 70-150 requests that one workspace's node client aborted within 1 s (1,278 such aborts on 7-8 Nov).Monitoring only: no memory or behaviour impact for customers. Same behaviour on Cloud and self-hosted.
Changes
trackMcpRequestClose()(exported frommcp-endpoint.controller.ts) holds the close handling that was inline inserveStateless.closedordestroyedis settled right away (decrement + abort count) instead of waiting for aclosethat will not come again.Type
Testing
mcp-request-close.spec.ts(normal close, abort before answer, already closed, already destroyed with no double decrement, mock withoutonce).In
packages/backend(afternpm ciandnpx prisma generate):npx jest --maxWorkers=4 src/mcp-server/mcp-request-close.spec.ts src/mcp-server/mcp-endpoint.controller.spec.ts: 2 suites, 57 tests passed.npx tsc --noEmit -p tsconfig.json: clean.npx eslinton both files: clean.Checklist
Related Issues
Found in the 2026-11-08 daily check (Cloud backend vitals line).