fix(runtime): detect SSE stream truncation and auto-continue from partial response#82
Merged
yishuiliunian merged 2 commits intomainfrom Apr 5, 2026
Merged
Conversation
…tial response (#79) When an API proxy silently drops SSE connections mid-stream (no `message_stop` event), the agent loop previously treated the truncated response as a normal EndTurn — causing sub-agents to exit with incomplete output (e.g. "Let me create the file." without the Write tool call). Detection: track `received_done` in the stream loop; EOF without Done and without cancel sets `stream_error = true`. Recovery: stream_error with partial content triggers auto-continue (record text, discard incomplete tool_uses, re-call LLM) — same pattern as MaxTokens/PauseTurn. Bounded by `max_auto_continuations`. Cancel safety: cancel paths are excluded from both truncation detection (llm.rs) and auto-continue (turn_exec.rs) to preserve existing cancel behavior. Also extracts stop-hook and observer dispatch into `turn_observer_dispatch.rs` as an independent lifecycle extension point.
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
message_stop) by trackingreceived_doneinllm.rsmax_auto_continuationsChanges
llm.rs:received_doneflag + post-loop truncation check (excludes cancel)llm_result.rs: expandedstream_errordocturn_exec.rs:stream_truncatedauto-continue branch + partial text preservation on cancel/errorturn_observer_dispatch.rs(new): extracted stop-hook and observer dispatch as lifecycle extension pointContext
Sub-agents behind an API proxy would output text like "Let me create the file." then exit without executing the Write tool — because the proxy silently cut the SSE connection and the agent loop treated the truncated stream as a normal EndTurn.
Test plan
bazel test //crates/loopal-runtime:loopal-runtime_test— 219 tests passbazel build //... --config=clippy— zero warnings