Skip to content

fix(sdk): bound the response body an error message quotes - #1348

Merged
kvinwang merged 2 commits into
nextfrom
fix/sdk-bound-error-body
Sep 24, 2026
Merged

kvinwang merged 2 commits into
nextfrom
fix/sdk-bound-error-body

Conversation

@kvinwang

Copy link
Copy Markdown
Collaborator

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 error field, 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 ./dstack and pytest tests/test_error_bounds.py pass.

Split out of #1281.

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.
@kvinwang
kvinwang merged commit 0f85581 into next Sep 24, 2026
7 checks passed
@kvinwang
kvinwang deleted the fix/sdk-bound-error-body branch September 24, 2026 05:17
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