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
@@ -314,7 +314,7 @@ struct WebsocketSession {
|
||||
}
|
||||
|
||||
// This is intentionally not a `PartialEq` implementation: request equality includes `input` and
|
||||
// `client_metadata`, while websocket reuse compares the input separately and ignores metadata.
|
||||
// `client_metadata`, while websocket reuse compares input and late tool-result metadata separately.
|
||||
// Access programs are authorized per response, including continuations, without replaying input.
|
||||
// Keep the destructuring exhaustive so new request fields require an explicit reuse decision.
|
||||
fn responses_request_properties_match(
|
||||
@@ -382,6 +382,11 @@ fn response_items_equal_ignoring_internal_metadata(
|
||||
return true;
|
||||
}
|
||||
|
||||
// Late results update an already-sent output. A delta cannot carry that update.
|
||||
if !previous.has_same_tool_result_metadata(current) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut previous = previous.clone();
|
||||
previous.clear_internal_chat_message_metadata_passthrough();
|
||||
let mut current = current.clone();
|
||||
|
||||
@@ -541,6 +541,121 @@ fn responses_request_limits_raw_tool_metadata_to_resolved_first_party_https_endp
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn websocket_incremental_reuse_tracks_raw_result_metadata() -> anyhow::Result<()> {
|
||||
let provider =
|
||||
ModelProviderInfo::create_openai_provider(Some("https://api.openai.com/v1".to_string()));
|
||||
let mut api_provider = provider.to_api_provider(/*auth_mode*/ None)?;
|
||||
let mut client = test_model_client(SessionSource::Cli);
|
||||
Arc::get_mut(&mut client.state)
|
||||
.expect("test client should have unique session state")
|
||||
.provider = create_model_provider(provider, /*auth_manager*/ None);
|
||||
let responses_metadata = test_responses_metadata_for_client(
|
||||
&client,
|
||||
/*turn_id*/ None,
|
||||
format!("{}:0", client.state.thread_id),
|
||||
/*parent_thread_id*/ None,
|
||||
TestCodexResponsesRequestKind::Turn,
|
||||
);
|
||||
for (scenario, base_url, previous_metadata, current_metadata, expect_incremental) in [
|
||||
(
|
||||
"late_result",
|
||||
"https://api.openai.com/v1",
|
||||
None,
|
||||
Some("first"),
|
||||
false,
|
||||
),
|
||||
(
|
||||
"unchanged_result",
|
||||
"https://api.openai.com/v1",
|
||||
Some("first"),
|
||||
Some("first"),
|
||||
true,
|
||||
),
|
||||
(
|
||||
"changed_result",
|
||||
"https://api.openai.com/v1",
|
||||
Some("first"),
|
||||
Some("second"),
|
||||
false,
|
||||
),
|
||||
(
|
||||
"ordinary_metadata_only",
|
||||
"https://api.openai.com/v1",
|
||||
None,
|
||||
None,
|
||||
true,
|
||||
),
|
||||
(
|
||||
"filtered_result",
|
||||
"https://proxy.example.com/v1",
|
||||
None,
|
||||
Some("first"),
|
||||
true,
|
||||
),
|
||||
] {
|
||||
let [mut previous_output, mut current_output] =
|
||||
[previous_metadata, current_metadata].map(|metadata| {
|
||||
let mut call =
|
||||
ExecutedToolCall::new("apps_tool".to_string(), json!({ "query": "same" }));
|
||||
if let Some(id) = metadata {
|
||||
call.set_tool_result_metadata(ToolResultMetadata::new(&json!({ "id": id })));
|
||||
}
|
||||
let mut output = ResponseItem::from(ResponseInputItem::CustomToolCallOutput {
|
||||
call_id: "exec-call".to_string(),
|
||||
name: None,
|
||||
output: FunctionCallOutputPayload::from_text(
|
||||
"Script running with cell ID cell".to_string(),
|
||||
),
|
||||
});
|
||||
output.append_executed_tool_calls(vec![call]);
|
||||
output.set_tool_call_cell_id("exec-call");
|
||||
output
|
||||
});
|
||||
previous_output.set_turn_id_if_missing("previous-turn");
|
||||
current_output.set_turn_id_if_missing("current-turn");
|
||||
let mut previous = client.build_responses_request(
|
||||
&Prompt {
|
||||
input: vec![previous_output],
|
||||
..Default::default()
|
||||
},
|
||||
&test_model_info(),
|
||||
/*effort*/ None,
|
||||
codex_protocol::config_types::ReasoningSummary::None,
|
||||
/*service_tier*/ None,
|
||||
&responses_metadata,
|
||||
)?;
|
||||
let follow_up = ResponseItem::from(ResponseInputItem::FunctionCallOutput {
|
||||
call_id: "wait-call".to_string(),
|
||||
output: FunctionCallOutputPayload::from_text("done".to_string()),
|
||||
});
|
||||
let mut current = previous.clone();
|
||||
current.input = vec![current_output, follow_up.clone()];
|
||||
api_provider.base_url = base_url.to_string();
|
||||
ModelClient::filter_tool_result_metadata(&mut previous.input, &api_provider);
|
||||
ModelClient::filter_tool_result_metadata(&mut current.input, &api_provider);
|
||||
|
||||
let mut session = client.new_session();
|
||||
session.websocket_session.last_request = Some(previous);
|
||||
let (sender, receiver) = tokio::sync::oneshot::channel();
|
||||
sender
|
||||
.send(super::LastResponse {
|
||||
response_id: "previous-response".to_string(),
|
||||
items_added: Vec::new(),
|
||||
})
|
||||
.unwrap();
|
||||
session.websocket_session.last_response_rx = Some(receiver);
|
||||
let (incremental, from_warmup) = session.prepare_websocket_request(¤t);
|
||||
assert_eq!(
|
||||
incremental,
|
||||
expect_incremental.then_some(("previous-response".to_string(), vec![follow_up])),
|
||||
"{scenario}",
|
||||
);
|
||||
assert!(!from_warmup);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn responses_http_omits_raw_tool_metadata_for_openai_named_custom_endpoint()
|
||||
-> anyhow::Result<()> {
|
||||
|
||||
@@ -185,8 +185,14 @@ impl McpHandler {
|
||||
)
|
||||
.await;
|
||||
// Use the executed call's binding; a later catalog refresh must not change eligibility.
|
||||
// Only the new metadata is internal; tool execution and call accounting are not.
|
||||
let result_metadata_capture_allowed = false;
|
||||
let result_metadata_capture_allowed = invocation
|
||||
.session
|
||||
.services
|
||||
.analytics_events_client
|
||||
.is_enabled()
|
||||
&& prepared_mcp_call
|
||||
.as_ref()
|
||||
.is_some_and(codex_mcp::PreparedMcpCall::is_host_owned_apps);
|
||||
let mcp_tool = prepared_mcp_call.as_ref().map(|call| {
|
||||
McpToolContext::from_prepared_call(
|
||||
call,
|
||||
|
||||
Reference in new issue
Block a user