From 120ef3e15a55a86b8795f3eb88cf6b0f6d746025 Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Mon, 2 Feb 2026 12:58:24 -0800 Subject: [PATCH] Gate todo update notifications by client version --- codex-rs/Cargo.lock | 1 + codex-rs/app-server/Cargo.toml | 1 + .../app-server/src/bespoke_event_handling.rs | 50 ++++++++++++++++--- codex-rs/app-server/src/message_processor.rs | 1 + codex-rs/app-server/src/outgoing_message.rs | 33 ++++++++++++ 5 files changed, 80 insertions(+), 6 deletions(-) diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 4c321b3f62..b23e14eb9f 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -1102,6 +1102,7 @@ dependencies = [ "os_info", "pretty_assertions", "rmcp", + "semver", "serde", "serde_json", "serial_test", diff --git a/codex-rs/app-server/Cargo.toml b/codex-rs/app-server/Cargo.toml index af2f30c49c..8e37b76dab 100644 --- a/codex-rs/app-server/Cargo.toml +++ b/codex-rs/app-server/Cargo.toml @@ -33,6 +33,7 @@ codex-utils-json-to-toml = { workspace = true } chrono = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } +semver = { workspace = true } mcp-types = { workspace = true } tempfile = { workspace = true } time = { workspace = true } diff --git a/codex-rs/app-server/src/bespoke_event_handling.rs b/codex-rs/app-server/src/bespoke_event_handling.rs index 0737dda346..6eb167d25e 100644 --- a/codex-rs/app-server/src/bespoke_event_handling.rs +++ b/codex-rs/app-server/src/bespoke_event_handling.rs @@ -1157,6 +1157,12 @@ async fn handle_turn_todo_update( explanation, todo: steps, }; + if outgoing.supports_turn_todos_updated().await { + outgoing + .send_server_notification(ServerNotification::TurnTodosUpdated(notification)) + .await; + return; + } let legacy_params = match serde_json::to_value(¬ification) { Ok(params) => Some(params), Err(err) => { @@ -1164,9 +1170,6 @@ async fn handle_turn_todo_update( None } }; - outgoing - .send_server_notification(ServerNotification::TurnTodosUpdated(notification)) - .await; if let Some(params) = legacy_params { outgoing .send_notification(OutgoingNotification { @@ -2006,6 +2009,7 @@ mod tests { async fn test_handle_turn_todo_update_emits_notification_for_v2() -> Result<()> { let (tx, mut rx) = mpsc::channel(CHANNEL_CAPACITY); let outgoing = OutgoingMessageSender::new(tx); + outgoing.set_client_version("0.94.0").await; let update = UpdateTodoArgs::new( Some("need todo list".to_string()), vec![ @@ -2054,11 +2058,45 @@ mod tests { } other => bail!("unexpected message: {other:?}"), } - let legacy_msg = rx + assert!(rx.try_recv().is_err(), "no extra messages expected"); + Ok(()) + } + + #[tokio::test] + async fn test_handle_turn_todo_update_emits_legacy_for_old_client() -> Result<()> { + let (tx, mut rx) = mpsc::channel(CHANNEL_CAPACITY); + let outgoing = OutgoingMessageSender::new(tx); + outgoing.set_client_version("0.93.0").await; + let update = UpdateTodoArgs::new( + Some("need todo list".to_string()), + vec![ + TodoItemArg { + step: "first".to_string(), + status: TodoStatus::Pending, + }, + TodoItemArg { + step: "second".to_string(), + status: TodoStatus::Completed, + }, + ], + ); + + let conversation_id = ThreadId::new(); + + handle_turn_todo_update( + conversation_id, + "turn-123", + update, + ApiVersion::V2, + &outgoing, + ) + .await; + + let msg = rx .recv() .await .ok_or_else(|| anyhow!("should send legacy notification"))?; - match legacy_msg { + match msg { OutgoingMessage::Notification(notification) => { assert_eq!(notification.method, "turn/plan/updated"); let params = notification @@ -2070,7 +2108,7 @@ mod tests { "legacy plan alias should mirror todo" ); } - other => bail!("unexpected legacy message: {other:?}"), + other => bail!("unexpected message: {other:?}"), } assert!(rx.try_recv().is_err(), "no extra messages expected"); Ok(()) diff --git a/codex-rs/app-server/src/message_processor.rs b/codex-rs/app-server/src/message_processor.rs index 95d62d3f90..6532050bae 100644 --- a/codex-rs/app-server/src/message_processor.rs +++ b/codex-rs/app-server/src/message_processor.rs @@ -155,6 +155,7 @@ impl MessageProcessor { if let Ok(mut suffix) = USER_AGENT_SUFFIX.lock() { *suffix = Some(user_agent_suffix); } + self.outgoing.set_client_version(&version).await; let user_agent = get_codex_user_agent(); let response = InitializeResponse { user_agent }; diff --git a/codex-rs/app-server/src/outgoing_message.rs b/codex-rs/app-server/src/outgoing_message.rs index 7b4a599b00..68c1b31599 100644 --- a/codex-rs/app-server/src/outgoing_message.rs +++ b/codex-rs/app-server/src/outgoing_message.rs @@ -8,6 +8,7 @@ use codex_app_server_protocol::Result; use codex_app_server_protocol::ServerNotification; use codex_app_server_protocol::ServerRequest; use codex_app_server_protocol::ServerRequestPayload; +use semver::Version; use serde::Serialize; use tokio::sync::Mutex; use tokio::sync::mpsc; @@ -24,6 +25,7 @@ pub(crate) struct OutgoingMessageSender { next_request_id: AtomicI64, sender: mpsc::Sender, request_id_to_callback: Mutex>>, + client_version: Mutex>, } impl OutgoingMessageSender { @@ -32,6 +34,21 @@ impl OutgoingMessageSender { next_request_id: AtomicI64::new(0), sender, request_id_to_callback: Mutex::new(HashMap::new()), + client_version: Mutex::new(None), + } + } + + pub(crate) async fn set_client_version(&self, version: &str) { + let parsed = parse_cli_version(version); + let mut client_version = self.client_version.lock().await; + *client_version = parsed; + } + + pub(crate) async fn supports_turn_todos_updated(&self) -> bool { + let client_version = self.client_version.lock().await; + match client_version.as_ref() { + Some(version) => supports_turn_todos_updated(version), + None => false, } } @@ -156,6 +173,22 @@ pub(crate) struct OutgoingError { pub id: RequestId, } +const TURN_TODOS_UPDATED_MIN_VERSION: (u64, u64, u64) = (0, 94, 0); + +fn parse_cli_version(raw: &str) -> Option { + let trimmed = raw.trim(); + let start = trimmed.find(|ch: char| ch.is_ascii_digit())?; + let candidate: String = trimmed[start..] + .chars() + .take_while(|ch| ch.is_ascii_digit() || *ch == '.') + .collect(); + Version::parse(&candidate).ok() +} + +fn supports_turn_todos_updated(version: &Version) -> bool { + (version.major, version.minor, version.patch) >= TURN_TODOS_UPDATED_MIN_VERSION +} + #[cfg(test)] mod tests { use codex_app_server_protocol::AccountLoginCompletedNotification;