Repository navigation
fix(mcp): count the error flag in error result budgets - #2848
Merged
morluto merged 1 commit intoOct 13, 2026
Merged
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Error results reach the wire as text plus `isError: true`, but the text-only envelope omitted the flag. An error up to 15 bytes above the result budget passed both the delivery and transport checks and was sent as the original diagnostic instead of taking the oversized-error recovery path. Rename the error representation to "error-text" and size its envelope with the flag, so ToolResultDelivery and the error transport share the complete delivered shape. Successful structured results are unchanged. Fixes morluto#2557 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
shubhamahuja9999
force-pushed
the
fix/mcp-error-result-budget-flag
branch
from
October 13, 2026 14:39
4a09bd4 to
01a1ad0
Compare
11 tasks done
Owner
|
Thanks, @shubhamahuja9999, for counting |
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
Fixes #2557
Error results reach the MCP wire as text plus
isError: true(and the target-content_metamarker when applicable). Their budget accounting omitted the 15-byte,"isError":truemember, so an error up to 15 bytes above the result budget passed both delivery checks and was sent as the original diagnostic instead of taking the existing oversized-error recovery path.Problem and expected behavior
Smallest trigger: a projected tool error whose delivered result (
content+isError, without the privatestructuredContentcarrier) is exactlyresultBudgetBytes + 1bytes. Onmainthe client receives the originalinvalid_requesterror. Expected: theresource_constraintrecovery diagnostic, as for any other oversized error. An error that exactly fits the budget must still arrive unchanged.Violated invariant:
encodeToolResultaccounts for the delivered representation before allocation (toolResultEncoding.ts), but its text-only envelope did not match the delivered error shape.ToolResultDelivery.projectedErrorResultandErrorEvidenceTransport.recoverErrorboth inherited the omission.Change and scope
src/server/toolResultEncoding.ts: the text-only representation is used only for errors, so it is renamed from"text"to"error-text"and its envelope is sized from{ content: [...], isError: true }. This fixes the owning representation once instead of adding 15 bytes at each caller.src/server/toolResult.tsandsrc/server/EvidenceMcpServer.ts: both error budget checks use"error-text", so they keep sharing one accounting.docs/mcp-contracts.md: the result-budget paragraph now says the error text andisErrorflag count against the budget."structured-and-text"accounting is unchanged.response_bytes_at_leastlower bound are unchanged.Contribution scope: ordinary fix within existing boundaries; maintainer decision not applicable.
Contract and boundary impact
encodeToolResulterror envelope accounting (src/server/toolResultEncoding.ts).resource_constraintrecovery path; all other errors and all successful results are unchanged.docs:checkpasses).Expected effects:
None of these apply: this changes MCP response size accounting only.
Evidence and regression coverage
tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts, "applies the result budget to the complete delivered error", for bothtargetContent: falseandtrue. It runs the productionToolResultDeliveryandEvidenceMcpServerwith the SDK client over linked in-memory transports. An error whose delivered wire is exactlyresultBudgetBytesarrives as the original diagnostic; one byte larger yieldsresource_constraintwithoriginal_error_code: "invalid_request".src/server/toolResultEncoding.test.tscases for text-only errors measured the expected bytes withoutisError, which encoded the bug. They now measure the delivered error shape, with and without_meta.48a683ac8with the new test and without the fix, both new cases fail (the client receivesinvalid_request; 2 failed, 4 passed). With the fix, all 6 pass.resource_constraintdiagnostic.For evidence-bearing changes:
Validation performed
Windows 11, Node.js 24.18.0, npm 11.16.0, rebased on
mainat6e25cc3c7:npm run test:focused -- tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts: the new cases failed without the fix (the client receivedinvalid_request; 2 failed, 4 passed, first reproduced on48a683ac8). With the fix,oversizedErrorDeliveryMcp,toolResultEncodingandlargeToolResultpass 20/20.npm run test:focused --the 38 test files that referenceToolResultDelivery,toolResultEncoding,EvidenceMcpServer,resultBudgetBytesorresource_constraint: the same 42 tests fail with and without this change. They are Windows-environment cases such as native-command capture, HAR/qlog heap limits, and Flutter APK extraction. The failure sets are identical, so there are no new failures, and every new or updated test passes.npm run check:fast(typecheck and lint): passed, including as the pre-push hook.npm run docs:check: passed (6/6 tasks, README consistency 4/4).npm run verify:module-boundariesandoxfmt --checkon changed files: passed.Compatibility, safety, and release
ToolResultRepresentationsis internal tosrc/server/; its two callers are updated.Before merge
type(scope): outcome.🤖 Generated with Claude Code