fix: handle empty xAI streams without crashing#4015
Open
shaun0927 wants to merge 2 commits intocamel-ai:masterfrom
Open
fix: handle empty xAI streams without crashing#4015shaun0927 wants to merge 2 commits intocamel-ai:masterfrom
shaun0927 wants to merge 2 commits intocamel-ai:masterfrom
Conversation
The xAI streaming adapter referenced the loop variable after iteration even when the iterator yielded no chunks. Initializing the accumulated response state avoids an UnboundLocalError and locks the behavior with a regression test. Constraint: Keep the existing streaming protocol unchanged for non-empty streams Rejected: Catch UnboundLocalError at call sites | hides the adapter bug instead of fixing it Confidence: high Scope-risk: narrow Reversibility: clean Directive: Streaming helpers should tolerate empty iterators and post-loop bookkeeping must handle that path explicitly Tested: pytest -q test/models/test_xai_model.py Not-tested: Live xAI SDK streaming against a real service
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Constraint: Preserve the behavior fix exactly while satisfying repository formatting hooks Rejected: Skip formatter and rely on maintainers | leaves the PR blocked on avoidable CI noise Confidence: high Scope-risk: narrow Reversibility: clean Directive: Run Ruff formatting on touched Python files before pushing small bug-fix PRs Tested: ruff check camel/models/xai_model.py test/models/test_xai_model.py; pytest -q test/models/test_xai_model.py Not-tested: Live xAI SDK integration
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.
Related Issue
Fixes #4013
Description
XAIModel._stream_to_chunks()referencesresponseafter the streaming loop even when the iterator yields no chunks.This PR initializes the accumulated response state before iteration and keeps the post-loop bookkeeping guarded so empty streams return cleanly instead of crashing with
UnboundLocalError.Changes:
response = Nonebefore iteratingif response is not None:What is the purpose of this pull request?
Checklist
pyproject.tomland runuv lockTest evidence
Passed locally:
1 passed