mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Gate todo update notifications by client version
This commit is contained in:
Generated
+1
@@ -1102,6 +1102,7 @@ dependencies = [
|
||||
"os_info",
|
||||
"pretty_assertions",
|
||||
"rmcp",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serial_test",
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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<OutgoingMessage>,
|
||||
request_id_to_callback: Mutex<HashMap<RequestId, oneshot::Sender<Result>>>,
|
||||
client_version: Mutex<Option<Version>>,
|
||||
}
|
||||
|
||||
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<Version> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user