Repository navigation
fix(gateway): bounded response bodies, single parse, SSE pass-through - #43
Merged
Merged
Conversation
Reject oversized responses instead of returning truncated bodies. Reuse decoded params without changing JCS receipt hashes. Commit SSE acceptance receipts before forwarding any bytes. Keep final stream hashes in logs pending a v2 spec. Signed-off-by: Shreyansh Sancheti <43677304+shreyanshjain7174@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep a 5s deadline for HTTP stream terminators. Forward validated JSON without a second scan or body-sized copy. Preserve envelope field order and existing text escaping. Signed-off-by: Shreyansh Sancheti <43677304+shreyanshjain7174@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Plan
Phase 0, item 5 of the AgentGate scale-out prompt: response body limits, a single params parse, and SSE pass-through.
The gateway read upstream bodies with
io.ReadAll(io.LimitReader(body, 1 MiB))and silently truncated anything larger. It parsed params 3 times and response JSON twice. It had no streaming.What changed
limit + 1bytes. Over the limit, the agent gets 502upstream_response_too_largeand the receipt records it. Nothing is truncated silently. The default is 1 MiB, overridable per service withupstream.max_response_bytes(1 KiB to 64 MiB).FuzzDigestParamsLegacy) against the oldjcs.Transformpath all pass.json.Valid, then theActResponseenvelope is written by hand around the validated bytes. Field order and text escaping are unchanged. Upstream JSON is no longer HTML-escaped, which is safe because the response isapplication/jsonwithnosniff.stream: true, the agent sendsAccept: text/event-stream, and the upstream answers 2xx withtext/event-stream.max_stream_bytes(default 64 MiB) and an idle timeout (default 60s) end the stream.text/event-stream,nosniffandno-cache.docs/spec/proposals/receipt-stream-digest.mdproposes a v2 field for the stream digest.Numbers (
BenchmarkHandleAct, median of 5)A 1 MiB JSON response envelope now costs 4 allocs/op.
Validation
go build ./...: passedgo vet ./...: passedgo test -race ./...: passedsemgrep --config auto --error --quiet internal/gateway internal/upstream internal/registry: passed. Two scopednosemgreplines on raw writes. Each sits on a response with a fixedContent-Typeandnosniff, and is commented.Review
Reviewed by a second model (Claude Opus 5.5). Approved with 2 minors, both fixed here: a bounded final write deadline on streams, and removing the second JSON scan.
Known limits
buildURLstill does not escape path params. This is unchanged frommainand is a separate fix.