mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Enable app tool result metadata with analytics controls (#46010)
## What changed Capture result metadata for host-owned app calls when analytics and executed tool call metadata recording are enabled. Respect both `analytics.enabled = false` and host-disabled analytics, using the prepared call's ownership to determine eligibility. Disable incremental WebSocket request reuse when raw result metadata or its call binding changes, so late results attached to an already-sent output are included in the next request. Continue allowing reuse when only other metadata changes or result metadata is filtered out for the endpoint. ## Testing Extend coverage for direct and code-mode calls, analytics settings and host overrides, runtime recording changes, and prepared call ownership. Add metadata comparison and WebSocket reuse tests, and verify that raw response item notifications continue to omit result metadata. GitOrigin-RevId: 411843fbff3749ee96fd6f0ebc591362942a4555
This commit is contained in:
1 parent
7f0ab95827
commit
3a589370a4
7 files changed
+276
-28
No files matched your search
@@ -485,6 +485,31 @@ impl ResponseItem {
|
||||
self.internal_chat_message_metadata_passthrough()
|
||||
}
|
||||
|
||||
/// Compares raw result metadata and its call bindings, ignoring other internal metadata.
|
||||
pub fn has_same_tool_result_metadata(&self, other: &Self) -> bool {
|
||||
fn result_metadata(
|
||||
item: &ResponseItem,
|
||||
) -> impl Iterator<Item = (usize, &str, &ExecutedToolCallArguments, &ToolResultMetadata)>
|
||||
{
|
||||
item.executed_tool_call_metadata()
|
||||
.and_then(|metadata| metadata.executed_tool_calls.as_ref())
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.enumerate()
|
||||
.filter(|(_, call)| call.tool_result_metadata.is_some())
|
||||
.map(|(index, call)| {
|
||||
(
|
||||
index,
|
||||
call.name.as_str(),
|
||||
call.arguments(),
|
||||
&call.tool_result_metadata,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
result_metadata(self).eq(result_metadata(other))
|
||||
}
|
||||
|
||||
/// Omits raw tool results without changing existing call, source or completion metadata.
|
||||
pub fn clear_tool_result_metadata(&mut self) {
|
||||
if let Some(metadata) = self
|
||||
|
||||
@@ -26,6 +26,67 @@ fn first_executed_tool_call(item: &mut ResponseItem) -> Option<&mut ExecutedTool
|
||||
.and_then(|calls| calls.first_mut())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn result_metadata_comparison_tracks_raw_values_and_call_bindings() {
|
||||
let empty = output("output");
|
||||
let mut without_metadata = empty.clone();
|
||||
without_metadata.append_executed_tool_calls(vec![ExecutedToolCall::new(
|
||||
"apps_tool".to_string(),
|
||||
serde_json::json!({ "query": "same" }),
|
||||
)]);
|
||||
assert!(empty.has_same_tool_result_metadata(&without_metadata));
|
||||
|
||||
let mut with_metadata = without_metadata.clone();
|
||||
first_executed_tool_call(&mut with_metadata)
|
||||
.unwrap()
|
||||
.set_tool_result_metadata(ToolResultMetadata::new(
|
||||
&serde_json::json!({ "id": "first" }),
|
||||
));
|
||||
assert!(!without_metadata.has_same_tool_result_metadata(&with_metadata));
|
||||
assert!(!with_metadata.has_same_tool_result_metadata(&without_metadata));
|
||||
assert!(with_metadata.has_same_tool_result_metadata(&with_metadata.clone()));
|
||||
|
||||
let mut changed = with_metadata.clone();
|
||||
first_executed_tool_call(&mut changed)
|
||||
.unwrap()
|
||||
.set_tool_result_metadata(ToolResultMetadata::new(
|
||||
&serde_json::json!({ "id": "second" }),
|
||||
));
|
||||
assert!(!with_metadata.has_same_tool_result_metadata(&changed));
|
||||
changed.clear_tool_result_metadata();
|
||||
assert!(without_metadata.has_same_tool_result_metadata(&changed));
|
||||
|
||||
let mut ordinary_metadata = with_metadata.clone();
|
||||
ordinary_metadata.set_turn_id_if_missing("other-turn");
|
||||
ordinary_metadata.set_tool_call_cell_id("other-cell");
|
||||
ordinary_metadata.mark_tool_calls_complete();
|
||||
first_executed_tool_call(&mut ordinary_metadata)
|
||||
.unwrap()
|
||||
.set_tool_result_sources(ToolResultSources::new(vec![ToolResultSource {
|
||||
r#type: "resource".to_string(),
|
||||
id: "source".to_string(),
|
||||
}]));
|
||||
assert!(with_metadata.has_same_tool_result_metadata(&ordinary_metadata));
|
||||
|
||||
let mut different_call = with_metadata.clone();
|
||||
first_executed_tool_call(&mut different_call).unwrap().name = "other_tool".to_string();
|
||||
assert!(!with_metadata.has_same_tool_result_metadata(&different_call));
|
||||
first_executed_tool_call(&mut different_call).unwrap().name = "apps_tool".to_string();
|
||||
different_call
|
||||
.internal_chat_message_metadata_passthrough_mut()
|
||||
.unwrap()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.executed_tool_calls
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.insert(
|
||||
0,
|
||||
ExecutedToolCall::new("other_tool".to_string(), serde_json::json!({})),
|
||||
);
|
||||
assert!(!with_metadata.has_same_tool_result_metadata(&different_call));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn executed_tool_call_prompt_budget_includes_metadata_fields() -> Result<()> {
|
||||
let metadata_bytes = |items: &[ResponseItem]| -> Result<usize> {
|
||||
|
||||
Reference in new issue
Block a user