From be005307b23c1c858408ed3d69716698dfeeaa38 Mon Sep 17 00:00:00 2001 From: grearsl Date: Thu, 9 Apr 2026 07:34:46 +0100 Subject: [PATCH] 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 --- pkg/providers/codex_provider.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/providers/codex_provider.go b/pkg/providers/codex_provider.go index d968215cc..b9040db03 100644 --- a/pkg/providers/codex_provider.go +++ b/pkg/providers/codex_provider.go @@ -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 } }