Skip to content

fix(runtime): don't truncate the SSE stream on tool results >64 KiB - #3883

Open
EronWright wants to merge 1 commit into
docker:mainfrom
EronWright:contrib/sse-large-events
Open

fix(runtime): don't truncate the SSE stream on tool results >64 KiB#3883
EronWright wants to merge 1 commit into
docker:mainfrom
EronWright:contrib/sse-large-events

Conversation

@EronWright

Copy link
Copy Markdown
Contributor

fix(runtime): don't truncate the SSE stream on tool results >64 KiB

Problem

The remote-runtime SSE reader (pkg/runtime/client.go) uses bufio.NewScanner
with the default 64 KiB token cap (bufio.MaxScanTokenSize). Each server event is
delivered as one data: {json} line, so a large tool result — e.g. a big
tool_call_response — overflows it: scanner.Scan() trips bufio.ErrTooLong, the
loop ends, and the run appears to stop silently right after the last event that
fit. The scanner error was discarded, leaving no trace.

Fix

In both SSE readers: raise the buffer ceiling (maxSSELineBytes, added to
pkg/runtime/defaults.go) and emit an Error event on scanner.Err() instead of
closing the channel without a word.

Impact

Any agent that returns a tool response larger than 64 KiB over a remote runtime —
today that run vanishes with no error.

Test

go build ./pkg/runtime/ && go test ./pkg/runtime/. Reproduced with a ~78 KB
tool_call_response that previously cut the stream mid-run; it now streams to
completion.

The client SSE reader used bufio.Scanner with the default 64KiB token cap
(bufio.MaxScanTokenSize). Each agent event is delivered as one `data: {json}`
line, and a large tool result (e.g. a big tool_call_response) exceeds that,
so scanner.Scan() trips bufio.ErrTooLong, the loop ends, and the run appears
to stop silently after the preceding event. The scanner error was also
swallowed, leaving no trace.

Raise the reader's buffer ceiling and surface any read error as an Error
event instead of closing the stream without a word.
@EronWright
EronWright requested a review from a team as a code owner August 2, 2026 00:07
@aheritier aheritier added area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants