Skip to content

fix(chat): say so when a reply hits the output-token limit - #667

Merged
kthare10 merged 1 commit into
developfrom
fix/empty-length-reply
Nov 10, 2026
Merged

kthare10 merged 1 commit into
developfrom
fix/empty-length-reply

Conversation

@kthare10

Copy link
Copy Markdown
Contributor

Closes #665

Why

When a provider stops a reply at its output-token cap, OpenCode records finish: "length" and sets no error, so the panel's error box never appears. If the cap is hit while the model is still reasoning, the step has no text and no tool call, and the turn shows nothing. The chat looks like it did nothing.

Seen live on 2026-11-10: the gateway's default model routes to the Jetstream2 qwen-3.8-27b backend, which reports max_output_tokens: 8192. Two first turns recorded output: 0, reasoning: 8192 after about 100 s each.

What changed

  • lib/opencode/output-limit.ts: a pure rule that classifies a finished assistant step cut off at the limit as:

    • empty: stopped before saying or doing anything
    • truncated: stopped after some text or a tool call

    Steps with an error, steps still running, and user messages are ignored.

  • opencode-chat.tsx: the turn bubble now keeps such a step visible and shows an amber notice. For an empty step it reads "No reply: the model used its whole output budget (8.2K tokens) thinking … send again or pick another model". For a truncated step it says the reply may be incomplete.

  • output-limit.test.ts: 10 vitest cases.

This doesn't raise the cap. That limit is on the backend; reporting real limits from the gateway's /v1/models, and the per-caller RPM throttle, are studio-system follow-ups.

Testing

  • tsc --noEmit: clean
  • npm test: 104 passed
  • pytest -q: 1148 passed

Not yet seen in a browser. On :develop, an existing conversation that hit the limit (for example one from 2026-11-10 21:15) should now show the notice when reopened.

A provider that stops a reply at its output cap is recorded by OpenCode as
finish "length" with no error, so the panel's error box never fired. When
the cap was reached while the model was still reasoning, the step had no
text and no tool call and the turn rendered as nothing: the chat looked like
it had done nothing. Seen live on 2026-11-10, where the gateway's default
model routes to a backend capped at 8192 output tokens and two first turns
spent all of it thinking (output 0, reasoning 8192).

lib/opencode/output-limit.ts classifies a finished assistant step as "empty"
(cut off before saying or doing anything) or "truncated" (cut off after some
text or a tool call), and the turn bubble shows an amber notice with the
tokens spent and what to do. Steps with an error are left to the error box.

Closes #665
@kthare10
kthare10 merged commit c9d040d into develop Nov 10, 2026
2 checks passed
@kthare10
kthare10 deleted the fix/empty-length-reply branch November 10, 2026 23:20
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