Repository navigation
fix(mistralai): raise when a stream ends before conversation.response.done - #8800
Open
ANDROIDHASSAN wants to merge 1 commit into
Open
ANDROIDHASSAN wants to merge 1 commit into
ANDROIDHASSAN wants to merge 1 commit into
Conversation
β¦.done The mistralai SDK stops iterating without an error when the SSE body ends, so a stream cut before conversation.response.done was treated as a complete reply, and a function call still being streamed was dispatched with truncated arguments. Raise APIConnectionError instead, retryable only while nothing has reached the caller.
Codex Review Summary: β CompletedThis comment shows the latest Codex review activity on this pull request.
βΉοΈ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with π while any review is running, comments if it has suggestions, and reacts with π once all reviews finish with no findings. |
Contributor
There was a problem hiding this comment.
π Devin Review: 1 flag
Not posted on this PR by your GitHub settings β view it in Devin Review. (Configure)
This branch has not been deployed
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.
Problem
mistralai.LLMStream._runtreats the end of the Conversations event stream as a finished reply, but nothing checks thatconversation.response.donearrived. The SDK's SSE reader (mistralai.client.utils.eventstreaming, no sentinel onstart_stream_async) just stops iterating when the body runs out. So:I ran the real
mistralai3.5.0 client against a local HTTP server that ends the event stream at different points:start_stream_async['conversation.response.started', 'message.output.delta']And through the plugin on
main, a stream ofmessage.output.delta+ afunction.call.deltawitharguments='{"ci', then end of body:#8705 fixed the same gap in the OpenAI Responses engine; #8728 (Anthropic) and #8787 (Bedrock) are the open counterparts.
Fix
APIConnectionErrorif the stream ends beforeResponseDoneEvent, before the pending function calls are flushed. It uses the existingretryableflag, so it is retried only while nothing has reached the caller.except Exceptioninstead of being wrapped again.conversation.response.erroralready raises from_parse_eventand is unaffected.pending_fnc_callsis local to each attempt, so a retry cannot leak the cut call.Tests
uv run pytest --plugin mistralai tests/test_plugin_mistralai_llm.py -qgives 16 passed.test_stream_ending_before_response_done_is_retried:conversation.response.startedalone, 3 attempts withmax_retry=2, then raises.test_stream_ending_before_response_done_after_output_is_an_error: text then a partial function call, 1 attempt, the text is kept, no tool call is emitted, raises withretryable=False.With
llm.pyfrommain, both fail withDID NOT RAISE APIConnectionError.The existing fakes ended without
conversation.response.done, which the real API always sends, so_no_eventsandtest_thinking_chunks_are_not_emittednow end with one. That is the only change to existing tests.Also ran:
ruff format --checkandruff checkon both files: clean.-p livekit.agents -p livekit.plugins.mistralai): no issues in 252 source files.uv run pytest --unit --audio_eot -q: 7552 passed, 4 skipped. One earlier run on the same diff had a single failure outside the Mistral plugin, and the next full run passed.Scope
_run, and the same as fix(openai): raise when a Responses HTTP stream ends before a terminal eventΒ #8705's default.livekit-plugins-mistralai/.../llm.pyand its test file change.