Skip to content

Release a refused 402's body, and leave the evidence parse bounded by bytes - #324

Merged
RunTimeAdmin merged 2 commits into
mainfrom
fix/sdk-bounded-reads
Nov 15, 2026
Merged

RunTimeAdmin merged 2 commits into
mainfrom
fix/sdk-bounded-reads

Conversation

@RunTimeAdmin

Copy link
Copy Markdown
Owner

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 sigvaraX402Fetch now 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:

Body Parse Heap
2,000 honest payments (accepted) 3.9 ms 2.8 MiB
3,700 honest payments, just under 4 MiB (refused after the parse) 7.3 ms 5.5 MiB
4 MiB of {} in the evidence list (refused after the parse) 372 ms 85 MiB
The same {} beside an empty evidence list (passes any count) 392 ms 85 MiB

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 evidence key keeps the last one, and an escaped key name decodes to evidence. 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.md has an Unreleased entry; 1.0.0-alpha.21 is untouched.

🤖 Generated with Claude Code

RunTimeAdmin and others added 2 commits November 15, 2026 17:13
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>
Main brought #323 and #327; the only conflicts were the oracle and SDK test counts in README and the whitepaper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RunTimeAdmin

Copy link
Copy Markdown
Owner Author

Refreshed by merging main (#323, #327); the refresh commit carries [skip ci]. Every job passed on 044f454, main's parts were tested on their own PRs, and the only conflicts were the test-count lines.

@RunTimeAdmin
RunTimeAdmin merged commit 7cf4138 into main Nov 15, 2026
2 checks passed
@RunTimeAdmin
RunTimeAdmin deleted the fix/sdk-bounded-reads branch November 15, 2026 23:46
RunTimeAdmin added a commit that referenced this pull request Nov 15, 2026
Main brought #323, #324, #325 and #327; the only conflict was the test-count paragraph in README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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