Repository navigation
Release 0.8.16 review: report cut-off replies, missing usage and stream failures - #566
Merged
Merged
Conversation
…eam errors Moves the botocore before-send harness out of test_bedrock_llm.py into tests/helpers/bedrock_wire.py and lets it answer with a refusal status, raise a transport error, or frame an exception event. test_bedrock_llm.py passes unchanged (34 passed).
…cross LiteLLM streams model_outcome.truncation_reason reads Bedrock stopReason, Anthropic stop_reason and LiteLLM finish_reason and says whether the reply was cut off (max_tokens, length, model_context_window_exceeded), tolerating the repeat a chunk merge makes. langchain-litellm drops finish_reason from a streamed reply; the OpenRouter model now carries it, and a note that usage is LiteLLM's estimate, onto response_metadata. Tested: each provider's real client stack (botocore before-send, patched Anthropic transport, local OpenRouter stand-in), streamed and complete (200 passed in the core suites it touches).
The CLI ignored the warning event and the warnings field of a complete response, so a reply the server flagged (it lists them, and the widget shows them) looked whole in a terminal. ask and chat now print each warning to stderr after the answer, streamed or not. Tested with respx against both stream and complete responses.
A Luna or gpt-oss turn that spends bedrock_max_output_tokens on reasoning ends its stream normally with no text: the server sent done with empty content at 200 and logged nothing, and the widget dropped the empty bubble, so the reader saw neither answer nor error. A reply cut off mid-sentence was presented as complete. The last model run's stopReason / stop_reason / finish_reason is now read on every path (streamed and complete, chat and ask). A cut-off reply logs a warning naming community, model, request id and the provider's reason. With no text and no code run it is an error event (502 and a metrics error_message when not streamed) and nothing is stored; with text it is a warning event before done (a warnings list on the complete response). A complete /chat reply with no text is no longer stored as an empty assistant turn. Tested through the real graph for Bedrock, Anthropic and OpenRouter chunk shapes, and through each provider's real client stack (53 tests in test_cut_off_replies.py).
_extract_token_usage answered zeros with no log when a model run carried no usage metadata (a NULL cost row), and the OpenRouter stream silently fell back to LiteLLM's own estimate when the provider reported none. Finished runs are now counted, and one warning naming community, model, request id and the run counts is logged when the request ends, on the streamed and complete chat and ask paths and the parked-browser-call path. The message says whether the cost is missing, too low or approximate. Tested with scripted Bedrock, Anthropic and OpenRouter runs, and through the real Bedrock (stream ending before its metadata event) and OpenRouter (no usage sent) stacks (29 tests in test_missing_usage.py).
…hat cannot work A throttle, a read timeout and a provider refusal (a 400 for a reasoning field the model rejects) all reached the reader as 'try again' and the log as one error with no model and no retry verdict. model_errors.classify_model_error reads botocore, Anthropic, LiteLLM, httpx and langchain-aws exceptions and says whether a retry can succeed. The streams log the exception class, the provider code or status and retryable=yes|no|unknown with community, model and request id (WARNING for a failure that can clear, ERROR with the traceback otherwise), add retryable to the error event, and for a failure no retry can fix say so instead of 'try again'. Text for retryable and unrecognized failures is unchanged. A ValueError that langchain-aws raises for the provider's own exception events is no longer labelled 'Invalid request' / a session limit; a ValueError of ours still is. Tested with real exceptions and through the real Bedrock (throttle, read timeout, in-stream exception event, validation, access denied), Anthropic and OpenRouter client stacks, streamed ask and chat (77 tests).
Measured against langchain-aws, langchain-anthropic and the OpenRouter message builder: Bedrock sends '.', OpenRouter an empty string, Anthropic drops the turn. Comment and test docstring only.
This was referenced Sep 30, 2026
Merged
neuromechanist
added a commit
that referenced
this pull request
Sep 30, 2026
* Widget: stack warnings so a second one does not replace the first showWarning wrote every warning into one text node, so a cut-off notice and the long-conversation notice that follows it were never both readable. Each warning is now its own line with its own 10 s timer; the banner hides with the last line; identical text restarts the one line's timer. Tested: new cases in frontend/test-widget-paced-streaming.js (failed before the change); bun frontend/test-widget-color-scheme.js unchanged. * Widget: mark a cut-off reply in place and keep the mark across a reload When a warning arrives before done and says the reply was cut off (code cut_off when the server sends one, else the server's wording), the reply gets a cutOff mark. The message draws the existing italic 'Response may be incomplete' note from that mark once its text is fully shown, so the done event's canonical text does not replace it. The mark is saved with the conversation and read back only as a boolean. Tested: new cases in frontend/test-widget-paced-streaming.js (failed before the change), including a saved-and-reloaded conversation. * Widget: keep a cut-off reply that has no text and no run record applyDoneEvent kept an empty reply only if it had entries in executions, but answerToolRequest records only code that ran, so a reply whose only run was get_full_output had none. The server sends a warning and a done with empty content for it (the run counts as code there), and the bubble was dropped, leaving the 10 s banner as the only explanation. A reply marked cutOff is now kept and draws the explanation the mark carries. Tested: frontend/test-streaming.js and frontend/test-widget-paced-streaming.js (new cases failed before the change). * Widget: show the warnings of a non-streamed response The non-streamed fallback ignored data.warnings, so a cut-off answer arrived unmarked. Warnings (strings, or objects with a message and an optional code) now go through the same function as a stream's warning events: the banner, and the cutOff mark on the reply, which is saved with it. A missing or malformed field is ignored. Tested: new cases in frontend/test-widget-paced-streaming.js (failed before the change). * Widget: do not rewrite a server error that contains the word timeout A backend error event whose text contained 'timeout' was rewritten to 'Stream timeout' in the reply when partial text was visible, and one that contained 'JSON' became 'Invalid response from server' in the banner. The error raised for an error event is now marked serverReported, and both handlers pass it through as sent before looking for failures of the stream or the page. A client-side stream failure that says timeout still reads as one. Tested: new cases in frontend/test-widget-paced-streaming.js (failed before the change). * Widget: keep a failed request's banner, hand the question back, show the error id The banner for a failed chat request lasted 5 s, and when the reply was empty (the routine no-answer error) the question was removed with it, so the reader lost both. Now, for a failed request: - the banner stays until dismissed or the next send, with a dismiss button, selectable text, and the server's error_id (when the event carries one) as text with a copy button (falling back to selecting it where the page cannot copy); - the question goes back in the input when the failure removed it from the conversation; an error after a partial reply keeps it there, as before; - an earlier message's timer no longer hides a later message's banner. Other banners (settings, feedback, storage) still go after 5 s. Tested: new cases in frontend/test-widget-paced-streaming.js (failed before the change); every frontend suite in the Frontend Tests job run locally. * Widget: read the server's cut-off warnings as #568 sends them #568 gives each warning a code and sends one combined notice (code cut_off, codes listing both) when a cut-off and a long conversation coincide, and adds a context-window cut-off whose message is 'stopped short because' and whose advice is to start a new conversation, not to ask it to continue. So: - the wording fallback for a warning with no code (a stream before #568, and a non-streamed response's warnings, which are strings) also reads that message; - the note under a cut-off reply's text says only that it was cut off, true for either cause; a reply with no text shows the server's own message for it, kept on the reply (bounded, saved and read back only as a string), so the advice is the server's and survives a reload; - tests read the server's message constants from src/api/turn_outcome.py. Tested: bun frontend/test-widget-paced-streaming.js.
This was referenced Sep 30, 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.
Fixes findings 1 to 4 of the five-reviewer review of release PR #562 that concern the streaming and usage paths. HED, EEGLAB, BIDS and NWB now default to GPT-6 Luna on Amazon Bedrock, which makes a reply that spends its output budget on reasoning (ADR 0014) a real, repeatable case.
Each finding was reproduced against the real client stacks before the change (scratch scripts, not committed): the empty
doneat 200 with nothing logged, and one undifferentiated error for a throttle, a read timeout and a validation refusal.Changes
1. Empty or truncated answers are now reported.
src/core/services/model_outcome.pyreads BedrockstopReason, Anthropicstop_reasonand LiteLLMfinish_reasonand says whether the reply was cut off (max_tokens,length,model_context_window_exceeded). Tolerates the repeat langchain-core makes when it merges two chunks that both carry the string (lengthlength).langchain-litellmdropsfinish_reasonfrom a streamed reply, so the OpenRouter model (litellm_chat.py) now carries it ontoresponse_metadata.src/api/turn_outcome.pydecides what the reader is told, from the last model run only. A cut-off reply logs one WARNING with community, model, request id and the provider's stop reason. With no text and no code run earlier in the reply it is anerrorevent (nodone, nothing stored, metrics row 502 with anerror_message); with text it is awarningevent beforedone.warningslist onAskResponseandChatResponse./chatand/askon all three provider paths.warningevents (and had no place for a warning on a complete response). It now prints them to stderr after the answer, so a cut-off reply is not silent in a terminal either.2. Missing usage is no longer silent. Finished model runs are counted; one WARNING per request names the community, model, request id and how many runs reported no usage or used LiteLLM's estimate, and says whether the cost row is missing, too low or approximate. The OpenRouter model marks a streamed reply whose usage is LiteLLM's estimate (
response_metadata["osa_usage_estimated"]). Covers streamed and complete chat and ask and the run that parks a browser call.3. Stream errors are told apart.
src/core/services/model_errors.pyclassifies botocore, Anthropic, LiteLLM, httpx and langchain-aws exceptions as retryable or not. The streams log the exception class, the provider code or status andretryable=yes|no|unknownwith community, model and request id (WARNING for a failure that can clear, ERROR with the traceback otherwise) and addretryableto theerrorevent. Text for retryable and unrecognized failures is unchanged; a failure no retry can fix (a validation refusal, a credential the provider does not accept) now says so, with the error id, instead of "Please try again". The provider's own message stays in the log.4. Empty assistant message and
done.model.done.modelis the resolved model id (awm.model) and is never empty; asserted for a cut-off reply./chatdid (AIMessage(content="")), and the next request replayed it: as "." on Bedrock, as an empty string through OpenRouter, dropped on Anthropic. It is no longer stored.Not changed, and corrections to the findings
_handle_bedrock_erroris inbedrock_llm.pyand that itsValueErrorrelabels a throttle or validation error as "Invalid request". It is in langchain-aws, and it raisesValueErroronly for abedrock:InvokeToolpermission error. Driven through the real client, a throttle, a validation refusal, a read timeout and an in-stream exception event all arrive asClientError,EventStreamErrororReadTimeoutError, which took the generic branch ("Please try again"), not the "Invalid request" one. I still stopped theValueErrorbranch from blaming the reader for the two things langchain-aws does raise asValueErrorthat are the provider's (Received AWS exception ...and theInvokeToolcase); aValueErrorof ours is still "Invalid request" (asserted).Needs a widget change (not made here)
frontend/osa-chat-widget.jsshows thewarningevent as its 10 second banner and theerrorevent as its 5 second banner, neither attached to the message. The reader is told, but a cut-off answer is unmarked in the transcript afterwards. A persistent marker on the message would need a widget change. The widget also replaces any backend error text containing the word "timeout" with "Stream timeout" when partial text is visible; the new messages avoid that word.Noticed, not changed
/chatprices a turn from every assistant message in the session (extract_token_usage), so a session that earlier ran a browser turn (history kept with its usage) would count those turns again. Only reachable by mixing streamed and non-streamed requests in one session.Testing
uv run ruff check . && uv run ruff format --check .cleanuv run ty checkon the touched files: only the nine diagnostics already on developuv run pytest --ignore=tests/test_integration -m "not integration and not llm and not network" -q -p no:cacheprovider --color=no --no-cov: 4179 passed, 14 skipped, 75 deselectedmessageStop, Anthropicmessage_delta, OpenRouter closing chunk) through the real graph, both streams, the real HTTP endpoints and a real metrics database (test_cut_off_replies.py,test_missing_usage.py)before-send(throttle, read timeout, in-stream exception event, validation, access denied, stream ending before its metadata event), a patched Anthropic transport, the local OpenRouter stand-in (test_model_outcome.py,test_stream_failures.py,test_litellm_chat.py)ValueErrors langchain-aws raises (test_model_errors.py)test_cli/test_main.py)max_tokensstop (needs the platform key; the stop reason shapes are pinned against the real parsers)