Skip to content

fix(openai): skip streaming chunks without choices - #707

Merged
brnaba-aws merged 1 commit into
2FastLabs:mainfrom
cyyecao-lappland:fix/openai-empty-stream-choices-20261002
Oct 2, 2026
Merged

brnaba-aws merged 1 commit into
2FastLabs:mainfrom
cyyecao-lappland:fix/openai-empty-stream-choices-20261002

Conversation

@cyyecao-lappland

Copy link
Copy Markdown
Contributor

Issue Link (REQUIRED)

Fixes #706

Summary

Changes

Skip OpenAI streaming chunks with an empty choices list before indexing the first choice. Add regression tests using actual SDK chunk objects for usage-only chunks at the start, middle, end, and alone, and for propagation of genuine stream errors. Update the method docstring.

User experience

A usage-only chunk currently raises IndexError and prevents delivery of the accumulated final message. After the fix, text callbacks and the final message are preserved; usage chunks do not generate empty token events.

Validation

  • Four usage-only cases failed on main; all five new cases pass with the fix.
  • OpenAI-related tests: 12 passed.
  • Full Python suite: 442 passed, 1 failure. Main without this fix has 437 passed and the identical failure in test_database_connection_handling: libsql cannot open the Windows temporary database path. No database or storage code is changed.
  • Full production-source Ruff lint passes; new-test lint and formatting pass. The repository's full formatting check reports 47 existing source files requiring formatting, so this PR keeps the source diff focused instead of reformatting unrelated code.
  • Tested on Windows with Python 3.11; all model responses are mocked locally.

Checklist

  • I have performed a self-review of this change (automated code inspection; no human review is claimed).
  • Changes have been tested.
  • Changes are documented.
  • I have linked this PR to an existing issue (required).

This is a bug fix with no public API changes or new dependencies.

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

AI disclosure

This contribution was autonomously authored and tested with Codex (GPT-6), at the account owner's explicit request. Tests use local mocked model responses; no live model call or human review is claimed.

@brnaba-aws
brnaba-aws merged commit 729d5f5 into 2FastLabs:main Oct 2, 2026
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.

Python OpenAIAgent crashes on usage-only streaming chunks with empty choices

2 participants