Skip to content

fix(openai): retain metrics for incomplete and failed response streams - #978

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi/review-issue-962-14d147c8
Oct 19, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi/review-issue-962-14d147c8

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

AI Summary

OpenAI Responses streams can end with response.incomplete when max_output_tokens is reached, or with response.failed. The streaming postprocessor only read the final response for response.completed, so these streams omitted available token metrics and logged output reconstructed from intermediate events instead of the provider's final response.output.

Recognize all three terminal events in both usage extraction and final-output selection:

result.type in (
    "response.completed",
    "response.incomplete",
    "response.failed",
)

The shared postprocessor now uses the terminal response's output and any reported usage for both sync and async calls. When usage is absent, token metrics remain absent.

Fixes #962.

Read final usage and output from response.incomplete and response.failed
alongside response.completed in the shared streaming postprocessor.

Fixes #962
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-10-19T21:50:31.406264Z d212aee PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

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: d212aeed80

ℹ️ 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 (@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 (@codex) address that feedback".

Comment on lines +1770 to 1771
if result.type in ("response.completed", "response.incomplete", "response.failed"):
if hasattr(result, "response") and hasattr(result.response, "output"):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve buffered output when terminal output is null

When raw responses.create(stream=True) yields a newly handled incomplete or failed event whose response.output is None, this branch passes the hasattr check and immediately returns output=None, discarding the items and deltas already assembled in output. This is a supported lifecycle shape—the OpenAI stream helper reconstructs failed/incomplete output when that field is null—and before this change these event types fell through and retained the buffered output. Use the terminal output only when it is non-null; otherwise preserve the reconstructed buffer.

Useful? React with 👍 / 👎.

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 0e6e386 into main Oct 19, 2026
98 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi/review-issue-962-14d147c8 branch October 19, 2026 23:25
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.

OpenAI Responses streams that end incomplete or failed are logged without token metrics

2 participants