fix(codex): preserve streamed text when completed response has empty output#37
Open
sunlei wants to merge 1 commit intobubbuild:mainfrom
Open
fix(codex): preserve streamed text when completed response has empty output#37sunlei wants to merge 1 commit intobubbuild:mainfrom
sunlei wants to merge 1 commit intobubbuild:mainfrom
Conversation
…output The Codex backend sometimes returns a `response.completed` event carrying an SDK Response object with `status="completed"` but `output=[]`, even though earlier stream events already delivered the full assistant text via `output_text.delta`. `_build_response` unconditionally returned this empty Response, discarding the text collected from the stream and causing a misleading `empty response` retry loop. - Narrow the early-return guard in `_build_response`: only return the SDK Response directly when its output is non-empty - Return as-is for non-completed status (preserve error metadata) - Return as-is when the stream collected nothing (avoid pointless reconstruction) - Add regression test with a real SDK Response(output=[])
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.
Summary
Fix
empty responsefailures on the Codex OAuth Responses path.The Codex backend sometimes returns a
response.completedevent carrying an SDKResponseobject withstatus="completed"butoutput=[], even though earlier stream events (output_text.delta) already delivered the full assistant text._build_responseunconditionally returned this emptyResponse, discarding the collected text and triggering a misleadingempty responseretry loop.Related:
Root cause
In
OpenAICodexProvider._build_response:The early return did not check whether
outputwas actually populated. Whenoutput=[], the already-collectedtextfrom stream events was never used to reconstruct the response.Changes
Narrow the early-return guard in
_build_responseso reconstruction from streamed data only happens under precise conditions:outputis non-empty → return as-is (output is good)status != "completed"→ return as-is (preserve error/incomplete metadata)Only when all three checks fail (completed + empty output + stream has content) does the method fall through to the existing reconstruction logic via
_build_response_output.Test plan
response.completedwith a real SDKResponse(output=[])while stream collected text — verifies text is preserved