fix(acp): include the relay response body in REST error messages - #6227
Open
Joxyko wants to merge 1 commit into
Open
fix(acp): include the relay response body in REST error messages#6227Joxyko wants to merge 1 commit into
Joxyko wants to merge 1 commit into
Conversation
`request_with_retry` built its error from the status line alone and dropped the body, where the relay explains which rule refused the request (`restricted: ...`). Every caller upstack saw a bare status code. Append the body to the message on both the terminal arm and the retriable arm (`last_err`, which is what surfaces once retries are exhausted). The read is bounded at 512 bytes via `resp.chunk()` rather than `text()`: this path is reached precisely when the peer is misbehaving, so a failing request must not become a memory amplifier. Control characters are collapsed so a body cannot forge or split a log line, and truncation walks back to a UTF-8 boundary. A bodyless failure produces the exact message it did before; that property has its own test, since it is the one most likely to be broken later. Signed-off-by: VSCteam <jose.cortinat@valuestrategyconsulting.com>
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
RestClient::request_with_retrybuilds its error from the status line alone and drops the response body:The relay explains which rule refused the request in that body —
restricted: agent-turn-metricptag must be the registered owner of this agent,restricted: not a relay member, and so on. The client discards it at the moment it arrives, so every caller upstack sees a bare403and has no way to tell an ownership problem from a membership problem from a rate-limit rule.Concretely: a
403onPOST /eventsthat blocked NIP-AM turn-metric publishing was unreadable from the client side for days. The reason was being sent correctly by the relay the whole time — the status code is the only thing that survived the client.This appends the body to the message, bounded, on both the terminal arm and the retriable arm (
last_err, which is what surfaces once retries are exhausted).Behaviour when there is no body is unchanged —
format_error_bodyreturns an empty string, so the message is byte-for-byte what it was before. That is covered by a test, since it is the property most likely to be broken by a later edit.Two things a reviewer will reasonably ask about, both handled:
resp.chunk()rather thanresp.text()— a failing request must not become a memory amplifier.Related issue
None found. Searched open PRs and issues touching
crates/buzz-acp/src/relay.rs; the nearest neighbours are #5724 (honour the relay's retry hint on a rate-limited REST call) and #4912 (rate-limit overhaul … client retry fixes), which both changeRestClientfor other reasons — I checked their diffs and neither touches theOk(resp)arms ofrequest_with_retry, so this should not conflict. #4821 (recognize the membership gate's bodyless 404 in onboarding) is adjacent in spirit but is desktop-side and about a response that has no body at all.Testing
cargo test -p buzz-acp --lib→ 797 passed, 0 failed (792 before, +5 new).cargo clippy -p buzz-acp --all-targets -- -D warnings→ clean.cargo fmt -p buzz-acp -- --check→ clean.rust-toolchain.toml.New unit tests cover: empty body (message unchanged), the relay's real
restricted: …reason coming through, newline flattening, the length bound, and a multi-byte character straddling the cap.