Skip to content

Conversation

@dulikaifazr
Copy link
Contributor

@dulikaifazr dulikaifazr commented Nov 16, 2025

Summary

Fixes streaming issue where Claude models return only 1-4 characters instead of full responses when used through certain API providers/proxies.

Environment

  • OS: Windows
  • Models affected: Claude models (e.g., claude-haiku-4-5-20251001)
  • API Provider: AAAI API proxy (https://api.aaai.vip/v1)
  • Working models: GLM, Google models work correctly

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

  • Tested on Windows with Claude Haiku model via AAAI API proxy
  • Full responses now received and displayed correctly in both TUI and exec modes
  • Other models (GLM, Google) continue to work as expected
  • No regression in existing functionality

Impact

  • Improves compatibility with API providers that send empty finish_reason during streaming
  • Enables Claude models to work correctly in Windows environment
  • No breaking changes to existing functionality

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.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 16, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@dulikaifazr
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Nov 16, 2025
@etraut-openai
Copy link
Collaborator

Is there an open bug report for this issue? Please provide a link.

@etraut-openai
Copy link
Collaborator

@codex review

@etraut-openai etraut-openai added the needs-response Additional information is requested label Nov 16, 2025
Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@dulikaifazr
Copy link
Contributor Author

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.

@dulikaifazr
Copy link
Contributor Author

image Currently, there is an issue with the handling logic of model responses in the official CLI and IDE plugins. The first image shows that it can be used with the same API provider without any problem. image From the second image, it can be seen that the Claude model from the same API provider did not respond at all. image The third image shows that the same Claude model is also completely unusable in the official IDE plugin. 屏幕截图 2025-11-16 195036 The fourth image shows the modifications made under the condition of minimal optimal changes without affecting any functionality. It can work perfectly for receiving and replying, making it compatible with any model.

@etraut-openai
Copy link
Collaborator

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.

@dulikaifazr
Copy link
Contributor Author

Okay, I’ll fix the formatting issue right away.

@dulikaifazr
Copy link
Contributor Author

The formatting errors have been fixed, and the latest changes have been submitted.

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Nov 16, 2025
@etraut-openai
Copy link
Collaborator

@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.

@dulikaifazr
Copy link
Contributor Author

Okay, got it

@etraut-openai etraut-openai merged commit de1768d into openai:main Nov 17, 2025
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants