Repository navigation
Release a refused 402's body, and leave the evidence parse bounded by bytes - #324
Merged
Merged
Conversation
sigvaraX402Fetch threw on a refused 402 without reading or cancelling the response it held, so a body cut off at the 64 KiB limit kept its connection open until the seller or a timeout closed it. Every refusal now cancels the body, a failed chain read included. A 402 that passes is left untouched. The evidence fetch in mcp.ts is unchanged: its 4 MiB read limit is what bounds the parse, and the same bytes beside an empty list cost as much to parse and pass any count of records. SDK tests, counted on 15 November: 383 pass and 9 skip of 392. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
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.
The SDK's part of the minor findings (20 and 21) from the 15 November performance review.
21. A refused 402 left the seller's body unread and its socket open (
x402.ts)Everything after the 402 check in
sigvaraX402Fetchnow runs in one try/catch that releases the body (res.body?.cancel()) and rethrows. That covers the three refusals, a chain that cannot be read and a body that cannot be read. A 402 that passes is returned unread, as before. Measured on a real socket: a body cut off at the limit used to leave its socket open 3 s after the refusal; it now closes 4 ms after.20. Counting records before the parse: no change, on measurement
The 4 MiB byte limit is what bounds the parse, and a count before it cannot lower that bound:
{}in the evidence list (refused after the parse){}beside an empty evidence list (passes any count)A hostile oracle's worst case is set by the byte limit alone. A count that does not refuse what JSON.parse accepts needs a real JSON scanner: a duplicate
evidencekey keeps the last one, and an escaped key name decodes toevidence. Lowering the byte limit would refuse bodies accepted today, which is a decision, not a fix.Tests
392 SDK tests: 383 pass and 9 skip (README and whitepaper updated); build and typecheck pass. New: one test per refusal path, each expecting exactly one cancel (all fail on main with no cancel), and one that a passing 402 is never cancelled.
CHANGELOG.mdhas anUnreleasedentry; 1.0.0-alpha.21 is untouched.🤖 Generated with Claude Code