-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Fix: Claude models return incomplete responses due to empty finish_reason handling #6728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Claude models return incomplete responses due to empty finish_reason handling #6728
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Is there an open bug report for this issue? Please provide a link. |
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
There is no existing bug report for this issue. I discovered it while testing Claude models on Windows through AAAI API proxy and debugged it myself. The root cause is in chat_completions.rs where empty finish_reason strings are incorrectly treated as termination signals. I've reverted the tui/src/lib.rs change as suggested by the bot. The core fix in chat_completions.rs should be sufficient to resolve the issue. |
|
It looks like there's a formatting issue (cargo format). Please fix that, and then I think this will be ready to merge. You can ignore the other test failures. The CI nodes used for Windows tests are broken at the moment. |
|
Okay, I’ll fix the formatting issue right away. |
|
The formatting errors have been fixed, and the latest changes have been submitted. |
|
@dulikaifazr, our Windows CI nodes appear to be broken at the moment. We'll fix it tomorrow. Thanks for fixing the formatting issue — it looks good now. |
|
Okay, got it |




Summary
Fixes streaming issue where Claude models return only 1-4 characters instead of full responses when used through certain API providers/proxies.
Environment
Problem
When using Claude models in both TUI and exec modes, only 1-4 characters are displayed despite the backend receiving the full response. Debug logs revealed that some API providers send SSE chunks with an empty string finish_reason during active streaming, rather than null or omitting the field entirely.
The current code treats any non-null finish_reason as a termination signal, causing the stream to exit prematurely after the first chunk. The problematic chunks contain finish_reason with an empty string instead of null.
Solution
Fix empty finish_reason handling in chat_completions.rs by adding a check to only process non-empty finish_reason values. This ensures empty strings are ignored and streaming continues normally.
Testing
Impact
Related Issues
This fix resolves the issue where Claude models appeared to return incomplete responses. The root cause was identified as a compatibility issue in parsing SSE responses from certain API providers/proxies, rather than a model-specific problem. This change improves overall robustness when working with various API endpoints.