Repository navigation
fix(aws): raise when a Bedrock stream ends before messageStop - #8787
ANDROIDHASSAN wants to merge 1 commit into
Conversation
aiobotocore ends iteration without an error when the event stream body ends early, so a cut reply was accepted as complete and an empty one was not retried. Raise APIConnectionError unless messageStop arrived, retryable only while nothing was sent, and reset the partial tool call on each attempt.
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. |
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| if not message_stopped: | ||
| # the event stream ends quietly when the body is cut short | ||
| raise APIConnectionError( | ||
| "aws bedrock llm: stream ended before messageStop", retryable=retryable | ||
| ) |
There was a problem hiding this comment.
🟥 Truncated Bedrock replies leak into logs
When Bedrock ends early after sending text, FallbackAdapter logs the partial reply in the unmarked text_sent field. JsonFormatter writes that field unchanged to production logs.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
The log line is real, but it is not specific to this change: FallbackAdapter (llm/fallback_adapter.py:386) logs text_sent for any provider whose stream fails after sending text, including Bedrock errors that already raise on main. This PR does make one more case reach it. #7832 already renames that field to lk.pii.text_sent, so I left it out of this diff and noted it under Scope.
Problem
aws.LLMStream._runtreats the end ofresponse["stream"]as a finished reply. AWS documentsmessageStopas sent once per response, but nothing checks that it arrived. When the body ends early, aiobotocore stops iterating without an error, so:I ran the real aiobotocore 3.8.0 client against a local HTTP server that ends the event stream at different points:
messageStopClientPayloadError(already handled)#8705 fixed the same gap in the OpenAI Responses engine; #8728 is the open Anthropic counterpart.
Fix
APIConnectionErrorif the stream ends beforemessageStop. It uses the existingretryableflag, so it is retried only while nothing has reached the caller.except Exceptioninstead of being wrapped again.toolUseblock emits the previous attempt's half-built call (arguments='{"a":') at the nextcontentBlockStop.Tests
uv run pytest --unit tests/test_plugin_aws_llm.py -qgives 28 passed.test_stream_ending_before_message_stop_is_an_error[no-output]: 3 attempts withmax_retry=2, then raises.test_stream_ending_before_message_stop_is_an_error[after-text]: 1 attempt, the text is kept, then raises.test_retry_after_a_cut_tool_call_drops_its_partial_state: the retry yields"Hello"and no tool call.With
llm.pyfrommain, all three fail: the first two withDID NOT RAISE APIConnectionError, the third with'' == 'Hello'because the cut stream is not retried. Removing only the state reset fails the third with the leakedFunctionToolCall.Also ran:
ruff format --checkandruff checkon both files: clean.uv run pytest --unit --audio_eot -q: 7527 passed, 4 skipped. An earlier run on the same diff had one failure intest_plugin_zoom_ai_realtime.py::test_interrupted_request_zoom_never_answers_reconnectsplus one error; that file then passed 5 of 5 runs on its own.-p livekit.agents -p livekit.plugins.aws): one error,aws/stt.py:277, which my local environment also reports withllm.pyfrommain.Scope
max_unrecoverable_errors). fix(openai): raise when a Responses HTTP stream ends before a terminal event #8705 does the same by default. WithFallbackAdapter(retry_on_chunk_sent=True), fix(openai): raise when a Responses HTTP stream ends before a terminal event #8705 can retry the same LLM; here the error stays non-retryable after text, like every other error in this plugin's_run, so the adapter moves to the next LLM.FallbackAdapterlogs the partial text of any failed stream in an unmarkedtext_sentfield. That is shared by all providers and not changed here; feat: structured provider error fields, truncation and realtime failure warnings #7832 already renames it tolk.pii.text_sent.