mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Preserve agent message phases in the cloud backend (#61737)
## Why Cloud agent messages lost their phase when converted to app-server thread items, leaving consumers unable to distinguish commentary, final answers, and partial answers. ## What changed Decode the optional phase from cloud agent messages, expose it through `ItemSummary::AgentMessage`, and map it to the corresponding app-server `MessagePhase`. Leave the phase unset for missing or unrecognized values. ## Testing Extend item lifecycle and completed-reply tests to verify that a final-answer phase survives decoding and conversion. Retain history coverage for messages without a phase. GitOrigin-RevId: b7661386758685e0f3c07b53935ff7fd7ba35f7d
This commit is contained in:
committed by
copyberry
parent
540eb31ece
commit
ac2c4a339c
@@ -3,6 +3,7 @@
|
||||
use codex_app_server_protocol as protocol;
|
||||
use codex_cloud_client as cloud;
|
||||
use codex_protocol::models::ImageDetail;
|
||||
use codex_protocol::models::MessagePhase;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::bail;
|
||||
|
||||
@@ -142,12 +143,17 @@ pub(super) fn item_summary(item: cloud::ItemSummary) -> Option<protocol::ThreadI
|
||||
cloud::ItemSummary::AgentMessage {
|
||||
id,
|
||||
text,
|
||||
phase,
|
||||
questions,
|
||||
} => protocol::ThreadItemPayload::AgentMessage {
|
||||
moderation: None,
|
||||
id,
|
||||
text,
|
||||
phase: None,
|
||||
phase: phase.map(|phase| match phase {
|
||||
cloud::AgentMessagePhase::Commentary => MessagePhase::Commentary,
|
||||
cloud::AgentMessagePhase::FinalAnswer => MessagePhase::FinalAnswer,
|
||||
cloud::AgentMessagePhase::PartialAnswer => MessagePhase::PartialAnswer,
|
||||
}),
|
||||
memory_citation: None,
|
||||
delivery: None,
|
||||
questions: questions.map(|questions| {
|
||||
|
||||
@@ -54,10 +54,11 @@ fn image_receipt_preserves_submission_identity_and_attachment() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completed_reply_preserves_the_full_text_questions_and_timestamp() -> Result<()> {
|
||||
fn completed_reply_preserves_the_full_text_phase_questions_and_timestamp() -> Result<()> {
|
||||
let item = cloud::ItemSummary::AgentMessage {
|
||||
id: "reply".into(),
|
||||
text: "Choose one".into(),
|
||||
phase: Some(cloud::AgentMessagePhase::FinalAnswer),
|
||||
questions: Some(vec![cloud::AgentQuestion {
|
||||
title: "Which?".into(),
|
||||
options: Some(vec!["One".into(), "Two".into()]),
|
||||
@@ -82,7 +83,7 @@ fn completed_reply_preserves_the_full_text_questions_and_timestamp() -> Result<(
|
||||
moderation: None,
|
||||
id: "reply".into(),
|
||||
text: "Choose one".into(),
|
||||
phase: None,
|
||||
phase: Some(MessagePhase::FinalAnswer),
|
||||
memory_citation: None,
|
||||
delivery: None,
|
||||
questions: Some(vec![protocol::AsyncUserInputQuestion {
|
||||
|
||||
@@ -77,6 +77,7 @@ async fn item_history_paginates_with_explicit_filters_and_preserves_rows() {
|
||||
&Some(ItemSummary::AgentMessage {
|
||||
id: "i".into(),
|
||||
text: "d".into(),
|
||||
phase: None,
|
||||
questions: Some(vec![AgentQuestion {
|
||||
title: "Q".into(),
|
||||
options: None
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use prost::Message;
|
||||
|
||||
const AGENT: &[u8] = b"\x1a\x06\x12\x01i\x32\x01d";
|
||||
const AGENT: &[u8] = b"\x1a\x0a\x12\x01i\x22\x02\x10\x01\x32\x01d";
|
||||
|
||||
const COMMAND: &[u8] =
|
||||
b"\x0a\x00\x12\x01c\x1a\x07\x0a\x05\x22\x03\x0a\x01c\x22\x01w\x28\x00\x30\x00\x3a\x01i\x60\x03";
|
||||
@@ -53,6 +53,7 @@ async fn item_lifecycle_keeps_identity_and_timestamps() {
|
||||
item: ItemSummary::AgentMessage {
|
||||
id: "i".into(),
|
||||
text: "d".into(),
|
||||
phase: Some(AgentMessagePhase::FinalAnswer),
|
||||
questions: None,
|
||||
},
|
||||
};
|
||||
@@ -297,6 +298,7 @@ fn agent_messages_keep_questions_with_empty_text() {
|
||||
Some(ItemSummary::AgentMessage {
|
||||
id: "i".into(),
|
||||
text: String::new(),
|
||||
phase: None,
|
||||
questions: Some(expected),
|
||||
})
|
||||
);
|
||||
@@ -388,6 +390,7 @@ fn item_summaries_redact_sensitive_fields() {
|
||||
questions: None,
|
||||
id: "secret".into(),
|
||||
text: "secret".into(),
|
||||
phase: None,
|
||||
};
|
||||
let text = format!("{item:?}");
|
||||
assert_eq!(text, "ItemSummary([redacted])");
|
||||
|
||||
@@ -76,12 +76,28 @@ pub(super) enum Value {
|
||||
pub(super) struct AgentMessage {
|
||||
#[prost(string, optional, tag = "2")]
|
||||
pub id: Option<String>,
|
||||
#[prost(message, optional, tag = "4")]
|
||||
pub phase: Option<MessagePhase>,
|
||||
#[prost(message, optional, tag = "5")]
|
||||
pub questions: Option<AgentQuestionList>,
|
||||
#[prost(string, optional, tag = "6")]
|
||||
pub text: Option<String>,
|
||||
}
|
||||
#[derive(Clone, Message)]
|
||||
pub(super) struct MessagePhase {
|
||||
#[prost(oneof = "MessagePhaseValue", tags = "1, 2, 3")]
|
||||
pub value: Option<MessagePhaseValue>,
|
||||
}
|
||||
#[derive(Clone, prost::Oneof)]
|
||||
pub(super) enum MessagePhaseValue {
|
||||
#[prost(int32, tag = "1")]
|
||||
Commentary(i32),
|
||||
#[prost(int32, tag = "2")]
|
||||
FinalAnswer(i32),
|
||||
#[prost(int32, tag = "3")]
|
||||
PartialAnswer(i32),
|
||||
}
|
||||
#[derive(Clone, Message)]
|
||||
pub(super) struct AgentQuestionList {
|
||||
#[prost(message, repeated, tag = "1")]
|
||||
pub values: Vec<AgentQuestion>,
|
||||
|
||||
@@ -33,6 +33,7 @@ pub enum ItemSummary {
|
||||
AgentMessage {
|
||||
id: String,
|
||||
text: String,
|
||||
phase: Option<AgentMessagePhase>,
|
||||
questions: Option<Vec<AgentQuestion>>,
|
||||
},
|
||||
Reasoning {
|
||||
@@ -47,6 +48,15 @@ pub enum ItemSummary {
|
||||
status: ItemStatus,
|
||||
},
|
||||
}
|
||||
|
||||
/// Phase explicitly supplied in a native agent message.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum AgentMessagePhase {
|
||||
Commentary,
|
||||
FinalAnswer,
|
||||
PartialAnswer,
|
||||
}
|
||||
|
||||
/// A structured question attached to an agent message.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct AgentQuestion {
|
||||
@@ -234,6 +244,16 @@ pub(crate) fn summary(item: wire::Item) -> Result<Option<ItemSummary>, DecodeFai
|
||||
Some(wire::Value::AgentMessage(value)) => ItemSummary::AgentMessage {
|
||||
id: required(value.id)?,
|
||||
text: required(value.text)?,
|
||||
phase: match value.phase.and_then(|phase| phase.value) {
|
||||
Some(wire::MessagePhaseValue::Commentary(1)) => Some(AgentMessagePhase::Commentary),
|
||||
Some(wire::MessagePhaseValue::FinalAnswer(1)) => {
|
||||
Some(AgentMessagePhase::FinalAnswer)
|
||||
}
|
||||
Some(wire::MessagePhaseValue::PartialAnswer(1)) => {
|
||||
Some(AgentMessagePhase::PartialAnswer)
|
||||
}
|
||||
Some(_) | None => None,
|
||||
},
|
||||
questions: value
|
||||
.questions
|
||||
.map(|questions| {
|
||||
|
||||
@@ -49,6 +49,7 @@ pub use history::HistoryQuery;
|
||||
pub use history::HistoryTurn;
|
||||
pub use history::ListItemsRequest;
|
||||
pub use history::ListTurnsRequest;
|
||||
pub use items::AgentMessagePhase;
|
||||
pub use items::AgentQuestion;
|
||||
pub use items::CommandAction;
|
||||
pub use items::CommandExecutionSource;
|
||||
|
||||
Reference in New Issue
Block a user