Skip to content

fix: reject premature Chat Completions stream EOF - #5211

Merged
jbeckwith-oai merged 2 commits into
mainfrom
codex/chat-completions-eof
Sep 28, 2026
Merged

jbeckwith-oai merged 2 commits into
mainfrom
codex/chat-completions-eof

Conversation

@jbeckwith-oai

@jbeckwith-oai jbeckwith-oai commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This pull request fixes premature Chat Completions stream termination being reported as a successful, truncated response. For the official OpenAI endpoint, streams now require a provider finish reason for choice zero before completing; otherwise they raise ModelBehaviorError before tool execution. Interrupted requests remain counted in generation spans even when no usage trailer arrives.

Tool-call buffering preserves real terminal choices instead of synthesizing completion at EOF. Third-party adapter behavior, nonempty length completions, content filtering, and usage trailers remain supported.

Test plan

  • Added offline HTTP SSE tests through the production AsyncOpenAI parser and Runner.run_streamed, covering premature text/tool/empty EOF, normal text and tool completion, buffering, usage, and third-party compatibility.
  • Confirmed the text EOF regressions fail on the unchanged baseline.
  • Focused checks: 206 adapter tests, 29 reasoning/SSE tests, and 125 EOF/tracing tests passed.
  • Full verification: formatting, lint, Mypy, Pyright, parallel tests, and serial tests passed. Native macOS sandbox tests are skipped by the mandated nested-sandbox setting and remain enabled in CI.
  • Two independent reviews of the final complete diff found no actionable issues.

Issue number

No linked issue.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • I've completed the repository-required independent review before submitting this PR

@jbeckwith-oai
jbeckwith-oai requested review from a team, rm-openai and seratch as code owners September 28, 2026 01:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T01:17:27.635122Z af0ea10 New commits
🔒 Security Review ✅ Completed 2026-09-28T01:17:26.603732Z af0ea10 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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.

Reviewed commit: 93233dac21

ℹ️ 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".

Comment thread src/agents/models/chatcmpl_stream_handler.py

@markstuart-oai markstuart-oai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed af0ea10395d6961656ea4b796c20e22f5a5121e9. No actionable findings. Official OpenAI streams now need a real terminal choice before final completion; buffering preserves that evidence instead of fabricating it. The EOF path retains request usage for tracing and closes the stream, while third-party EOF behavior and valid length/tool completions remain supported. The real-parser Runner regressions cover failure before tool execution and successful terminal paths.

All 22 hosted checks passed on this commit. Validation here was source inspection plus hosted CI; I did not run repository tests.

@jbeckwith-oai
jbeckwith-oai merged commit 220e307 into main Sep 28, 2026
22 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the codex/chat-completions-eof branch September 28, 2026 05:37
@github-actions github-actions Bot mentioned this pull request Sep 28, 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.

2 participants