fix(codex): accumulate output items from stream events

The Codex/OpenAI Responses streaming API sends output items via
response.output_item.done events during the stream, but the final
response.completed event arrives with an empty Output array. This
caused all Codex provider responses to return empty content despite
the model successfully generating a reply.

Fix by accumulating output items as they arrive and merging them
into the response when response.completed has none.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
grearsl 2026-04-09 07:34:46 +01:00
parent 06023c79fa
commit be005307b2

View file

@ -104,12 +104,21 @@ func (p *CodexProvider) Chat(
defer stream.Close()
var resp *responses.Response
var accumulatedOutput []responses.ResponseOutputItemUnion
for stream.Next() {
evt := stream.Current()
// Accumulate output items as they arrive — the response.completed
// event may not include them in its Response.Output field.
if evt.Type == "response.output_item.done" {
accumulatedOutput = append(accumulatedOutput, evt.Item)
}
if evt.Type == "response.completed" || evt.Type == "response.failed" || evt.Type == "response.incomplete" {
evtResp := evt.Response
if evtResp.ID != "" {
evtRespCopy := evtResp
if len(evtRespCopy.Output) == 0 && len(accumulatedOutput) > 0 {
evtRespCopy.Output = accumulatedOutput
}
resp = &evtRespCopy
}
}