mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
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
This commit is contained in:
committed by
copyberry
parent
c9325ea78c
commit
f1fd6c4c35
@@ -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,
|
||||
&[
|
||||
|
||||
@@ -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<Option<ItemSummary>, 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);
|
||||
|
||||
@@ -46,6 +46,8 @@ pub enum UserMessageInput {
|
||||
image: ImageReference,
|
||||
detail: Option<ImageDetail>,
|
||||
},
|
||||
/// 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(),
|
||||
|
||||
@@ -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<u8>),
|
||||
}
|
||||
#[derive(Clone, Message)]
|
||||
pub(super) struct Mention {
|
||||
#[prost(string, optional, tag = "1")]
|
||||
pub name: Option<String>,
|
||||
#[prost(string, optional, tag = "2")]
|
||||
pub path: Option<String>,
|
||||
}
|
||||
#[derive(Clone, Message)]
|
||||
pub(super) struct Text {
|
||||
#[prost(string, optional, tag = "1")]
|
||||
pub text: Option<String>,
|
||||
|
||||
Reference in New Issue
Block a user