From f1fd6c4c3570401033d25ea1a34e111b000df0d4 Mon Sep 17 00:00:00 2001 From: Benjamin Carlsson Date: Mon, 23 Nov 2026 01:55:12 +0000 Subject: [PATCH] Preserve mentions in cloud conversation transcripts (#63237) ## Why The cloud client treated user messages containing mentions as opaque, which prevented those messages from reaching callers as structured transcript items. ## What changed Decode mention names and paths in cloud history and live events, and carry them through to the app-server protocol as `UserInput::Mention`. Malformed or incomplete mentions still leave the containing item opaque. Cloud turn submissions reject mention inputs. ## Testing Extend tests to cover plugin mentions alongside text and images, app mentions in app-server receipts, and malformed or incomplete mention payloads. GitOrigin-RevId: 938cd37a81630ffe4d06f00544972dd9239c0cb3 --- .../app-server-client/src/cloud_backend/events.rs | 3 +++ .../src/cloud_backend/events_tests.rs | 10 +++++++++- codex-rs/cloud-client/src/item_tests.rs | 15 ++++++++++++++- codex-rs/cloud-client/src/items.rs | 12 ++++++++++++ codex-rs/cloud-client/src/turns.rs | 9 +++++++++ codex-rs/cloud-client/src/turns_wire.rs | 9 ++++++++- 6 files changed, 55 insertions(+), 3 deletions(-) diff --git a/codex-rs/app-server-client/src/cloud_backend/events.rs b/codex-rs/app-server-client/src/cloud_backend/events.rs index 8201f2aaff..760b85cd20 100644 --- a/codex-rs/app-server-client/src/cloud_backend/events.rs +++ b/codex-rs/app-server-client/src/cloud_backend/events.rs @@ -137,6 +137,9 @@ pub(super) fn item_summary(item: cloud::ItemSummary) -> Option { + protocol::UserInput::Mention { name, path } + } }) .collect(), }, diff --git a/codex-rs/app-server-client/src/cloud_backend/events_tests.rs b/codex-rs/app-server-client/src/cloud_backend/events_tests.rs index 119f1ef854..8bc14d27e2 100644 --- a/codex-rs/app-server-client/src/cloud_backend/events_tests.rs +++ b/codex-rs/app-server-client/src/cloud_backend/events_tests.rs @@ -4,7 +4,7 @@ use super::*; use pretty_assertions::assert_eq; #[test] -fn image_receipt_preserves_submission_identity_and_attachment() { +fn receipt_preserves_submission_identity_image_and_app_mention() { let label = "[Image #1]"; let actual = item_summary(cloud::ItemSummary::UserMessage { id: "item-1".into(), @@ -22,6 +22,10 @@ fn image_receipt_preserves_submission_identity_and_attachment() { placeholder: Some(label.into()), }], }, + cloud::UserMessageInput::Mention { + name: "Example App".into(), + path: "app://connector_example".into(), + }, ], }); assert_eq!( @@ -47,6 +51,10 @@ fn image_receipt_preserves_submission_identity_and_attachment() { Some(label.into()), )], }, + protocol::UserInput::Mention { + name: "Example App".into(), + path: "app://connector_example".into(), + }, ], }, )) diff --git a/codex-rs/cloud-client/src/item_tests.rs b/codex-rs/cloud-client/src/item_tests.rs index df81424295..19c2c9cde1 100644 --- a/codex-rs/cloud-client/src/item_tests.rs +++ b/codex-rs/cloud-client/src/item_tests.rs @@ -98,7 +98,7 @@ fn user_message_preserves_client_id_and_text() { } #[test] -fn user_message_preserves_images_spans_and_client_id() { +fn user_message_preserves_images_spans_mentions_and_client_id() { let url = "data:image/png;base64,AA=="; let label = "[Image #1]"; let element = [ @@ -112,12 +112,18 @@ fn user_message_preserves_images_spans_and_client_id() { ] .concat(); let image_bytes = [vec![0x08, 99], message(/*tag*/ 2, url.as_bytes())].concat(); + let mention = [ + message(/*tag*/ 1, b"Example"), + message(/*tag*/ 2, b"plugin://plugins~Plugin_example"), + ] + .concat(); let content = [ message(/*tag*/ 1, &message(/*tag*/ 1, &text)), message( /*tag*/ 1, &message(/*tag*/ 2, &message(/*tag*/ 1, &image_bytes)), ), + message(/*tag*/ 1, &message(/*tag*/ 7, &mention)), ] .concat(); let user = message( @@ -145,6 +151,10 @@ fn user_message_preserves_images_spans_and_client_id() { image: ImageReference::Url(url.into()), detail: None, }, + UserMessageInput::Mention { + name: "Example".into(), + path: "plugin://plugins~Plugin_example".into(), + }, ], }; assert_eq!(summary(&user), Some(expected.clone())); @@ -336,6 +346,9 @@ fn unsupported_and_incomplete_items_stay_opaque() { message(/*tag*/ 2, &message(/*tag*/ 3, b"")), // Future image reference. message(/*tag*/ 2, &message(/*tag*/ 1, b"\x08\x01")), // Missing URL. message(/*tag*/ 2, &message(/*tag*/ 2, b"")), // Missing file ID. + message(/*tag*/ 7, b"\xff"), // Malformed mention payload. + message(/*tag*/ 7, &message(/*tag*/ 2, b"plugin://x")), // Missing mention name. + message(/*tag*/ 7, &message(/*tag*/ 1, b"Example")), // Missing mention path. message( /*tag*/ 1, &[ diff --git a/codex-rs/cloud-client/src/items.rs b/codex-rs/cloud-client/src/items.rs index ab673ef1a5..e27edba905 100644 --- a/codex-rs/cloud-client/src/items.rs +++ b/codex-rs/cloud-client/src/items.rs @@ -12,6 +12,7 @@ use crate::transcript::required; use crate::transcript_wire::Envelope; use crate::transcript_wire::SelectedMessages; use crate::transcript_wire::merge_messages; +use prost::Message; use std::fmt; /// Lifecycle identity and timestamp for a typed item event. @@ -231,6 +232,17 @@ pub(crate) fn summary(item: wire::Item) -> Result, DecodeFai }; UserMessageInput::Image { image, detail } } + Some(crate::turns_wire::Value::Mention(bytes)) => { + // Keep an undecodable mention local to this item in history and live events. + let Ok(crate::turns_wire::Mention { + name: Some(name), + path: Some(path), + }) = crate::turns_wire::Mention::decode(bytes.as_slice()) + else { + return Ok(None); + }; + UserMessageInput::Mention { name, path } + } _ => return Ok(None), }; content.push(input); diff --git a/codex-rs/cloud-client/src/turns.rs b/codex-rs/cloud-client/src/turns.rs index 3ecfc097c4..b2d4a1cfa2 100644 --- a/codex-rs/cloud-client/src/turns.rs +++ b/codex-rs/cloud-client/src/turns.rs @@ -46,6 +46,8 @@ pub enum UserMessageInput { image: ImageReference, detail: Option, }, + /// A named resource in existing conversation history. + Mention { name: String, path: String }, } /// A placeholder span in the UTF-8 bytes of a text input part. #[derive(Clone, PartialEq, Eq)] @@ -137,6 +139,7 @@ impl Client { || !request.input.iter().any(|input| match input { UserMessageInput::Text { text, .. } => !text.trim().is_empty(), UserMessageInput::Image { .. } => true, + UserMessageInput::Mention { .. } => false, }) || request.input.iter().any(|input| match input { UserMessageInput::Text { @@ -156,6 +159,7 @@ impl Client { } ImageReference::FileId(value) => value.trim().is_empty(), }, + UserMessageInput::Mention { .. } => true, }) { return Err(MutationError::InvalidRequest); @@ -211,6 +215,11 @@ impl Client { }; wire::Value::Image(wire::Image { value: Some(value) }) } + UserMessageInput::Mention { .. } => { + unreachable!( + "history mentions are rejected by submission validation" + ) + } }), }) .collect(), diff --git a/codex-rs/cloud-client/src/turns_wire.rs b/codex-rs/cloud-client/src/turns_wire.rs index 245584f373..13b459a3b7 100644 --- a/codex-rs/cloud-client/src/turns_wire.rs +++ b/codex-rs/cloud-client/src/turns_wire.rs @@ -1,4 +1,4 @@ -//! Native text/image submission and interruption envelopes; omitted settings inherit thread config. +//! Native message submission and interruption envelopes; omitted settings inherit thread config. use prost::Message; #[derive(Clone, Message)] @@ -50,6 +50,13 @@ pub(super) enum Value { Mention(Vec), } #[derive(Clone, Message)] +pub(super) struct Mention { + #[prost(string, optional, tag = "1")] + pub name: Option, + #[prost(string, optional, tag = "2")] + pub path: Option, +} +#[derive(Clone, Message)] pub(super) struct Text { #[prost(string, optional, tag = "1")] pub text: Option,