Repository navigation
fix(llm): catch the stream edge cases that still lost answers or hung turns - #393
Merged
Merged
Conversation
… turns
- Anthropic: a stream that closed before message_stop was taken as a
finished answer (and a half-written tool call ran). It is now a
retryable drop, as the chat-completions parser already does.
- Anthropic error events kept only their text; the type (api_error,
overloaded_error) that tells a retryable failure from a fatal one was
dropped. It is kept, and the classifier reads it bare as well.
- Chat completions: a `data: {"error":{…}}` chunk was ignored, so the
real cause was lost and a following finish_reason passed the partial
reply as an answer. It now ends the stream as a provider error event.
- A stream that stopped sending without closing held the turn until Esc.
Five minutes of silence now counts as a dropped stream and is retried.
- A response still cut off at the output limit after every continuation
ran its tool calls, the last possibly with half its arguments. The
text is kept as the answer and the calls are dropped.
- An unclassified error showed the provider's raw JSON body; it now
shows the provider's reason, capped.
Codex and Code Assist keep accepting a clean close without their final
event: their parsers document that the backends do send that.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes (remaining findings from the LLM-stream audit)
AnthropicSsetracks whether any event arrived and whethermessage_stopwas seen. A clean close in between is now a retryableunexpected EOF before message_stop, the same checkChatSsealready has. Before, a truncated answer, and its half-written tool call, were accepted.errorevent now keeps its type, e.g.(api_error) Internal server error. The classifier also recognises a bareapi_errorand the phrase "internal server error" as server errors, so these are retried.data: {"error":{…}}chunk becomesStreamEvent::Error, which the turn's retry path classifies. Nothing after it is read. Before, it was ignored, and a laterfinish_reasonpassed the partial reply off as an answer.Agent::stream_idle(300 s) is raced against eachnext(). A provider that stops sending without closing yields aTimeouterror, retried like a drop. Before, the turn hung until Esc.readable_reason: the provider's own reason, with the prefix kept and capped at 300 chars. Before, the raw JSON body was shown.Left as is: Codex and Code Assist still accept a clean close without their final event. Their parsers and tests document that the backends do this.
Tests
mainbecause the write runs; it now passes.mainbecause the turn hangs; it is now retried and finishes.message_stopis a retryable error; a stop and an empty stream close cleanly; the error type is kept and classified as retryable.stream_error_messagevariants.readable_reason.cargo llvm-covon llm and agent shows no uncovered added line.🤖 Generated with Claude Code