From 8b728eb8d3a6c173027588148ab8181823eb2731 Mon Sep 17 00:00:00 2001 From: zerone0x Date: Wed, 4 Mar 2026 15:50:54 +0100 Subject: [PATCH] Forward warning messages and compact notifications to client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After /compact runs, the client received no feedback — the LLM-driven summarization ran silently and only a stopReason notification arrived. This change improves the UX in two ways: 1. When a ContextCompaction TurnItem completes (or a ContextCompacted event fires), send an agent message "Context compacted" so users see explicit confirmation that the operation finished. 2. Forward Warning events as agent messages. Codex emits user-facing warnings in several situations (post-compact advisory, deprecated config notices, etc.). Previously they were only logged server-side; now clients receive them as session/update notifications. Fixes #164 Co-Authored-By: Claude --- src/thread.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/thread.rs b/src/thread.rs index 5f916ee..1ed6466 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -48,6 +48,7 @@ use codex_protocol::{ config_types::TrustLevel, custom_prompts::CustomPrompt, dynamic_tools::{DynamicToolCallOutputContentItem, DynamicToolCallRequest}, + items::TurnItem, mcp::CallToolResult, models::{ResponseItem, WebSearchAction}, openai_models::{ModelPreset, ReasoningEffort}, @@ -637,6 +638,11 @@ impl PromptState { item, }) => { info!("Item completed: thread_id={}, turn_id={}, item={:?}", thread_id, turn_id, item); + // Notify the client when context compaction completes so users see + // a status message rather than silence during /compact. + if matches!(item, TurnItem::ContextCompaction(..)) { + client.send_agent_text("Context compacted".to_string()).await; + } } EventMsg::TurnComplete(TurnCompleteEvent { last_agent_message, turn_id }) => { info!( @@ -725,6 +731,9 @@ impl PromptState { } EventMsg::Warning(WarningEvent { message }) => { warn!("Warning: {message}"); + // Forward warnings to the client as agent messages so users see + // informational notices (e.g., the post-compact advisory message). + client.send_agent_text(message).await; } EventMsg::McpStartupUpdate(McpStartupUpdateEvent { server, status }) => { info!("MCP startup update: server={server}, status={status:?}"); @@ -750,6 +759,11 @@ impl PromptState { info!("Model reroute: from={from_model}, to={to_model}, reason={reason:?}"); } + EventMsg::ContextCompacted(..) => { + info!("Context compacted"); + client.send_agent_text("Context compacted".to_string()).await; + } + // Ignore these events EventMsg::AgentReasoningRawContent(..) | EventMsg::ThreadRolledBack(..) @@ -757,7 +771,6 @@ impl PromptState { | EventMsg::TurnDiff(..) // Revisit when we can emit status updates | EventMsg::BackgroundEvent(..) - | EventMsg::ContextCompacted(..) | EventMsg::SkillsUpdateAvailable // Old events | EventMsg::AgentMessageDelta(..)