mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Include the final agent message in turn completion summaries (#34777)
## Why Streamed message deltas can be dropped when the transport is saturated, leaving clients with a truncated final response. ## What changed - Include the last non-empty final agent message in successful `turn/completed` notifications and mark the items as a summary. - Treat completed message content as authoritative in the TUI, repairing an incomplete stream while avoiding duplicate messages when `item/completed` was already received. - Continue backfilling full turn items for persisted `codex exec` threads when a completion contains only the summary view. ## Testing Added coverage for completion summaries, dropped stream deltas, duplicate item handling, and directive-only responses. GitOrigin-RevId: ffe9d36d683d6b6690e4a468ff68aa9189fe6ab7
This commit is contained in:
1 parent
730ec92003
commit
80f3c3141e
15 files changed
+275
-56
No files matched your search
@@ -3,6 +3,7 @@ use crate::outgoing_message::ConnectionRequestId;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::ThreadGoal;
|
||||
use codex_app_server_protocol::ThreadHistoryBuilder;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::ThreadSettings;
|
||||
use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnError;
|
||||
@@ -12,6 +13,9 @@ use codex_file_watcher::WatchRegistration;
|
||||
use codex_protocol::ThreadId;
|
||||
#[cfg(test)]
|
||||
use codex_protocol::config_types::MultiAgentMode;
|
||||
use codex_protocol::items::AgentMessageContent as CoreAgentMessageContent;
|
||||
use codex_protocol::items::TurnItem as CoreTurnItem;
|
||||
use codex_protocol::models::MessagePhase;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::RolloutItem;
|
||||
use codex_rollout::state_db::StateDbHandle;
|
||||
@@ -77,6 +81,7 @@ pub(crate) struct TurnSummary {
|
||||
pub(crate) started_at: Option<i64>,
|
||||
pub(crate) command_execution_started: HashSet<String>,
|
||||
pub(crate) last_error: Option<TurnError>,
|
||||
pub(crate) last_agent_message: Option<ThreadItem>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -150,12 +155,22 @@ impl ThreadState {
|
||||
if let EventMsg::TurnStarted(payload) = event {
|
||||
self.turn_summary.started_at = payload.started_at;
|
||||
}
|
||||
self.current_turn_history.handle_event(event);
|
||||
if matches!(event, EventMsg::TurnAborted(_) | EventMsg::TurnComplete(_))
|
||||
&& !self.current_turn_history.has_active_turn()
|
||||
if let EventMsg::ItemCompleted(payload) = event
|
||||
&& let CoreTurnItem::AgentMessage(item) = &payload.item
|
||||
&& matches!(item.phase, Some(MessagePhase::FinalAnswer) | None)
|
||||
&& item.content.iter().any(|content| {
|
||||
matches!(content, CoreAgentMessageContent::Text { text } if !text.trim().is_empty())
|
||||
})
|
||||
{
|
||||
self.turn_summary.last_agent_message =
|
||||
Some(ThreadItem::from(CoreTurnItem::AgentMessage(item.clone())));
|
||||
}
|
||||
self.current_turn_history.handle_event(event);
|
||||
if matches!(event, EventMsg::TurnAborted(_) | EventMsg::TurnComplete(_)) {
|
||||
self.last_terminal_turn_id = Some(event_turn_id.to_string());
|
||||
self.current_turn_history.reset();
|
||||
if !self.current_turn_history.has_active_turn() {
|
||||
self.current_turn_history.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user