mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
feat(core): add metadata field to ResponseItem (#28355)
## Description This PR adds an optional `metadata` field to `ResponseItem` for Responses API calls. Only mechanical plumbing, no actual values populated and sent yet. Turns out just adding a new field to `ResponseItem` has quite a large blast radius already. This change is backwards compatible because `metadata` is optional and omitted when absent, so existing response items and rollout history without it still deserialize and requests that do not set it keep the same wire shape. For provider compatibility, we strip out `metadata` before non-OpenAI Responses requests so Azure and AWS Bedrock never see this field. My followup PR here will actually make use of it to start storing and passing along `turn_id`: https://github.com/openai/codex/pull/28360 ## What changed - Added `ResponseItemMetadata` with optional `turn_id`, plus optional `metadata` on Responses API item variants and inter-agent communication. - Preserved item metadata through response-item rewrites such as truncation, missing tool-output synthesis, compaction history rebuilding, visible-history conversion, rollout/resume, and generated app-server schemas/types. - Strip item metadata from non-OpenAI Responses requests while preserving it for OpenAI-shaped requests. - Updated the mechanical fixture/test construction churn required by the new optional field.
This commit is contained in:
committed by
GitHub
Unverified
parent
bef99f861b
commit
040dafa32d
@@ -51,7 +51,7 @@ fn keep_forked_rollout_item(item: &RolloutItem, preserve_reference_context_item:
|
||||
| ResponseItem::WebSearchCall { .. }
|
||||
| ResponseItem::ImageGenerationCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::CompactionTrigger
|
||||
| ResponseItem::CompactionTrigger { .. }
|
||||
| ResponseItem::ContextCompaction { .. }
|
||||
| ResponseItem::Other,
|
||||
) => false,
|
||||
|
||||
@@ -71,6 +71,7 @@ fn assistant_message(text: &str, phase: Option<MessagePhase>) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +91,7 @@ fn spawn_agent_call(call_id: &str) -> ResponseItem {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: call_id.to_string(),
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -861,6 +863,7 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
text: "Parent root guidance.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -869,6 +872,7 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
text: "Parent subagent guidance.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
assistant_message("parent commentary", Some(MessagePhase::Commentary)),
|
||||
assistant_message("parent final answer", Some(MessagePhase::FinalAnswer)),
|
||||
@@ -878,6 +882,7 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
summary: Vec::new(),
|
||||
content: None,
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
},
|
||||
trigger_message.to_response_input_item().into(),
|
||||
spawn_agent_call(&parent_spawn_call_id),
|
||||
@@ -903,7 +908,6 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
.flush_rollout()
|
||||
.await
|
||||
.expect("parent rollout should flush");
|
||||
|
||||
let child_thread_id = harness
|
||||
.control
|
||||
.spawn_agent_with_metadata(
|
||||
@@ -941,6 +945,7 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
text: "parent seed context".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
assistant_message("parent final answer", Some(MessagePhase::FinalAnswer)),
|
||||
ResponseItem::Message {
|
||||
@@ -950,6 +955,7 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
text: "Child subagent guidance.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
assert_eq!(
|
||||
@@ -1080,6 +1086,7 @@ async fn spawn_agent_fork_strips_parent_usage_hints_from_compacted_history() {
|
||||
text: "compacted parent summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -1088,6 +1095,7 @@ async fn spawn_agent_fork_strips_parent_usage_hints_from_compacted_history() {
|
||||
text: "Parent root guidance.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
parent_thread
|
||||
@@ -1385,6 +1393,7 @@ async fn spawn_agent_fork_last_n_turns_drops_parent_startup_prefix_when_under_li
|
||||
text: "parent startup developer context".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}],
|
||||
)
|
||||
.await;
|
||||
@@ -1506,6 +1515,7 @@ async fn spawn_agent_fork_last_n_turns_strips_parent_usage_hints() {
|
||||
text: "Parent root guidance.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
spawn_agent_call(&parent_spawn_call_id),
|
||||
],
|
||||
|
||||
@@ -782,7 +782,10 @@ impl ModelClient {
|
||||
responses_metadata: &CodexResponsesMetadata,
|
||||
) -> Result<ResponsesApiRequest> {
|
||||
let instructions = &prompt.base_instructions.text;
|
||||
let input = prompt.get_formatted_input_for_request(model_info.use_responses_lite);
|
||||
let mut input = prompt.get_formatted_input_for_request(model_info.use_responses_lite);
|
||||
if !self.state.provider.info().is_openai() {
|
||||
input.iter_mut().for_each(ResponseItem::clear_metadata);
|
||||
}
|
||||
let tools = create_tools_json_for_responses_api(&prompt.tools)?;
|
||||
let reasoning = Self::build_reasoning(model_info, effort, summary);
|
||||
let include = if reasoning.is_some() {
|
||||
@@ -1057,9 +1060,15 @@ impl ModelClientSession {
|
||||
trace!("incremental request failed, items didn't match");
|
||||
return None;
|
||||
};
|
||||
let response_items =
|
||||
last_response.map_or(&[][..], |response| response.items_added.as_slice());
|
||||
let Some(incremental_items) = after_previous_input.strip_prefix(response_items) else {
|
||||
let mut response_items =
|
||||
last_response.map_or_else(Vec::new, |response| response.items_added.clone());
|
||||
if !self.client.state.provider.info().is_openai() {
|
||||
response_items
|
||||
.iter_mut()
|
||||
.for_each(ResponseItem::clear_metadata);
|
||||
}
|
||||
let Some(incremental_items) = after_previous_input.strip_prefix(response_items.as_slice())
|
||||
else {
|
||||
trace!("incremental request failed, items didn't match");
|
||||
return None;
|
||||
};
|
||||
|
||||
@@ -98,7 +98,7 @@ fn strip_image_details(items: &mut [ResponseItem]) {
|
||||
| ResponseItem::WebSearchCall { .. }
|
||||
| ResponseItem::ImageGenerationCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::CompactionTrigger
|
||||
| ResponseItem::CompactionTrigger { .. }
|
||||
| ResponseItem::ContextCompaction { .. }
|
||||
| ResponseItem::Other => {}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ fn prompt_with_image_outputs() -> Prompt {
|
||||
detail: Some(ImageDetail::Original),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "function-call".to_string(),
|
||||
@@ -29,6 +30,7 @@ fn prompt_with_image_outputs() -> Prompt {
|
||||
detail: Some(ImageDetail::High),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "custom-call".to_string(),
|
||||
@@ -39,6 +41,7 @@ fn prompt_with_image_outputs() -> Prompt {
|
||||
detail: Some(ImageDetail::Auto),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
@@ -63,6 +66,7 @@ fn responses_lite_request_copies_strip_image_details() {
|
||||
detail: None,
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "function-call".to_string(),
|
||||
@@ -72,6 +76,7 @@ fn responses_lite_request_copies_strip_image_details() {
|
||||
detail: None,
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "custom-call".to_string(),
|
||||
@@ -82,6 +87,7 @@ fn responses_lite_request_copies_strip_image_details() {
|
||||
detail: None,
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
@@ -225,6 +225,7 @@ fn output_message(id: &str, text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ async fn forward_events_cancelled_while_send_blocked_shuts_down_delegate() {
|
||||
call_id: "call-1".to_string(),
|
||||
name: "tool".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -437,6 +437,7 @@ impl CodexThread {
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText { text: message }],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
self.codex
|
||||
.session
|
||||
|
||||
@@ -32,6 +32,7 @@ use codex_protocol::items::TurnItem;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ResponseInputItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::models::ResponseItemMetadata;
|
||||
use codex_protocol::protocol::CompactedItem;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
@@ -443,7 +444,13 @@ pub fn content_items_to_text(content: &[ContentItem]) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn collect_user_messages(items: &[ResponseItem]) -> Vec<String> {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct CompactedUserMessage {
|
||||
message: String,
|
||||
metadata: Option<ResponseItemMetadata>,
|
||||
}
|
||||
|
||||
pub(crate) fn collect_user_messages(items: &[ResponseItem]) -> Vec<CompactedUserMessage> {
|
||||
items
|
||||
.iter()
|
||||
.filter_map(|item| match crate::event_mapping::parse_turn_item(item) {
|
||||
@@ -451,7 +458,13 @@ pub(crate) fn collect_user_messages(items: &[ResponseItem]) -> Vec<String> {
|
||||
if is_summary_message(&user.message()) {
|
||||
None
|
||||
} else {
|
||||
Some(user.message())
|
||||
Some(CompactedUserMessage {
|
||||
message: user.message(),
|
||||
metadata: match item {
|
||||
ResponseItem::Message { metadata, .. } => metadata.clone(),
|
||||
_ => None,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
@@ -522,7 +535,7 @@ pub(crate) fn insert_initial_context_before_last_real_user_or_summary(
|
||||
|
||||
pub(crate) fn build_compacted_history(
|
||||
initial_context: Vec<ResponseItem>,
|
||||
user_messages: &[String],
|
||||
user_messages: &[CompactedUserMessage],
|
||||
summary_text: &str,
|
||||
) -> Vec<ResponseItem> {
|
||||
build_compacted_history_with_limit(
|
||||
@@ -535,24 +548,28 @@ pub(crate) fn build_compacted_history(
|
||||
|
||||
fn build_compacted_history_with_limit(
|
||||
mut history: Vec<ResponseItem>,
|
||||
user_messages: &[String],
|
||||
user_messages: &[CompactedUserMessage],
|
||||
summary_text: &str,
|
||||
max_tokens: usize,
|
||||
) -> Vec<ResponseItem> {
|
||||
let mut selected_messages: Vec<String> = Vec::new();
|
||||
let mut selected_messages: Vec<CompactedUserMessage> = Vec::new();
|
||||
if max_tokens > 0 {
|
||||
let mut remaining = max_tokens;
|
||||
for message in user_messages.iter().rev() {
|
||||
if remaining == 0 {
|
||||
break;
|
||||
}
|
||||
let tokens = approx_token_count(message);
|
||||
let tokens = approx_token_count(&message.message);
|
||||
if tokens <= remaining {
|
||||
selected_messages.push(message.clone());
|
||||
remaining = remaining.saturating_sub(tokens);
|
||||
} else {
|
||||
let truncated = truncate_text(message, TruncationPolicy::Tokens(remaining));
|
||||
selected_messages.push(truncated);
|
||||
let truncated =
|
||||
truncate_text(&message.message, TruncationPolicy::Tokens(remaining));
|
||||
selected_messages.push(CompactedUserMessage {
|
||||
message: truncated,
|
||||
metadata: message.metadata.clone(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -564,9 +581,10 @@ fn build_compacted_history_with_limit(
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: message.clone(),
|
||||
text: message.message.clone(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: message.metadata.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -581,6 +599,7 @@ fn build_compacted_history_with_limit(
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText { text: summary_text }],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
});
|
||||
|
||||
history
|
||||
|
||||
@@ -344,7 +344,7 @@ pub(crate) fn should_keep_compacted_history_item(item: &ResponseItem) -> bool {
|
||||
ResponseItem::Message { .. } => false,
|
||||
ResponseItem::AgentMessage { .. } => true,
|
||||
ResponseItem::Compaction { .. } | ResponseItem::ContextCompaction { .. } => true,
|
||||
ResponseItem::CompactionTrigger => false,
|
||||
ResponseItem::CompactionTrigger { .. } => false,
|
||||
ResponseItem::Reasoning { .. }
|
||||
| ResponseItem::LocalShellCall { .. }
|
||||
| ResponseItem::FunctionCall { .. }
|
||||
@@ -403,29 +403,38 @@ pub(crate) fn trim_function_call_history_to_fit_context_window(
|
||||
|
||||
fn rewritten_output_for_context_window(item: &ResponseItem) -> Option<ResponseItem> {
|
||||
Some(match item {
|
||||
ResponseItem::FunctionCallOutput { call_id, output } => ResponseItem::FunctionCallOutput {
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id,
|
||||
output,
|
||||
metadata,
|
||||
} => ResponseItem::FunctionCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
output: truncated_output_payload(output),
|
||||
metadata: metadata.clone(),
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id,
|
||||
name,
|
||||
output,
|
||||
metadata,
|
||||
} => ResponseItem::CustomToolCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
name: name.clone(),
|
||||
output: truncated_output_payload(output),
|
||||
metadata: metadata.clone(),
|
||||
},
|
||||
ResponseItem::ToolSearchOutput {
|
||||
call_id,
|
||||
status,
|
||||
execution,
|
||||
metadata,
|
||||
..
|
||||
} => ResponseItem::ToolSearchOutput {
|
||||
call_id: call_id.clone(),
|
||||
status: status.clone(),
|
||||
execution: execution.clone(),
|
||||
tools: Vec::new(),
|
||||
metadata: metadata.clone(),
|
||||
},
|
||||
_ => return None,
|
||||
})
|
||||
|
||||
@@ -231,7 +231,7 @@ async fn run_remote_compact_task_inner_impl(
|
||||
)
|
||||
.await?;
|
||||
let mut input = prompt_input.clone();
|
||||
input.push(ResponseItem::CompactionTrigger);
|
||||
input.push(ResponseItem::CompactionTrigger { metadata: None });
|
||||
let prompt = Prompt {
|
||||
input,
|
||||
tools: tool_router.model_visible_specs(),
|
||||
@@ -515,6 +515,7 @@ fn truncate_message_text_to_token_budget(
|
||||
role,
|
||||
content,
|
||||
phase,
|
||||
metadata,
|
||||
} = item
|
||||
else {
|
||||
return Some(item);
|
||||
@@ -553,6 +554,7 @@ fn truncate_message_text_to_token_budget(
|
||||
role,
|
||||
content: truncated_content,
|
||||
phase,
|
||||
metadata,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -573,6 +575,7 @@ mod tests {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,13 +607,16 @@ mod tests {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call_1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Compaction {
|
||||
encrypted_content: "old".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let output = ResponseItem::Compaction {
|
||||
encrypted_content: "new".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let (history, _) = build_v2_compacted_history(&input, output.clone());
|
||||
@@ -638,6 +644,7 @@ mod tests {
|
||||
];
|
||||
let output = ResponseItem::Compaction {
|
||||
encrypted_content: "new".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let (history, _) = build_v2_compacted_history(&input, output.clone());
|
||||
@@ -664,9 +671,11 @@ mod tests {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
let output = ResponseItem::Compaction {
|
||||
encrypted_content: "new".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let (_, retained_image_count) = build_v2_compacted_history(&input, output);
|
||||
@@ -714,6 +723,7 @@ mod tests {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let truncated =
|
||||
@@ -737,6 +747,7 @@ mod tests {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}]
|
||||
);
|
||||
}
|
||||
@@ -751,6 +762,7 @@ mod tests {
|
||||
detail: None,
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
let newest = message("user", "new", /*phase*/ None);
|
||||
let retained = vec![
|
||||
@@ -775,6 +787,7 @@ mod tests {
|
||||
detail: None,
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
let newest = message("user", "new", /*phase*/ None);
|
||||
let retained = vec![image_only_message, newest.clone()];
|
||||
@@ -789,6 +802,7 @@ mod tests {
|
||||
async fn collect_compaction_output_accepts_additional_output_items() {
|
||||
let compaction = ResponseItem::Compaction {
|
||||
encrypted_content: "encrypted".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
let stream = response_stream(vec![
|
||||
Ok(ResponseEvent::OutputItemDone(message(
|
||||
|
||||
@@ -2,6 +2,7 @@ use super::*;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_model_provider_info::WireApi;
|
||||
use codex_protocol::models::DEFAULT_IMAGE_DETAIL;
|
||||
use codex_protocol::models::ResponseItemMetadata;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
async fn process_compacted_history_with_test_session(
|
||||
@@ -31,6 +32,14 @@ fn user_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn compacted_user_message(text: &str) -> CompactedUserMessage {
|
||||
CompactedUserMessage {
|
||||
message: text.to_string(),
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +84,7 @@ fn collect_user_messages_extracts_user_text_only() {
|
||||
text: "ignored".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: Some("user".to_string()),
|
||||
@@ -83,13 +93,14 @@ fn collect_user_messages_extracts_user_text_only() {
|
||||
text: "first".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Other,
|
||||
];
|
||||
|
||||
let collected = collect_user_messages(&items);
|
||||
|
||||
assert_eq!(vec!["first".to_string()], collected);
|
||||
assert_eq!(vec![compacted_user_message("first")], collected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -107,6 +118,7 @@ do things
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -115,6 +127,7 @@ do things
|
||||
text: "<ENVIRONMENT_CONTEXT>cwd=/tmp</ENVIRONMENT_CONTEXT>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -123,12 +136,13 @@ do things
|
||||
text: "real user message".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
let collected = collect_user_messages(&items);
|
||||
|
||||
assert_eq!(vec!["real user message".to_string()], collected);
|
||||
assert_eq!(vec![compacted_user_message("real user message")], collected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -148,7 +162,7 @@ fn collect_user_messages_filters_legacy_warnings() {
|
||||
|
||||
let collected = collect_user_messages(&items);
|
||||
|
||||
assert_eq!(vec!["real user message".to_string()], collected);
|
||||
assert_eq!(vec![compacted_user_message("real user message")], collected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -157,9 +171,10 @@ fn build_token_limited_compacted_history_truncates_overlong_user_messages() {
|
||||
// that oversized user content is truncated.
|
||||
let max_tokens = 16;
|
||||
let big = "word ".repeat(200);
|
||||
let user_message = compacted_user_message(&big);
|
||||
let history = super::build_compacted_history_with_limit(
|
||||
Vec::new(),
|
||||
std::slice::from_ref(&big),
|
||||
std::slice::from_ref(&user_message),
|
||||
"SUMMARY",
|
||||
max_tokens,
|
||||
);
|
||||
@@ -196,7 +211,7 @@ fn build_token_limited_compacted_history_truncates_overlong_user_messages() {
|
||||
#[test]
|
||||
fn build_token_limited_compacted_history_appends_summary_message() {
|
||||
let initial_context: Vec<ResponseItem> = Vec::new();
|
||||
let user_messages = vec!["first user message".to_string()];
|
||||
let user_messages = vec![compacted_user_message("first user message")];
|
||||
let summary_text = "summary text";
|
||||
|
||||
let history = build_compacted_history(initial_context, &user_messages, summary_text);
|
||||
@@ -215,6 +230,23 @@ fn build_token_limited_compacted_history_appends_summary_message() {
|
||||
assert_eq!(summary, summary_text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_compacted_history_preserves_user_message_metadata() {
|
||||
let history = build_compacted_history(
|
||||
Vec::new(),
|
||||
&[CompactedUserMessage {
|
||||
message: "first user message".to_string(),
|
||||
metadata: Some(ResponseItemMetadata {
|
||||
turn_id: Some("turn-1".to_string()),
|
||||
}),
|
||||
}],
|
||||
"summary text",
|
||||
);
|
||||
|
||||
assert_eq!(history[0].turn_id(), Some("turn-1"));
|
||||
assert_eq!(history[1].turn_id(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_use_remote_compact_task_for_azure_provider() {
|
||||
let provider = ModelProviderInfo {
|
||||
@@ -249,6 +281,7 @@ async fn process_compacted_history_replaces_developer_messages() {
|
||||
text: "stale permissions".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -257,6 +290,7 @@ async fn process_compacted_history_replaces_developer_messages() {
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -265,6 +299,7 @@ async fn process_compacted_history_replaces_developer_messages() {
|
||||
text: "stale personality".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let (refreshed, mut expected) = process_compacted_history_with_test_session(
|
||||
@@ -279,6 +314,7 @@ async fn process_compacted_history_replaces_developer_messages() {
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
});
|
||||
assert_eq!(refreshed, expected);
|
||||
}
|
||||
@@ -292,6 +328,7 @@ async fn process_compacted_history_reinjects_full_initial_context() {
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
let (refreshed, mut expected) = process_compacted_history_with_test_session(
|
||||
compacted_history,
|
||||
@@ -305,6 +342,7 @@ async fn process_compacted_history_reinjects_full_initial_context() {
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
});
|
||||
assert_eq!(refreshed, expected);
|
||||
}
|
||||
@@ -324,6 +362,7 @@ keep me updated
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -336,6 +375,7 @@ keep me updated
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -348,6 +388,7 @@ keep me updated
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -356,6 +397,7 @@ keep me updated
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -364,6 +406,7 @@ keep me updated
|
||||
text: "stale developer instructions".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let (refreshed, mut expected) = process_compacted_history_with_test_session(
|
||||
@@ -378,6 +421,7 @@ keep me updated
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
});
|
||||
assert_eq!(refreshed, expected);
|
||||
}
|
||||
@@ -417,6 +461,7 @@ async fn process_compacted_history_inserts_context_before_last_real_user_message
|
||||
text: "older user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -425,6 +470,7 @@ async fn process_compacted_history_inserts_context_before_last_real_user_message
|
||||
text: format!("{SUMMARY_PREFIX}\nsummary text"),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -433,6 +479,7 @@ async fn process_compacted_history_inserts_context_before_last_real_user_message
|
||||
text: "latest user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -449,6 +496,7 @@ async fn process_compacted_history_inserts_context_before_last_real_user_message
|
||||
text: "older user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -457,6 +505,7 @@ async fn process_compacted_history_inserts_context_before_last_real_user_message
|
||||
text: format!("{SUMMARY_PREFIX}\nsummary text"),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
expected.extend(initial_context);
|
||||
@@ -467,6 +516,7 @@ async fn process_compacted_history_inserts_context_before_last_real_user_message
|
||||
text: "latest user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
});
|
||||
assert_eq!(refreshed, expected);
|
||||
}
|
||||
@@ -480,6 +530,7 @@ async fn process_compacted_history_reinjects_model_switch_message() {
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
let previous_turn_settings = PreviousTurnSettings {
|
||||
model: "previous-regular-model".to_string(),
|
||||
@@ -510,6 +561,7 @@ async fn process_compacted_history_reinjects_model_switch_message() {
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
});
|
||||
assert_eq!(refreshed, expected);
|
||||
}
|
||||
@@ -524,6 +576,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: "older user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -532,6 +585,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: "latest user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -540,6 +594,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: format!("{SUMMARY_PREFIX}\nsummary text"),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let initial_context = vec![ResponseItem::Message {
|
||||
@@ -549,6 +604,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: "fresh permissions".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
|
||||
let refreshed =
|
||||
@@ -561,6 +617,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: "older user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -569,6 +626,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: "fresh permissions".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -577,6 +635,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: "latest user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -585,6 +644,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
text: format!("{SUMMARY_PREFIX}\nsummary text"),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
assert_eq!(refreshed, expected);
|
||||
@@ -594,6 +654,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_summary_last()
|
||||
fn insert_initial_context_before_last_real_user_or_summary_keeps_compaction_last() {
|
||||
let compacted_history = vec![ResponseItem::Compaction {
|
||||
encrypted_content: "encrypted".to_string(),
|
||||
metadata: None,
|
||||
}];
|
||||
let initial_context = vec![ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -602,6 +663,7 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_compaction_last
|
||||
text: "fresh permissions".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
|
||||
let refreshed =
|
||||
@@ -614,9 +676,11 @@ fn insert_initial_context_before_last_real_user_or_summary_keeps_compaction_last
|
||||
text: "fresh permissions".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Compaction {
|
||||
encrypted_content: "encrypted".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
assert_eq!(refreshed, expected);
|
||||
|
||||
@@ -338,23 +338,25 @@ impl ContextManager {
|
||||
fn process_item(&self, item: &ResponseItem, policy: TruncationPolicy) -> ResponseItem {
|
||||
let policy_with_serialization_budget = policy * 1.2;
|
||||
match item {
|
||||
ResponseItem::FunctionCallOutput { call_id, output } => {
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
output: truncate_function_output_payload(
|
||||
output,
|
||||
policy_with_serialization_budget,
|
||||
),
|
||||
}
|
||||
}
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id,
|
||||
output,
|
||||
metadata,
|
||||
} => ResponseItem::FunctionCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
output: truncate_function_output_payload(output, policy_with_serialization_budget),
|
||||
metadata: metadata.clone(),
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id,
|
||||
name,
|
||||
output,
|
||||
metadata,
|
||||
} => ResponseItem::CustomToolCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
name: name.clone(),
|
||||
output: truncate_function_output_payload(output, policy_with_serialization_budget),
|
||||
metadata: metadata.clone(),
|
||||
},
|
||||
ResponseItem::Message { .. }
|
||||
| ResponseItem::AgentMessage { .. }
|
||||
@@ -367,7 +369,7 @@ impl ContextManager {
|
||||
| ResponseItem::ImageGenerationCall { .. }
|
||||
| ResponseItem::CustomToolCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::CompactionTrigger
|
||||
| ResponseItem::CompactionTrigger { .. }
|
||||
| ResponseItem::ContextCompaction { .. }
|
||||
| ResponseItem::Other => item.clone(),
|
||||
}
|
||||
@@ -459,7 +461,7 @@ fn is_api_message(message: &ResponseItem) -> bool {
|
||||
| ResponseItem::ImageGenerationCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::ContextCompaction { .. } => true,
|
||||
ResponseItem::CompactionTrigger => false,
|
||||
ResponseItem::CompactionTrigger { .. } => false,
|
||||
ResponseItem::Other => false,
|
||||
}
|
||||
}
|
||||
@@ -511,9 +513,11 @@ fn estimate_response_item_model_visible_bytes(item: &ResponseItem) -> i64 {
|
||||
}
|
||||
| ResponseItem::Compaction {
|
||||
encrypted_content: content,
|
||||
..
|
||||
}
|
||||
| ResponseItem::ContextCompaction {
|
||||
encrypted_content: Some(content),
|
||||
..
|
||||
} => i64::try_from(estimate_reasoning_length(content.len())).unwrap_or(i64::MAX),
|
||||
item => {
|
||||
let raw = serde_json::to_string(item)
|
||||
@@ -689,7 +693,7 @@ fn is_model_generated_item(item: &ResponseItem) -> bool {
|
||||
| ResponseItem::LocalShellCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::ContextCompaction { .. } => true,
|
||||
ResponseItem::CompactionTrigger => false,
|
||||
ResponseItem::CompactionTrigger { .. } => false,
|
||||
ResponseItem::FunctionCallOutput { .. }
|
||||
| ResponseItem::ToolSearchOutput { .. }
|
||||
| ResponseItem::CustomToolCallOutput { .. }
|
||||
|
||||
@@ -14,6 +14,7 @@ use codex_protocol::models::LocalShellExecAction;
|
||||
use codex_protocol::models::LocalShellStatus;
|
||||
use codex_protocol::models::ReasoningItemContent;
|
||||
use codex_protocol::models::ReasoningItemReasoningSummary;
|
||||
use codex_protocol::models::ResponseItemMetadata;
|
||||
use codex_protocol::openai_models::InputModality;
|
||||
use codex_protocol::openai_models::default_input_modalities;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
@@ -41,6 +42,7 @@ fn assistant_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +61,7 @@ fn inter_agent_assistant_msg(text: &str) -> ResponseItem {
|
||||
text: serde_json::to_string(&communication).unwrap(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +81,7 @@ fn user_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +93,7 @@ fn user_input_text_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +105,7 @@ fn developer_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +120,7 @@ fn developer_msg_with_fragments(texts: &[&str]) -> ResponseItem {
|
||||
})
|
||||
.collect(),
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +152,7 @@ fn custom_tool_call_output(call_id: &str, output: &str) -> ResponseItem {
|
||||
call_id: call_id.to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text(output.to_string()),
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +166,7 @@ fn reasoning_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}]),
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +178,7 @@ fn reasoning_with_encrypted_content(len: usize) -> ResponseItem {
|
||||
}],
|
||||
content: None,
|
||||
encrypted_content: Some("a".repeat(len)),
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +202,7 @@ fn filters_non_api_messages() {
|
||||
text: "ignored".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
let reasoning = reasoning_msg("thinking...");
|
||||
h.record_items([&system, &reasoning, &ResponseItem::Other], policy);
|
||||
@@ -214,6 +225,7 @@ fn filters_non_api_messages() {
|
||||
text: "thinking...".to_string(),
|
||||
}]),
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -222,6 +234,7 @@ fn filters_non_api_messages() {
|
||||
text: "hi".to_string()
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -230,6 +243,7 @@ fn filters_non_api_messages() {
|
||||
text: "hello".to_string()
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
]
|
||||
);
|
||||
@@ -379,6 +393,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -386,6 +401,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
@@ -398,6 +414,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCall {
|
||||
id: None,
|
||||
@@ -405,6 +422,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
call_id: "tool-1".to_string(),
|
||||
name: "js_repl".to_string(),
|
||||
input: "view_image".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "tool-1".to_string(),
|
||||
@@ -418,6 +436,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let history = create_history_with_items(items);
|
||||
@@ -441,6 +460,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -448,6 +468,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
@@ -460,6 +481,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
.to_string(),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCall {
|
||||
id: None,
|
||||
@@ -467,6 +489,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
call_id: "tool-1".to_string(),
|
||||
name: "js_repl".to_string(),
|
||||
input: "view_image".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "tool-1".to_string(),
|
||||
@@ -480,6 +503,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
.to_string(),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
assert_eq!(stripped, expected);
|
||||
@@ -499,6 +523,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}]);
|
||||
let preserved = with_images.for_prompt(&modalities);
|
||||
assert_eq!(preserved.len(), 1);
|
||||
@@ -518,6 +543,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
|
||||
status: "generating".to_string(),
|
||||
revised_prompt: Some("lobster".to_string()),
|
||||
result: "Zm9v".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -526,6 +552,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
|
||||
text: "hi".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -537,6 +564,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
|
||||
status: "generating".to_string(),
|
||||
revised_prompt: Some("lobster".to_string()),
|
||||
result: "Zm9v".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -545,6 +573,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
|
||||
text: "hi".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
]
|
||||
);
|
||||
@@ -560,12 +589,14 @@ fn for_prompt_clears_image_generation_result_when_images_are_unsupported() {
|
||||
text: "generate a lobster".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::ImageGenerationCall {
|
||||
id: "ig_123".to_string(),
|
||||
status: "completed".to_string(),
|
||||
revised_prompt: Some("lobster".to_string()),
|
||||
result: "Zm9v".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -579,12 +610,14 @@ fn for_prompt_clears_image_generation_result_when_images_are_unsupported() {
|
||||
text: "generate a lobster".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::ImageGenerationCall {
|
||||
id: "ig_123".to_string(),
|
||||
status: "completed".to_string(),
|
||||
revised_prompt: Some("lobster".to_string()),
|
||||
result: String::new(),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -621,10 +654,12 @@ fn remove_first_item_removes_matching_output_for_function_call() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let mut h = create_history_with_items(items);
|
||||
@@ -638,6 +673,7 @@ fn remove_first_item_removes_matching_call_for_output() {
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-2".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -645,6 +681,7 @@ fn remove_first_item_removes_matching_call_for_output() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-2".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let mut h = create_history_with_items(items);
|
||||
@@ -667,6 +704,7 @@ fn replace_last_turn_images_replaces_tool_output_images() {
|
||||
]),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let mut history = create_history_with_items(items);
|
||||
@@ -687,6 +725,7 @@ fn replace_last_turn_images_replaces_tool_output_images() {
|
||||
]),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -702,6 +741,7 @@ fn replace_last_turn_images_does_not_touch_user_images() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
let mut history = create_history_with_items(items.clone());
|
||||
|
||||
@@ -723,10 +763,12 @@ fn remove_first_item_handles_local_shell_pair() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-3".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let mut h = create_history_with_items(items);
|
||||
@@ -948,11 +990,13 @@ fn remove_first_item_handles_custom_tool_pair() {
|
||||
call_id: "tool-1".to_string(),
|
||||
name: "my_tool".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "tool-1".to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let mut h = create_history_with_items(items);
|
||||
@@ -974,10 +1018,12 @@ fn normalization_retains_local_shell_outputs() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "shell-1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("Total output lines: 1\n\nok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1001,6 +1047,9 @@ fn record_items_truncates_function_call_output_content() {
|
||||
body: FunctionCallOutputBody::Text(long_output.clone()),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: Some(ResponseItemMetadata {
|
||||
turn_id: Some("turn-1".to_string()),
|
||||
}),
|
||||
};
|
||||
|
||||
history.record_items([&item], policy);
|
||||
@@ -1021,6 +1070,7 @@ fn record_items_truncates_function_call_output_content() {
|
||||
}
|
||||
other => panic!("unexpected history item: {other:?}"),
|
||||
}
|
||||
assert_eq!(history.items[0].turn_id(), Some("turn-1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1033,6 +1083,7 @@ fn record_items_truncates_custom_tool_call_output_content() {
|
||||
call_id: "tool-200".to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text(long_output.clone()),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
history.record_items([&item], policy);
|
||||
@@ -1066,6 +1117,7 @@ fn record_items_respects_custom_token_limit() {
|
||||
body: FunctionCallOutputBody::Text(long_output),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
history.record_items([&item], policy);
|
||||
@@ -1185,6 +1237,7 @@ fn normalize_adds_missing_output_for_function_call() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-x".to_string(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1199,10 +1252,12 @@ fn normalize_adds_missing_output_for_function_call() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-x".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-x".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -1217,6 +1272,7 @@ fn normalize_adds_missing_output_for_custom_tool_call() {
|
||||
call_id: "tool-x".to_string(),
|
||||
name: "custom".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1231,11 +1287,13 @@ fn normalize_adds_missing_output_for_custom_tool_call() {
|
||||
call_id: "tool-x".to_string(),
|
||||
name: "custom".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "tool-x".to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -1255,6 +1313,7 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1274,10 +1333,12 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "shell-1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -1289,6 +1350,7 @@ fn normalize_removes_orphan_function_call_output() {
|
||||
let items = vec![ResponseItem::FunctionCallOutput {
|
||||
call_id: "orphan-1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1304,6 +1366,7 @@ fn normalize_removes_orphan_custom_tool_call_output() {
|
||||
call_id: "orphan-2".to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1323,11 +1386,13 @@ fn normalize_mixed_inserts_and_removals() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "c1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
// Orphan output that should be removed
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "c2".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
// Will get an inserted custom tool output
|
||||
ResponseItem::CustomToolCall {
|
||||
@@ -1336,6 +1401,7 @@ fn normalize_mixed_inserts_and_removals() {
|
||||
call_id: "t1".to_string(),
|
||||
name: "tool".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
// Local shell call also gets an inserted function call output
|
||||
ResponseItem::LocalShellCall {
|
||||
@@ -1349,6 +1415,7 @@ fn normalize_mixed_inserts_and_removals() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let mut h = create_history_with_items(items);
|
||||
@@ -1364,10 +1431,12 @@ fn normalize_mixed_inserts_and_removals() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "c1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "c1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCall {
|
||||
id: None,
|
||||
@@ -1375,11 +1444,13 @@ fn normalize_mixed_inserts_and_removals() {
|
||||
call_id: "t1".to_string(),
|
||||
name: "tool".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "t1".to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::LocalShellCall {
|
||||
id: None,
|
||||
@@ -1392,10 +1463,12 @@ fn normalize_mixed_inserts_and_removals() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "s1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -1409,6 +1482,7 @@ fn normalize_adds_missing_output_for_function_call_inserts_output() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-x".to_string(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
h.normalize_history(&default_input_modalities());
|
||||
@@ -1421,10 +1495,12 @@ fn normalize_adds_missing_output_for_function_call_inserts_output() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-x".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-x".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -1438,6 +1514,7 @@ fn normalize_adds_missing_output_for_tool_search_call() {
|
||||
status: Some("completed".to_string()),
|
||||
execution: "client".to_string(),
|
||||
arguments: "{}".into(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1452,12 +1529,14 @@ fn normalize_adds_missing_output_for_tool_search_call() {
|
||||
status: Some("completed".to_string()),
|
||||
execution: "client".to_string(),
|
||||
arguments: "{}".into(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::ToolSearchOutput {
|
||||
call_id: Some("search-call-x".to_string()),
|
||||
status: "completed".to_string(),
|
||||
execution: "client".to_string(),
|
||||
tools: Vec::new(),
|
||||
metadata: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -1473,6 +1552,7 @@ fn normalize_adds_missing_output_for_custom_tool_call_panics_in_debug() {
|
||||
call_id: "tool-x".to_string(),
|
||||
name: "custom".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
h.normalize_history(&default_input_modalities());
|
||||
@@ -1493,6 +1573,7 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id_panics_in_debug()
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
h.normalize_history(&default_input_modalities());
|
||||
@@ -1505,6 +1586,7 @@ fn normalize_removes_orphan_function_call_output_panics_in_debug() {
|
||||
let items = vec![ResponseItem::FunctionCallOutput {
|
||||
call_id: "orphan-1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
h.normalize_history(&default_input_modalities());
|
||||
@@ -1518,6 +1600,7 @@ fn normalize_removes_orphan_custom_tool_call_output_panics_in_debug() {
|
||||
call_id: "orphan-2".to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
h.normalize_history(&default_input_modalities());
|
||||
@@ -1531,6 +1614,7 @@ fn normalize_removes_orphan_client_tool_search_output() {
|
||||
status: "completed".to_string(),
|
||||
execution: "client".to_string(),
|
||||
tools: Vec::new(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1548,6 +1632,7 @@ fn normalize_removes_orphan_client_tool_search_output_panics_in_debug() {
|
||||
status: "completed".to_string(),
|
||||
execution: "client".to_string(),
|
||||
tools: Vec::new(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
h.normalize_history(&default_input_modalities());
|
||||
@@ -1560,6 +1645,7 @@ fn normalize_keeps_server_tool_search_output_without_matching_call() {
|
||||
status: "completed".to_string(),
|
||||
execution: "server".to_string(),
|
||||
tools: Vec::new(),
|
||||
metadata: None,
|
||||
}];
|
||||
let mut h = create_history_with_items(items);
|
||||
|
||||
@@ -1572,6 +1658,7 @@ fn normalize_keeps_server_tool_search_output_without_matching_call() {
|
||||
status: "completed".to_string(),
|
||||
execution: "server".to_string(),
|
||||
tools: Vec::new(),
|
||||
metadata: None,
|
||||
}]
|
||||
);
|
||||
}
|
||||
@@ -1587,10 +1674,12 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "c1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "c2".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCall {
|
||||
id: None,
|
||||
@@ -1598,6 +1687,7 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
|
||||
call_id: "t1".to_string(),
|
||||
name: "tool".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::LocalShellCall {
|
||||
id: None,
|
||||
@@ -1610,6 +1700,7 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let mut h = create_history_with_items(items);
|
||||
@@ -1633,6 +1724,7 @@ fn image_data_url_payload_does_not_dominate_message_estimate() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
let text_only_item = ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -1641,6 +1733,7 @@ fn image_data_url_payload_does_not_dominate_message_estimate() {
|
||||
text: "Here is the screenshot".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&image_item).unwrap().len() as i64;
|
||||
@@ -1668,6 +1761,7 @@ fn image_data_url_payload_does_not_dominate_function_call_output_estimate() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1694,6 +1788,7 @@ fn image_data_url_payload_does_not_dominate_custom_tool_call_output_estimate() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1714,6 +1809,7 @@ fn non_base64_image_urls_are_unchanged() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
let function_output_item = ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
@@ -1723,6 +1819,7 @@ fn non_base64_image_urls_are_unchanged() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
@@ -1745,6 +1842,7 @@ fn encrypted_function_output_uses_plaintext_byte_estimate() {
|
||||
encrypted_content: encrypted_content.clone(),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1765,6 +1863,7 @@ fn data_url_without_base64_marker_is_unchanged() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
@@ -1785,6 +1884,7 @@ fn non_image_base64_data_url_is_unchanged() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1805,6 +1905,7 @@ fn mixed_case_data_url_markers_are_adjusted() {
|
||||
detail: Some(DEFAULT_IMAGE_DETAIL),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1837,6 +1938,7 @@ fn multiple_inline_images_apply_multiple_fixed_costs() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1870,6 +1972,7 @@ fn original_detail_images_scale_with_dimensions() {
|
||||
detail: Some(ImageDetail::Original),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1900,6 +2003,7 @@ fn original_detail_images_are_capped_at_max_patch_count() {
|
||||
detail: Some(ImageDetail::Original),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1933,6 +2037,7 @@ fn original_detail_webp_images_scale_with_dimensions() {
|
||||
detail: Some(ImageDetail::Original),
|
||||
},
|
||||
]),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
|
||||
@@ -1951,6 +2056,7 @@ fn text_only_items_unchanged() {
|
||||
text: "Hello world, this is a response.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let estimated = estimate_response_item_model_visible_bytes(&item);
|
||||
|
||||
@@ -49,6 +49,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -64,6 +65,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
|
||||
status: "completed".to_string(),
|
||||
execution: "client".to_string(),
|
||||
tools: Vec::new(),
|
||||
metadata: None,
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -79,6 +81,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
|
||||
call_id: call_id.clone(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -95,6 +98,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
@@ -203,6 +203,7 @@ fn build_text_message(role: &str, text_sections: Vec<String>) -> Option<Response
|
||||
role: role.to_string(),
|
||||
content,
|
||||
phase: None,
|
||||
metadata: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ pub fn parse_turn_item(item: &ResponseItem) -> Option<TurnItem> {
|
||||
status,
|
||||
revised_prompt,
|
||||
result,
|
||||
..
|
||||
} => Some(TurnItem::ImageGeneration(
|
||||
codex_protocol::items::ImageGenerationItem {
|
||||
id: id.clone(),
|
||||
|
||||
@@ -61,6 +61,7 @@ fn parses_user_message_with_text_and_two_images() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected user message turn item");
|
||||
@@ -110,6 +111,7 @@ fn skips_local_image_label_text() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected user message turn item");
|
||||
@@ -142,6 +144,7 @@ fn parses_assistant_message_input_text_for_backward_compatibility() {
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected assistant message turn item");
|
||||
@@ -191,6 +194,7 @@ fn skips_unnamed_image_label_text() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected user message turn item");
|
||||
@@ -223,7 +227,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "# AGENTS.md instructions for test_directory\n\n<INSTRUCTIONS>\ntest_text\n</INSTRUCTIONS>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -231,7 +235,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "<environment_context>test_text</environment_context>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -239,7 +243,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "# AGENTS.md instructions for test_directory\n\n<INSTRUCTIONS>\ntest_text\n</INSTRUCTIONS>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -248,7 +252,7 @@ fn skips_user_instructions_and_env() {
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -256,7 +260,7 @@ fn skips_user_instructions_and_env() {
|
||||
text: "<user_shell_command>echo 42</user_shell_command>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
@@ -271,7 +275,7 @@ fn skips_user_instructions_and_env() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
];
|
||||
|
||||
for item in items {
|
||||
@@ -321,7 +325,7 @@ fn parses_hook_prompt_and_hides_other_contextual_fragments() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
};
|
||||
metadata: None,};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected hook prompt turn item");
|
||||
|
||||
@@ -353,6 +357,7 @@ fn internal_model_context_does_not_parse_as_visible_turn_item() {
|
||||
.render(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
assert!(parse_turn_item(&item).is_none());
|
||||
@@ -367,6 +372,7 @@ fn parses_agent_message() {
|
||||
text: "Hello from Codex".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected agent message turn item");
|
||||
@@ -398,6 +404,7 @@ fn parses_reasoning_summary_and_raw_content() {
|
||||
text: "raw details".to_string(),
|
||||
}]),
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected reasoning turn item");
|
||||
@@ -430,6 +437,7 @@ fn parses_reasoning_including_raw_content() {
|
||||
},
|
||||
]),
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected reasoning turn item");
|
||||
@@ -455,6 +463,7 @@ fn parses_web_search_call() {
|
||||
query: Some("weather".to_string()),
|
||||
queries: None,
|
||||
}),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
@@ -483,6 +492,7 @@ fn parses_web_search_open_page_call() {
|
||||
action: Some(WebSearchAction::OpenPage {
|
||||
url: Some("https://example.com".to_string()),
|
||||
}),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
@@ -511,6 +521,7 @@ fn parses_web_search_find_in_page_call() {
|
||||
url: Some("https://example.com".to_string()),
|
||||
pattern: Some("needle".to_string()),
|
||||
}),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
@@ -537,6 +548,7 @@ fn parses_partial_web_search_call_without_action_as_other() {
|
||||
id: Some("ws_partial".to_string()),
|
||||
status: Some("in_progress".to_string()),
|
||||
action: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let turn_item = parse_turn_item(&item).expect("expected web search turn item");
|
||||
|
||||
@@ -298,6 +298,7 @@ async fn seed_guardian_parent_history(session: &Arc<Session>, turn: &Arc<TurnCon
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -305,12 +306,14 @@ async fn seed_guardian_parent_history(session: &Arc<Session>, turn: &Arc<TurnCon
|
||||
namespace: None,
|
||||
arguments: "{\"repo\":\"openai/codex\"}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: codex_protocol::models::FunctionCallOutputPayload::from_text(
|
||||
"repo visibility: public".to_string(),
|
||||
),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -320,6 +323,7 @@ async fn seed_guardian_parent_history(session: &Arc<Session>, turn: &Arc<TurnCon
|
||||
.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -526,6 +530,7 @@ async fn build_guardian_prompt_delta_mode_preserves_original_numbering() -> anyh
|
||||
text: "Please also push the second docs fix.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -534,6 +539,7 @@ async fn build_guardian_prompt_delta_mode_preserves_original_numbering() -> anyh
|
||||
text: "I need approval for the second push.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -656,6 +662,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "Compacted retained user request.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -664,6 +671,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "Compacted summary of earlier guardian context.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
/*reference_context_item*/ None,
|
||||
@@ -680,6 +688,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "Please push after the compaction.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -688,6 +697,7 @@ async fn build_guardian_prompt_stale_delta_version_falls_back_to_full_prompt() -
|
||||
text: "I need approval for the post-compaction push.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -735,6 +745,7 @@ fn collect_guardian_transcript_entries_skips_contextual_user_messages() {
|
||||
text: "<environment_context>\n<cwd>/tmp</cwd>\n</environment_context>".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -743,6 +754,7 @@ fn collect_guardian_transcript_entries_skips_contextual_user_messages() {
|
||||
text: "hello".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -770,6 +782,7 @@ fn collect_guardian_transcript_entries_keeps_manual_approval_developer_message()
|
||||
text: "ordinary developer context".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -778,6 +791,7 @@ fn collect_guardian_transcript_entries_keeps_manual_approval_developer_message()
|
||||
text: approval_text.clone(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -802,6 +816,7 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
|
||||
text: "check the repo".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -809,12 +824,14 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
|
||||
namespace: None,
|
||||
arguments: "{\"path\":\"README.md\"}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: codex_protocol::models::FunctionCallOutputPayload::from_text(
|
||||
"repo is public".to_string(),
|
||||
),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -823,6 +840,7 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
|
||||
text: "I need to push a fix".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1909,6 +1927,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "Please push the second docs fix too.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -1917,6 +1936,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "I need approval for the second docs fix.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -1954,6 +1974,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "Please push the third docs fix too.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -1962,6 +1983,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
text: "I need approval for the third docs fix.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
)
|
||||
@@ -2701,7 +2723,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "Please inspect pending changes before pushing.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "assistant".to_string(),
|
||||
@@ -2709,7 +2731,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "I need approval to run git diff.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
],
|
||||
)
|
||||
.await;
|
||||
@@ -2768,7 +2790,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "Now inspect whether pushing is safe.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "assistant".to_string(),
|
||||
@@ -2776,7 +2798,7 @@ async fn guardian_ephemeral_retry_preserves_parallel_trunk_and_fork_history() ->
|
||||
text: "I need approval to push after the diff check.".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
},
|
||||
metadata: None,},
|
||||
],
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -62,7 +62,7 @@ pub(crate) fn prepare_response_items(items: &mut [ResponseItem]) {
|
||||
| ResponseItem::WebSearchCall { .. }
|
||||
| ResponseItem::ImageGenerationCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::CompactionTrigger
|
||||
| ResponseItem::CompactionTrigger { .. }
|
||||
| ResponseItem::ContextCompaction { .. }
|
||||
| ResponseItem::Other => {}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ fn preparation_preserves_small_image_bytes_and_non_data_urls() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
|
||||
prepare_response_items(&mut items);
|
||||
@@ -85,6 +86,7 @@ fn detail_policies_apply_the_expected_budgets() {
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputImage { image_url, detail }],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}];
|
||||
|
||||
prepare_response_items(&mut items);
|
||||
@@ -130,6 +132,7 @@ fn preparation_replaces_only_failed_tool_images_and_preserves_metadata() {
|
||||
]),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: None,
|
||||
}];
|
||||
|
||||
prepare_response_items(&mut items);
|
||||
@@ -160,6 +163,7 @@ fn preparation_replaces_only_failed_tool_images_and_preserves_metadata() {
|
||||
]),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: None,
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ fn message(role: &str, content: ContentItem) -> ResponseItem {
|
||||
role: role.to_string(),
|
||||
content: vec![content],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@ use uuid::Uuid;
|
||||
|
||||
use crate::client::ModelClient;
|
||||
use crate::codex_thread::ThreadConfigSnapshot;
|
||||
#[cfg(test)]
|
||||
use crate::compact::collect_user_messages;
|
||||
use crate::config::Config;
|
||||
use crate::config::Constrained;
|
||||
|
||||
@@ -296,7 +296,7 @@ impl Session {
|
||||
// prompt shape.
|
||||
// TODO(ccunningham): if we drop support for None replacement_history compaction items,
|
||||
// we can get rid of this second loop entirely and just build `history` directly in the first loop.
|
||||
let user_messages = collect_user_messages(history.raw_items());
|
||||
let user_messages = compact::collect_user_messages(history.raw_items());
|
||||
let rebuilt = compact::build_compacted_history(
|
||||
Vec::new(),
|
||||
&user_messages,
|
||||
|
||||
@@ -20,6 +20,7 @@ fn user_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +32,7 @@ fn assistant_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +51,7 @@ fn inter_agent_assistant_message(text: &str) -> ResponseItem {
|
||||
text: serde_json::to_string(&communication).unwrap(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ use codex_protocol::config_types::Settings;
|
||||
use codex_protocol::models::BaseInstructions;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::models::ResponseItemMetadata;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::CodexErrorInfo;
|
||||
use codex_protocol::protocol::CompactedItem;
|
||||
@@ -189,6 +190,7 @@ fn user_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +202,7 @@ fn assistant_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +262,7 @@ fn skill_message(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1598,6 +1602,9 @@ async fn reconstruct_history_uses_replacement_history_verbatim() {
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: Some(ResponseItemMetadata {
|
||||
turn_id: Some("compact-turn".to_string()),
|
||||
}),
|
||||
};
|
||||
let replacement_history = vec![
|
||||
summary_item.clone(),
|
||||
@@ -1608,6 +1615,7 @@ async fn reconstruct_history_uses_replacement_history_verbatim() {
|
||||
text: "stale developer instructions".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
let rollout_items = vec![RolloutItem::Compacted(CompactedItem {
|
||||
@@ -1669,32 +1677,35 @@ async fn resize_all_images_prepares_failures_before_history_insertion() {
|
||||
]),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
session
|
||||
.record_conversation_items(turn_context.as_ref(), std::slice::from_ref(&item))
|
||||
.await;
|
||||
|
||||
let expected = vec![ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: FunctionCallOutputPayload {
|
||||
body: FunctionCallOutputBody::ContentItems(vec![
|
||||
FunctionCallOutputContentItem::InputText {
|
||||
text: "before".to_string(),
|
||||
},
|
||||
FunctionCallOutputContentItem::InputText {
|
||||
text: "image content omitted because it could not be processed".to_string(),
|
||||
},
|
||||
FunctionCallOutputContentItem::InputImage {
|
||||
image_url: "https://example.com/image.png".to_string(),
|
||||
detail: Some(ImageDetail::High),
|
||||
},
|
||||
]),
|
||||
success: Some(true),
|
||||
},
|
||||
metadata: None,
|
||||
}];
|
||||
assert_eq!(
|
||||
session.state.lock().await.clone_history().raw_items(),
|
||||
&[ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: FunctionCallOutputPayload {
|
||||
body: FunctionCallOutputBody::ContentItems(vec![
|
||||
FunctionCallOutputContentItem::InputText {
|
||||
text: "before".to_string(),
|
||||
},
|
||||
FunctionCallOutputContentItem::InputText {
|
||||
text: "image content omitted because it could not be processed".to_string(),
|
||||
},
|
||||
FunctionCallOutputContentItem::InputImage {
|
||||
image_url: "https://example.com/image.png".to_string(),
|
||||
detail: Some(ImageDetail::High),
|
||||
},
|
||||
]),
|
||||
success: Some(true),
|
||||
},
|
||||
}]
|
||||
expected.as_slice()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1721,6 +1732,7 @@ async fn resize_all_images_prepares_resumed_history_before_installing_it() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
session
|
||||
@@ -1745,6 +1757,7 @@ async fn resize_all_images_prepares_resumed_history_before_installing_it() {
|
||||
},
|
||||
],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}]
|
||||
);
|
||||
}
|
||||
@@ -1860,7 +1873,8 @@ async fn resumed_history_injects_initial_context_on_first_context_update_only()
|
||||
session
|
||||
.record_context_updates_and_set_reference_context_item(&turn_context)
|
||||
.await;
|
||||
expected.extend(session.build_initial_context(&turn_context).await);
|
||||
let initial_context = session.build_initial_context(&turn_context).await;
|
||||
expected.extend(initial_context);
|
||||
let history_after_seed = session.clone_history().await;
|
||||
assert_eq!(expected, history_after_seed.raw_items());
|
||||
|
||||
@@ -7662,6 +7676,7 @@ async fn build_initial_context_omits_default_image_save_location_with_image_hist
|
||||
status: "completed".to_string(),
|
||||
revised_prompt: Some("a tiny blue square".to_string()),
|
||||
result: "Zm9v".to_string(),
|
||||
metadata: None,
|
||||
}],
|
||||
/*reference_context_item*/ None,
|
||||
)
|
||||
@@ -7914,6 +7929,7 @@ async fn handle_output_item_done_records_image_save_history_message() {
|
||||
status: "completed".to_string(),
|
||||
revised_prompt: Some("a tiny blue square".to_string()),
|
||||
result: "Zm9v".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let mut ctx = HandleOutputCtx {
|
||||
@@ -7944,7 +7960,8 @@ async fn handle_output_item_done_records_image_save_history_message() {
|
||||
image_output_path.display(),
|
||||
),
|
||||
);
|
||||
assert_eq!(history.raw_items(), &[image_message, item]);
|
||||
let expected = vec![image_message, item];
|
||||
assert_eq!(history.raw_items(), expected.as_slice());
|
||||
assert_eq!(
|
||||
std::fs::read(&expected_saved_path).expect("saved file"),
|
||||
b"foo"
|
||||
@@ -7969,6 +7986,7 @@ async fn handle_output_item_done_skips_image_save_message_when_save_fails() {
|
||||
status: "completed".to_string(),
|
||||
revised_prompt: Some("broken payload".to_string()),
|
||||
result: "_-8".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let mut ctx = HandleOutputCtx {
|
||||
@@ -7985,7 +8003,8 @@ async fn handle_output_item_done_skips_image_save_message_when_save_fails() {
|
||||
.expect("image generation item should still complete");
|
||||
|
||||
let history = session.clone_history().await;
|
||||
assert_eq!(history.raw_items(), &[item]);
|
||||
let expected = vec![item];
|
||||
assert_eq!(history.raw_items(), expected.as_slice());
|
||||
assert!(!expected_saved_path.exists());
|
||||
}
|
||||
|
||||
@@ -8128,6 +8147,7 @@ async fn record_context_updates_and_set_reference_context_item_reinjects_full_co
|
||||
text: format!("{}\nsummary", crate::compact::SUMMARY_PREFIX),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
session
|
||||
.record_conversation_items(&turn_context, std::slice::from_ref(&compacted_summary))
|
||||
@@ -8152,7 +8172,8 @@ async fn record_context_updates_and_set_reference_context_item_reinjects_full_co
|
||||
|
||||
let history = session.clone_history().await;
|
||||
let mut expected_history = vec![compacted_summary];
|
||||
expected_history.extend(session.build_initial_context(&turn_context).await);
|
||||
let initial_context = session.build_initial_context(&turn_context).await;
|
||||
expected_history.extend(initial_context);
|
||||
assert_eq!(history.raw_items().to_vec(), expected_history);
|
||||
}
|
||||
|
||||
@@ -8725,6 +8746,7 @@ async fn task_finish_emits_turn_item_lifecycle_for_leftover_pending_user_input()
|
||||
text: "late pending input".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
assert!(
|
||||
history.raw_items().iter().any(|item| item == &expected),
|
||||
@@ -9157,6 +9179,7 @@ async fn abort_empty_active_turn_preserves_pending_input() {
|
||||
text: "late pending input".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
let turn_state = {
|
||||
let mut active = sess.active_turn.lock().await;
|
||||
@@ -9415,6 +9438,7 @@ async fn tool_calls_reopen_mailbox_delivery_for_current_turn() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
let mut ctx = HandleOutputCtx {
|
||||
sess: Arc::clone(&sess),
|
||||
@@ -9542,6 +9566,7 @@ async fn fatal_tool_error_stops_turn_and_reports_error() {
|
||||
call_id: "call-1".to_string(),
|
||||
name: "shell_command".to_string(),
|
||||
input: "{}".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
let call = ToolRouter::build_tool_call(item.clone())
|
||||
@@ -9626,6 +9651,7 @@ async fn sample_rollout(
|
||||
text: "first user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
live_history.record_items(
|
||||
std::iter::once(&user1),
|
||||
@@ -9640,6 +9666,7 @@ async fn sample_rollout(
|
||||
text: "assistant reply one".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant1),
|
||||
@@ -9667,6 +9694,7 @@ async fn sample_rollout(
|
||||
text: "second user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
live_history.record_items(
|
||||
std::iter::once(&user2),
|
||||
@@ -9681,6 +9709,7 @@ async fn sample_rollout(
|
||||
text: "assistant reply two".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant2),
|
||||
@@ -9708,6 +9737,7 @@ async fn sample_rollout(
|
||||
text: "third user".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
live_history.record_items(
|
||||
std::iter::once(&user3),
|
||||
@@ -9722,6 +9752,7 @@ async fn sample_rollout(
|
||||
text: "assistant reply three".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant3),
|
||||
@@ -9867,6 +9898,7 @@ while :; do sleep 1; done"#,
|
||||
})
|
||||
.to_string(),
|
||||
call_id: "shell-cleanup-call".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
let call = ToolRouter::build_tool_call(item)?
|
||||
.expect("shell command response item should build a tool call");
|
||||
|
||||
@@ -536,6 +536,7 @@ async fn process_compacted_history_preserves_separate_guardian_developer_message
|
||||
text: "stale developer message".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -544,6 +545,7 @@ async fn process_compacted_history_preserves_separate_guardian_developer_message
|
||||
text: "summary".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
],
|
||||
InitialContextInjection::BeforeLastUserMessage,
|
||||
|
||||
@@ -1978,7 +1978,7 @@ async fn try_run_sampling_request(
|
||||
| ResponseItem::WebSearchCall { .. }
|
||||
| ResponseItem::ImageGenerationCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::CompactionTrigger
|
||||
| ResponseItem::CompactionTrigger { .. }
|
||||
| ResponseItem::ContextCompaction { .. }
|
||||
| ResponseItem::Other => false,
|
||||
};
|
||||
|
||||
@@ -33,6 +33,7 @@ fn assistant_output_text(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -626,6 +626,7 @@ pub(crate) fn response_input_to_response_item(input: &ResponseInputItem) -> Opti
|
||||
Some(ResponseItem::FunctionCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
output: output.clone(),
|
||||
metadata: None,
|
||||
})
|
||||
}
|
||||
ResponseInputItem::CustomToolCallOutput {
|
||||
@@ -636,12 +637,14 @@ pub(crate) fn response_input_to_response_item(input: &ResponseInputItem) -> Opti
|
||||
call_id: call_id.clone(),
|
||||
name: name.clone(),
|
||||
output: output.clone(),
|
||||
metadata: None,
|
||||
}),
|
||||
ResponseInputItem::McpToolCallOutput { call_id, output } => {
|
||||
let output = output.as_function_call_output_payload();
|
||||
Some(ResponseItem::FunctionCallOutput {
|
||||
call_id: call_id.clone(),
|
||||
output,
|
||||
metadata: None,
|
||||
})
|
||||
}
|
||||
ResponseInputItem::ToolSearchOutput {
|
||||
@@ -654,6 +657,7 @@ pub(crate) fn response_input_to_response_item(input: &ResponseInputItem) -> Opti
|
||||
status: status.clone(),
|
||||
execution: execution.clone(),
|
||||
tools: tools.clone(),
|
||||
metadata: None,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ fn assistant_output_text_with_phase(text: &str, phase: Option<MessagePhase>) ->
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +53,7 @@ fn external_context_pollution_items_include_web_search_and_tool_search() {
|
||||
id: None,
|
||||
status: Some("completed".to_string()),
|
||||
action: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::ToolSearchCall {
|
||||
id: None,
|
||||
@@ -59,12 +61,14 @@ fn external_context_pollution_items_include_web_search_and_tool_search() {
|
||||
status: None,
|
||||
execution: "client".to_string(),
|
||||
arguments: serde_json::json!({"query": "calendar"}),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::ToolSearchOutput {
|
||||
call_id: Some("search-1".to_string()),
|
||||
status: "completed".to_string(),
|
||||
execution: "client".to_string(),
|
||||
tools: Vec::new(),
|
||||
metadata: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -89,6 +93,7 @@ fn external_context_pollution_items_exclude_local_tool_calls() {
|
||||
env: None,
|
||||
user: None,
|
||||
}),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -96,10 +101,12 @@ fn external_context_pollution_items_exclude_local_tool_calls() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCall {
|
||||
id: None,
|
||||
@@ -107,11 +114,13 @@ fn external_context_pollution_items_exclude_local_tool_calls() {
|
||||
call_id: "custom-1".to_string(),
|
||||
name: "apply_patch".to_string(),
|
||||
input: "*** Begin Patch\n*** End Patch\n".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::CustomToolCallOutput {
|
||||
call_id: "custom-1".to_string(),
|
||||
name: Some("apply_patch".to_string()),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
},
|
||||
assistant_output_text("plain assistant text"),
|
||||
];
|
||||
@@ -413,6 +422,7 @@ fn completed_item_defers_mailbox_delivery_for_image_generation_calls() {
|
||||
status: "completed".to_string(),
|
||||
revised_prompt: None,
|
||||
result: "Zm9v".to_string(),
|
||||
metadata: None,
|
||||
};
|
||||
|
||||
assert!(completed_item_defers_mailbox_delivery_to_next_turn(
|
||||
|
||||
@@ -109,6 +109,7 @@ pub(crate) fn interrupted_turn_history_marker(
|
||||
text: marker.render(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +247,7 @@ pub(crate) async fn exit_review_mode(
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText { text: user_message }],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}],
|
||||
)
|
||||
.await;
|
||||
@@ -267,6 +268,7 @@ pub(crate) async fn exit_review_mode(
|
||||
text: assistant_message,
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -42,6 +42,7 @@ fn user_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
fn assistant_msg(text: &str) -> ResponseItem {
|
||||
@@ -52,6 +53,7 @@ fn assistant_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +82,7 @@ fn truncates_before_requested_user_message() {
|
||||
}],
|
||||
content: None,
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -87,6 +90,7 @@ fn truncates_before_requested_user_message() {
|
||||
name: "tool".to_string(),
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
assistant_msg("a4"),
|
||||
];
|
||||
|
||||
@@ -15,6 +15,7 @@ fn user_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +27,7 @@ fn assistant_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +39,7 @@ fn developer_msg(text: &str) -> ResponseItem {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +79,7 @@ fn truncates_rollout_from_start_before_nth_user_only() {
|
||||
}],
|
||||
content: None,
|
||||
encrypted_content: None,
|
||||
metadata: None,
|
||||
},
|
||||
ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
@@ -83,6 +87,7 @@ fn truncates_rollout_from_start_before_nth_user_only() {
|
||||
name: "tool".to_string(),
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
metadata: None,
|
||||
},
|
||||
assistant_msg("a4"),
|
||||
];
|
||||
|
||||
@@ -302,6 +302,7 @@ impl CoreTurnHost {
|
||||
call_id,
|
||||
name: Some(PUBLIC_TOOL_NAME.to_string()),
|
||||
output: FunctionCallOutputPayload::from_text(text),
|
||||
metadata: None,
|
||||
}])
|
||||
.await
|
||||
.map_err(|_| {
|
||||
|
||||
@@ -324,6 +324,7 @@ mod tests {
|
||||
text: "extension history".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
session
|
||||
.record_conversation_items(&turn, std::slice::from_ref(&history_item))
|
||||
|
||||
@@ -2797,6 +2797,7 @@ async fn resume_agent_restores_closed_agent_and_accepts_send_input() {
|
||||
text: "materialized".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
})]),
|
||||
AuthManager::from_auth_for_testing(CodexAuth::from_api_key("dummy")),
|
||||
/*parent_trace*/ None,
|
||||
|
||||
@@ -157,6 +157,7 @@ async fn build_tool_call_uses_namespace_for_registry_name() -> anyhow::Result<()
|
||||
namespace: Some("mcp__codex_apps__calendar".to_string()),
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-namespace".to_string(),
|
||||
metadata: None,
|
||||
})?
|
||||
.expect("function_call should produce a tool call");
|
||||
|
||||
@@ -339,6 +340,7 @@ async fn extension_tool_executors_are_model_visible_and_dispatchable() -> anyhow
|
||||
text: "extension history".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
};
|
||||
session
|
||||
.record_conversation_items(&turn, std::slice::from_ref(&history_item))
|
||||
@@ -374,6 +376,7 @@ async fn extension_tool_executors_are_model_visible_and_dispatchable() -> anyhow
|
||||
namespace: Some("extension/".to_string()),
|
||||
arguments: json!({ "message": "hello" }).to_string(),
|
||||
call_id: "call-extension".to_string(),
|
||||
metadata: None,
|
||||
})?
|
||||
.expect("function_call should produce a tool call");
|
||||
let result = router
|
||||
|
||||
@@ -378,7 +378,7 @@ fn response_item_records_turn_ttft(item: &ResponseItem) -> bool {
|
||||
| ResponseItem::ImageGenerationCall { .. }
|
||||
| ResponseItem::Compaction { .. }
|
||||
| ResponseItem::ContextCompaction { .. } => true,
|
||||
ResponseItem::CompactionTrigger => false,
|
||||
ResponseItem::CompactionTrigger { .. } => false,
|
||||
ResponseItem::FunctionCallOutput { .. }
|
||||
| ResponseItem::CustomToolCallOutput { .. }
|
||||
| ResponseItem::ToolSearchOutput { .. }
|
||||
|
||||
@@ -112,6 +112,7 @@ fn response_item_records_turn_ttft_for_first_output_signals() {
|
||||
namespace: None,
|
||||
arguments: "{}".to_string(),
|
||||
call_id: "call-1".to_string(),
|
||||
metadata: None,
|
||||
}
|
||||
));
|
||||
assert!(response_item_records_turn_ttft(
|
||||
@@ -121,6 +122,7 @@ fn response_item_records_turn_ttft_for_first_output_signals() {
|
||||
call_id: "call-2".to_string(),
|
||||
name: "custom".to_string(),
|
||||
input: "echo hi".to_string(),
|
||||
metadata: None,
|
||||
}
|
||||
));
|
||||
assert!(response_item_records_turn_ttft(&ResponseItem::Message {
|
||||
@@ -130,6 +132,7 @@ fn response_item_records_turn_ttft_for_first_output_signals() {
|
||||
text: "hello".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -142,11 +145,13 @@ fn response_item_records_turn_ttft_ignores_empty_non_output_items() {
|
||||
text: String::new(),
|
||||
}],
|
||||
phase: None,
|
||||
metadata: None,
|
||||
}));
|
||||
assert!(!response_item_records_turn_ttft(
|
||||
&ResponseItem::FunctionCallOutput {
|
||||
call_id: "call-1".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("ok".to_string()),
|
||||
metadata: None,
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user