Repository navigation
fix(sdk): bound the response body an error message quotes - #1348
Merged
Merged
Conversation
An agent with no route for the path answers with an HTML page. Go put the whole body in the error string and Python put the whole body in the exception message: a 20 KB response produced a 20 KB error, measured at 20035 bytes in Go and 20176 characters in Python. Rust already caps this at 512 characters and JS at 300, both with comments saying why, so this is the two stragglers catching up rather than a new policy. Use Rust's number and Rust's rule -- prefer the prpc handler's `error` field when the body is one, fall back to the raw body when it is an HTML page, and count characters rather than bytes so the bound cannot land inside a multi-byte sequence. Go also stops reading at 64 KiB instead of buffering a whole page it is going to throw away, and now reports `HTTP <status>: <reason>` rather than `unexpected status code: <status>, body: <everything>`, which matches what the other three SDKs print. The read bound is deliberately larger than the quote bound: the quoted text is lifted out of the `error` field *inside* the body, so a body cut off mid-string is no longer JSON and every large prpc error would degrade into a raw truncated blob. Compat: error text only. No response that parsed before parses differently.
Assert the exact error text per case instead of indirect length and substring checks, cover the large prpc error field in Python too, and drop the success-status test that belongs to no change in this PR. This also fixes the ruff-format failure in CI.
This was referenced Sep 24, 2026
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.
Problem
Go and Python put the entire response body into the error message; a 20 KB HTML page from an agent with no route for the path produced a 20 KB error. Rust caps this at 512 characters and JS at 300.
Fix
Go and Python follow Rust: prefer the prpc
errorfield, fall back to the raw body, cap at 512 characters. Go also stops reading the body at 64 KiB.Error text only; no behaviour change otherwise.
Verification
go test ./dstackandpytest tests/test_error_bounds.pypass.Split out of #1281.