fix(chat): surface interrupted/truncated replies + code-block copy button#207
Merged
Conversation
… copy button Chat replies sometimes rendered as empty bubbles or stopped mid-sentence with zero explanation. Root cause: codec_llm.stream never raises by contract — a non-200, connection drop, or read timeout just ENDED the stream, indistinguishable from a clean finish; and a finish_reason= "length" stop (max_tokens cap, which includes <think> tokens in thinking mode) was silently swallowed. - codec_llm.stream(error_sentinel=True): yields STREAM_ERROR on abnormal death and FINISH_LENGTH on the token-cap stop. Off by default — all existing callers keep the old contract. - routes/chat.py stream path consumes the sentinels and tells the user: "reply interrupted" / "reply truncated (raise chat.max_tokens)". - Blank-bubble fallback now honest: "tool didn't apply" only when [SKILL:] tags were actually resolved (new SkillTagBuffer.tags_resolved counter); otherwise "model returned an empty reply, try again". - chat.max_tokens (default 28000) + chat.llm_timeout_s (default 300) are now operator-tunable via ~/.codec/config.json. - codec_chat.html: every ``` code block gets a floating copy button (reuses the existing clipboard + "copied" feedback path). Tests: 5 new stream-sentinel tests, 3 new tags_resolved tests. Full suite 2440 passed (4 pre-existing pilot-e2e failures, known-issues). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
Fixes the two chat annoyances from today's report (empty bubbles / replies cut mid-sentence) and adds the missing copy button on code blocks.
Why replies died silently:
codec_llm.streamnever raises — a connection drop, model-server non-200, or read timeout just ended the stream, which the chat handler couldn't tell apart from a clean finish. Separately, when the model stopped at themax_tokenscap (finish_reason="length"— and the cap includes<think>tokens in thinking mode), that was swallowed too. Result: blank bubble or mid-sentence stop, no clue why.Now:
stream(error_sentinel=True)yieldsSTREAM_ERROR/FINISH_LENGTHsentinels (opt-in; zero change for other callers)[SKILL:]tags were actually resolved (newtags_resolvedcounter); otherwise it says the model returned nothingchat.max_tokens(28000) andchat.llm_timeout_s(300) are tunable via~/.codec/config.json— deep-chat length is now operator-controlledTests
8 new tests (5 sentinel, 3 tags_resolved). Full suite: 2,440 passed, 4 pre-existing pilot-e2e failures (documented in known-issues).
🤖 Generated with Claude Code