Repository navigation
Retry a Luna stream cut short once, and tell the reader their model is unavailable - #581
Merged
Merged
Conversation
A Bedrock stream that stalled past the read timeout surfaced as urllib3's ReadTimeoutError, which botocore lets out raw while iterating the response. classify_model_error only knew botocore's class, so the failure was logged as an unexpected error with no retryable field (issue 578). urllib3 timeouts and protocol errors are now the model call's when they came up through botocore. Tested: new cases drive the real Bedrock client with a staged stream that raises mid-body; they fail without the change. test_model_errors.py passes.
Bedrock can end a stream almost at once with no messageStop event (GPT-6 Luna did, issue 578) or answer a throttle; botocore does not retry once the response has begun, so each reached the reader as an error. The ask and chat streams now run the graph once more when the failure can clear by itself and fails fast, and only while the reader has seen no text, tool call or tool result and no model call has finished. A read timeout is not retried, since it has already spent the whole timeout. Tested: real graph and real Bedrock client with staged streams, on both endpoints; the retry tests and the no-retry guards fail when the change or the guard is removed. test_stream_failures.py and test_model_errors.py pass.
When a model call fails in a way that can clear by itself (throttle, stream cut short, stall, dropped connection) and the retry did not help, the reader got "An error occurred while processing your request." The error event now says the current model is not available and asks them to choose another. There is no automatic switch, which would change what a community chose and what a request costs. Failures that are not a model call's (a tool of ours) keep the generic text, and a refused request or credential keeps its own. Tested: the provider-failure cases in test_stream_failures.py now assert the new text on both endpoints, the generic text is still asserted for non-model failures; 149 pass across test_stream_failures.py and test_model_errors.py.
Review findings on the retry: - retry only a failure that arrives within 10 s, so a slow failure does not double the reader's wait; wait a jittered second, not a fixed one - retry only unavailable and connection failures; a throttle is already retried with backoff by the clients, and a second try only adds load - match urllib3 errors only when they came up through langchain-aws, and name urllib3 in the detail so it is not confused with botocore's class - treat a chunk it does not recognize as output, close the inner stream deterministically, and log a cancel during the wait - log the first failure's type, kind and text, the chat session, and when the second try worked; a failure that survived a retry is logged at ERROR and its metrics detail says so - correct docstrings the review found stale or inaccurate Tested: new cases for the window, the throttle exclusion, a dropped connection, the ERROR record, cancellation during the wait, and what counts as output; the window and throttle cases fail when their change is removed. 524 pass across the affected test files.
- the retry outcome is a required argument and the single record of whether a second try was made; the failure detail's retried flag has no default - one traceback-frame check serves both _raised_in and _passed_through - the wording branch reads as one conditional; trim docstrings that repeated each other - tests: typed staged answers (a misspelled key now fails), shared CUT_SHORT and dropped/stalled stream errors, one real-client helper for the classifier tests, one retry-log filter, and the unrecognized-wording constant renamed to match its field Tested: 1706 pass across test_stream_failures.py and tests/test_core; ruff clean.
- a service error inside a Bedrock stream, OpenRouter 503, and an Anthropic overloaded error are answered by the second try; a throttle (in-stream and OpenRouter) is left alone, as decided - the resume path sends the same request twice, carrying the browser's result, and labels the retry with its own endpoint - a provider failure nobody recognizes is called unavailable and claims nothing about retrying; one that survives a retry is logged at ERROR - each kind of output (a tool call alone, reasoning alone, a tool after a model that does not stream) ends the chance to retry - a disconnect during the wait releases the session's turn and starts no second call; a urllib3 error through botocore alone is not the model's - the retry log is found by its own field, and the unbounded-retry case fails fast instead of hanging Tested: 1727 pass (11 skipped) across tests/test_core and test_stream_failures.py; the langchain-aws requirement and the earlier guards fail when removed.
Type design review findings on RetryOutcome: - the helper read its caller's out-parameter as control state, so an instance that was reused skipped the retry and logged a success that never happened; it now keeps its own local state and only writes the report - the flag was sticky, so a later, unrelated failure in a run that had been retried was logged at ERROR as "after one retry"; it is now set only when the failure raised came from the second try before that try produced any output - renamed RetryOutcome to RetryState (outcome collides with the model_outcome and turn_outcome modules) and its field to failed_after_retry - tests: the classifier's tables are walked to keep kind and retryable consistent, and every kind is covered by the retry-policy cases; the wire helper's defaults are defined once and its docstring says its answers are indexed by transport request - docstrings: worth_retrying_now reflowed and tied to retryable; _FailureWording says it holds the two messages that differ by stream Tested: 1737 pass (11 skipped) across tests/test_core and test_stream_failures.py; the reuse and per-failure label tests fail when their change is removed.
This was referenced Oct 7, 2026
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.
Refs #578.
This makes the chat and ask streams survive the Luna failure mode and report it honestly.
It does not fix Luna itself, which is upstream.
What the evidence says
The four production error ids in the issue are all
ConnectionError: Incomplete Bedrock response stream: missing messageStop event, not throttling.CloudWatch (
AWS/Bedrock, us-east-2,us.openai.gpt-6-luna) shows zero client errors, server errors and throttles from Oct 3 to Oct 6.It also shows 8 invocations between 01:25 and 01:40 UTC on Oct 6 that finished in about 0.45 s with no error, where a real Luna answer takes 15 to 27 s.
So Bedrock closed those streams almost at once and counted them as successes.
The develop request that hung for 122 s (
ea0c685f) was a different failure: a stall until our 120 s read timeout.It surfaced as
urllib3.exceptions.ReadTimeoutError, which botocore lets out raw from an open stream andclassify_model_errordid not recognize.It was logged as an unexpected error with no
retryablefield.Changes
urllib3.so they are not confused with botocore's classes of the same names.astream_events_with_retryruns the graph a second time after about a second when the first try failed fast (within 10 s) and the reader has been shown nothing: no text, reasoning, tool call or tool result, and no finished model call.It applies to
/ask,/chatand/chat/resume.Only
connectionandunavailablefailures are retried.Timeouts are not (they have already waited out their limit) and neither are throttles (see below).
The first failure is logged with its type, kind and text; a failure that survives the retry is logged at ERROR and its metrics detail says
(after one retry); a retry that works is logged at INFO.There is no automatic fallback to another model, by decision: it would change what a community chose and what a request costs.
Failures that are not a model's keep their wording, and a refused request or key keeps its own.
[Unreleased].Decisions to review
LiteLLM does not retry, so an OpenRouter throttle is not retried by anyone; that is pinned by a test.
A persistent outage costs up to twice the requests for those.
Narrowing to failures that arrive after the response began is possible, at the price of a more complex classifier.
If Luna can stream reasoning and then drop
messageStop, that case is not retried.The Bedrock evidence above says these streams close before any content, and invocation logging (below) will show if that is wrong.
A retried success is visible in the INFO log, not in the metrics row.
reader.read()and cannot fire during a silent wait, so a stall still takes up to the 120 s read timeout to reach the reader.I left both alone: high-effort reasoning can legitimately be silent for a long time.
/askand/chatpaths are unchanged and still return a generic 500 for a provider failure.Outside the repo
Bedrock model invocation logging was turned on for account 358982197581 in us-east-2: CloudWatch Logs group
/osa/bedrock-invocations, 14-day retention, roleOsaBedrockInvocationLogging, text delivery on.It is account-wide and stores full prompts and answers;
delete-model-invocation-logging-configurationturns it off.Testing
test_chat_resume_endpoint.pytests fail with 401 on both.