From 1a7f036fb76a3cbe62173909372a48db7164fb2f Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Sat, 2 Aug 2025 12:17:06 -0700 Subject: [PATCH] fix reasoning --- codex-rs/core/src/chat_completions.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/codex-rs/core/src/chat_completions.rs b/codex-rs/core/src/chat_completions.rs index 829f6bd15a..8874061eaa 100644 --- a/codex-rs/core/src/chat_completions.rs +++ b/codex-rs/core/src/chat_completions.rs @@ -13,7 +13,6 @@ use std::task::Poll; use tokio::sync::mpsc; use tokio::time::timeout; use tracing::debug; -use tracing::trace; use tracing::warn; use crate::ModelProviderInfo; @@ -448,7 +447,11 @@ where response_id, token_usage, }))) => { - if !this.streaming_mode && !this.cumulative.is_empty() { + // Always emit a final OutputItemDone with the cumulative assistant text + // so downstream consumers see a completed item, even when streaming mode + // is enabled (which forwards deltas). This mirrors the Responses API + // behaviour where `response.output_item.done` is emitted alongside deltas. + if !this.cumulative.is_empty() { let aggregated_item = crate::models::ResponseItem::Message { id: None, role: "assistant".to_string(), @@ -480,11 +483,12 @@ where continue; } Poll::Ready(Some(Ok(ResponseEvent::OutputTextDelta(delta)))) => { + // Always accumulate deltas so we can emit a final OutputItemDone at Completed. + this.cumulative.push_str(&delta); if this.streaming_mode { + // In streaming mode, also forward the delta immediately. return Poll::Ready(Some(Ok(ResponseEvent::OutputTextDelta(delta)))); } else { - // Accumulate incremental assistant text deltas. - this.cumulative.push_str(&delta); continue; } } @@ -544,4 +548,3 @@ impl AggregatedChatStream { } } } -