Skip to content

Release 0.8.16 review follow-ups: one warning per reply, empty replies, error classification - #568

Merged
neuromechanist merged 9 commits into
developfrom
fix/release-0.8.16-streaming-followups
Sep 30, 2026
Merged

neuromechanist merged 9 commits into
developfrom
fix/release-0.8.16-streaming-followups

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Follow-ups to the independent review of #566 (empty and cut-off replies, stream error classification). Each finding was first confirmed against the code, with a failing test where it is a behavior bug, then fixed in its own commit.

Changes

  • 1. One warning per reply, with a code. A reply cut off in a long conversation got the cut-off warning and then "Conversation is getting long" straight after it; the widget keeps one warning element, so the second hid the first. They are now one event. Every warning carries an optional code (cut_off, long_conversation); when both apply code is cut_off and codes lists both. message is unchanged in shape, so existing clients work as before.
  • 2. code_ran counts only runs the widget keeps. The widget records an execution only when the tool is not get_full_output; the server counted every resume. Confirmed through the real /chat/resume endpoint: a read-back-only reply whose last run hit the limit got warning + an empty done, which the widget drops. The parked call now carries code_runs_before (PendingClientCall.runs_code), and only those runs make an empty ending a warning; otherwise it is an error.
  • 3. Empty replies are errors whatever the stop reason. No text, no code and no parked call used to end in an empty done unless the stop reason was a truncation (confirmed for refusal, content_filtered, guardrail_intervened, malformed_tool_use). Now an error with a message per reason (declined, malformed, other), the stop reason in the log and the metrics row. The non-streamed endpoints answer 502 for the same replies (an empty 200 was the same silence).
  • 4. Context-window copy. model_context_window_exceeded now says to start a new conversation instead of "try again" / "ask it to continue".
  • 5. Only a model provider's errors are "Model call failed". Built-in TimeoutError/ConnectionError and any httpx error were read as the model's, logged at WARNING with no traceback, and a tool's 404 told the reader retrying will not help (confirmed with real tools raising each through both streams). An exception is now the model call's only when its class comes from a provider library (Anthropic, OpenAI/LiteLLM, the vendored httpx2, botocore) or, for the built-in ConnectionError langchain-aws raises on a stream with no messageStop, when langchain-aws raised it. Anything else keeps ERROR and its traceback.
  • 6. Ids on error events, CLI order, 502 in the schema. The empty/cut-off error events (and model-failure events) carry request_id and error_id (the log line carries the error id). The CLI holds warnings until the answer is printed on the streaming paths, matching the batch paths, and shows the ids to quote. 502 is declared on /ask and /chat.
  • 7. Short cannot-retry message. The UUID is out of the text; error_id stays a field of the event and is in the log.
  • 8. Non-streamed /chat usage. Verified: extract_token_usage summed every model message in the returned state, which includes the session history, and a session that had a browser turn keeps those messages with their usage (the cost row was three times the request's in the test). It now reads only the messages after the last human one. The unanswered user message after a stream error is left as is; a comment where the turn ends documents it.

Not changed

  • The unanswered user message after a stream error (as instructed). Finding on "merged by merge_message_runs on every provider path": Bedrock does (langchain-aws, joins the two texts with a newline); Anthropic merges in langchain-anthropic's own _merge_messages (same effect, not merge_message_runs); the OpenRouter path does not merge at all (LiteLLM sends two consecutive user messages, valid in the OpenAI-style format). All three are pinned in tests/test_api/test_unanswered_user_message.py against the real clients.
  • frontend/, CHANGELOG.md, docs/, .env.example, deploy/ and the community configs, which belong to other work. The changelog and the SSE event docs should mention the new code/codes, error_id/request_id fields and the 502 for empty replies.

Also found, not fixed

  • A streamed request through MetricsMiddleware writes two request_log rows with the same request_id (the middleware's 200 when the response starts, then the stream's own). It predates this PR; the tests read the last row.
  • The non-streamed 502 names no request or error id (it is an HTTP error body); the log line has both.
  • ScriptedChatModel does not stream, so a turn ending on its text has no text to the router. Five tests in test_client_tool_streaming.py that asserted done for such a turn now use a streaming model.

Tested

  • uv run ruff check . && uv run ruff format . clean.
  • uv run pytest --ignore=tests/test_integration -m "not integration and not llm and not network" -q -p no:cacheprovider --color=no --no-cov: 4577 passed, 14 skipped.
  • New tests drive the real graph, router streams and endpoints with the real Bedrock, Anthropic and LiteLLM clients (network staged only), for each provider shape; the stop reasons come from the registry in model_outcome, not hardcoded.

httpx errors, the built-in TimeoutError and any ConnectionError were labelled
'Model call failed', logged at WARNING with no traceback, and a 404 from a tool's
fetch told the reader retrying will not help. langgraph's ToolNode re-raises
uncaught tool errors, so a tool failure was misattributed. An exception now counts
as the model call's only when its class comes from a provider library (Anthropic,
OpenAI/LiteLLM, the vendored httpx2) or, for the built-in ConnectionError, when
langchain-aws raised it. Anything else keeps ERROR and its traceback.

Tested: real tools raising each error through the ask and chat streams, and the
real Bedrock client for the langchain-aws ConnectionError.
… a full context to a new conversation

A reply with no text, no code and no parked call ended in an empty done (which the
widget drops silently) unless it had hit the output limit: a refusal, content filter,
guardrail or malformed tool use left the reader with nothing. It is now an error for any
stop reason, with its own message per reason, the stop reason in the log and the metrics
row, and a 502 on the non-streamed endpoints. A conversation that filled the context
window was told to try again or ask it to continue, which fails again; it now says to
start a new conversation.

Tested: every stop reason in the registry through the streamed and non-streamed ask and
chat paths on the Bedrock, Anthropic and OpenRouter shapes. The client-tool streaming
tests that ended a turn on text now stream it, as a provider does.
…g is fine

The server treated every resumed browser run as code the widget would keep on the
reply. The widget records a run only when the tool is not get_full_output, so a reply
whose only run read output back and whose last run hit the output limit with no text got
a warning and an empty done, which the widget drops: a banner and no answer. The parked
call now carries how many of its runs are code (PendingClientCall.code_runs_before,
runs_code), and only those make an empty ending a warning; otherwise it is an error.

Tested: through the real /chat/resume endpoint for each provider shape (read-back only,
code, code earlier in the reply) and the run counts carried across parked calls.
A reply cut off in a long conversation got the cut-off warning and then the
'Conversation is getting long' warning straight after it. The widget keeps one warning
element, so the second overwrote the first unread, in exactly the conversations where
truncation is likeliest. They are now one event. Every warning event also carries an
optional code (cut_off, long_conversation; codes lists both when both apply) so a client
can act on the kind; message is unchanged, so existing clients work as before.

Tested: through the streamed chat with a conversation filled past the token budget on each
provider shape (combined, long only, cut off only, full context window), the ask stream,
and the event builder directly.
…ge short

The error events for an empty or cut-off reply carried no request_id or error_id, so a
reader's report could not be tied to the 502 row in the metrics or to its log line. They
now carry both (the error id is also in the log line), and so do model-call failure events.
The cannot-retry message held a UUID in text the widget shows for five seconds; the error id
is now only a field of the event and the log, and the message fits at a glance.

Tested: ids on the error event match the metrics row and the log record on each provider
shape, ask and chat streams, and every permanent model failure.
Both endpoints return 502 when the model wrote no answer, but their route declarations
listed only 200, 400 and 500, so the OpenAPI schema did not say so.

Tested: the generated schema for both routes.
The streaming ask and chat printed a warning as its event arrived, above the answer;
the batch paths printed it below. The streaming paths now hold warnings until the answer
is printed. An error event's request and error ids are shown as a hint to quote in a report.

Tested: the printed order on all four paths with both consoles writing to one buffer,
several warnings, a stream with no answer, and the id hint.
The state a non-streamed /chat gets back holds the session's whole history, and
extract_token_usage summed the usage of every model message in it. A session that had a
browser turn keeps the model's own messages (replace_history adopts the graph state whole),
so later requests were billed for those runs again. The usage is now read from the messages
after the last human one, the same slice the cut-off check already used.

Tested: a session holding two earlier model runs with usage, then a non-streamed chat on each
provider shape; the cost row is the request's own (was three times it).
… provider takes it

A turn that ends on an error leaves the reader's message with no reply, and the next
message lands right behind it. That stays as it is; the comment where the turn ends says
so, and a test reads what each provider sends for two human messages in a row. Bedrock
merges them (merge_message_runs) and so does Anthropic (its own _merge_messages); the
OpenRouter path sends two consecutive user messages.

Tested: the real /chat endpoint twice per provider, the first request failing, through
the real Bedrock, Anthropic and LiteLLM clients with only the network staged.
@neuromechanist
neuromechanist merged commit 20ad1c4 into develop Sep 30, 2026
7 checks passed
@neuromechanist
neuromechanist deleted the fix/release-0.8.16-streaming-followups branch September 30, 2026 22:36
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant