Skip to content

fix: surface when a response is truncated by the output limit - #830

Open
northwang-lucky wants to merge 1 commit into
agegr:mainfrom
northwang-lucky:fix/surface-output-limit-truncation
Open

northwang-lucky wants to merge 1 commit into
agegr:mainfrom
northwang-lucky:fix/surface-output-limit-truncation

Conversation

@northwang-lucky

Copy link
Copy Markdown
Contributor

The problem (observed in real use). When an assistant turn ends on stopReason: "length" — e.g. a thinking model spending the entire output budget on reasoning — the conversation stops with no visible answer and no warning; the UI just sits on the last thinking block. It reads exactly like a hung session. We hit this with a 128K-token reasoning-only truncation on a long session: the model never produced a final message, and nothing in the UI said so.

The fix. Mirrors the existing provider-error handling:

  • getAssistantTruncationNotice() in lib/message-display.ts — a pure function beside getAssistantErrorMessage(): non-streaming + stopReason === "length" -> a short notice. stopReason reaches MessageView intact on both the live event path (normalizeToolCalls preserves it through the spread) and the history path (verified).
  • Rendered as an inline notice beside the existing error banner (MessageView), including the thinking-only-truncated case; classified alongside errors in the final-answer logic (ChatWindow) so the message is never silently dropped.

Notice copy: "This response was cut off after reaching the model's output limit. Send a follow-up to continue."

Tests. 5 new cases (3 on the pure function covering the discriminating states, 2 real-render cases on MessageView including thinking-only). tsc / eslint clean; 1025 tests pass on this branch.

Found while building the programmatic dispatch API discussed in #829 — unrelated to that design, so it ships standalone.

- Add getAssistantTruncationNotice() pure function mirroring getAssistantErrorMessage()
- Render a yellow inline banner on assistant messages with stopReason=length
- Fix the empty-content guard so thinking-only truncated messages are not hidden
- Fix ChatWindow finalAnswerMessage classification to treat truncation as terminal
- Add 5 test cases (3 pure-function, 2 component-rendering) for the new seam
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