Preserve large arguments in executed tool call metadata (#52268)

## Why

Fixed argument limits truncated recorded tool calls even when their metadata fit within the available message budget.

## What changed

- Remove the 8 KiB per-call and 32 KiB per-output argument limits for direct calls and Code Mode.
- Preserve full recorded arguments while retaining message metadata budgets, pending-call limits, and the direct metadata retention limit.
- Rename the normalization helper to `normalize_executed_tool_call_completeness`; it now only clears completeness when calls or tool names were lost.

## Testing

Update regression coverage for large arguments, escaped inputs, reserved-key wrappers, and argument and result metadata preservation across Code Mode waits.

GitOrigin-RevId: 8c199ccf39191d5d44eef02d28b1773654735b43
This commit is contained in:
ningyi-oai
2026-10-08 20:40:47 +00:00
committed by copyberry
parent 3b6ab3471a
commit 515c291d87
10 changed files with 97 additions and 168 deletions
+27 -24
View File
@@ -1548,7 +1548,7 @@ async fn code_mode_tool_call_completeness_is_private_and_opt_in(
let code = if oversized {
r#"
const args = { barrier: { id: "", participants: 1 } };
args.barrier.id = "x".repeat(8192 - JSON.stringify(args).length);
args.barrier.id = "x".repeat(9000 - JSON.stringify(args).length);
for (let index = 0; index < 17; index++) await tools.test_sync_tool(args);
text("done");
yield_control();
@@ -1577,12 +1577,17 @@ await new Promise(() => {});
let calls = serde_json::json!([{ "name": "test_sync_tool", "arguments": {} }]);
let complete = Value::Bool(true);
if oversized {
assert!(
metadata["executed_tool_calls"]
.as_array()
.is_some_and(|calls| calls.iter().any(|call| call["arguments"]
.get("_codex_executed_tool_call_truncated")
.is_some()))
let mut arguments = serde_json::json!({ "barrier": { "id": "", "participants": 1 } });
arguments["barrier"]["id"] =
serde_json::json!("x".repeat(9000 - arguments.to_string().len()));
assert_eq!(
metadata["executed_tool_calls"],
serde_json::json!(vec![
serde_json::json!({
"name": "test_sync_tool", "arguments": arguments,
});
17
]),
);
} else {
assert_eq!(
@@ -2976,7 +2981,7 @@ async fn code_mode_result_metadata_keeps_prepared_call_binding_across_runtime_re
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn code_mode_late_truncated_result_metadata_survives_waits() -> Result<()> {
async fn code_mode_late_result_metadata_with_large_arguments_survives_waits() -> Result<()> {
skip_if_no_network!(Ok(()));
let server = responses::start_mock_server().await;
let metadata = serde_json::json!({
@@ -3028,7 +3033,7 @@ async fn code_mode_late_truncated_result_metadata_survives_waits() -> Result<()>
.context("first call did not reach the result gate")??;
// The call may be dispatched after the first yield. Wait while its result is held so
// the request has already recorded the truncated call before accepting its metadata.
// the request has already recorded the call before accepting its metadata.
let held = responses::mount_function_call_agent_response(
&server,
"call-2",
@@ -3044,16 +3049,16 @@ async fn code_mode_late_truncated_result_metadata_survives_waits() -> Result<()>
let original_output = held_calls[0];
let original_id = original_output["call_id"].as_str().unwrap().to_string();
let original_type = original_output["type"].as_str().unwrap().to_string();
let truncated =
let recorded =
&original_output["internal_chat_message_metadata_passthrough"]["executed_tool_calls"][0];
assert!(
truncated["name"]
recorded["name"]
.as_str()
.unwrap()
.ends_with(RESULT_METADATA_TOOL)
);
assert!(truncated["arguments"]["_codex_executed_tool_call_truncated"].is_object());
assert!(truncated.get("tool_result_metadata").is_none());
assert_eq!(recorded["arguments"], arguments);
assert!(recorded.get("tool_result_metadata").is_none());
release_tx.send(()).unwrap();
let resumed = responses::mount_function_call_agent_response(
@@ -3096,7 +3101,7 @@ async fn code_mode_late_truncated_result_metadata_survives_waits() -> Result<()>
let captured_calls =
&captured_output["internal_chat_message_metadata_passthrough"]["executed_tool_calls"];
assert_eq!(captured_calls.as_array().unwrap().len(), 1);
assert_eq!(captured_calls[0]["arguments"], truncated["arguments"]);
assert_eq!(captured_calls[0]["arguments"], recorded["arguments"]);
assert_eq!(captured_calls[0]["tool_result_metadata"], metadata);
assert_ne!(
captured_output["internal_chat_message_metadata_passthrough"]["tool_calls_complete"],
@@ -3124,7 +3129,7 @@ async fn code_mode_late_truncated_result_metadata_survives_waits() -> Result<()>
let original = terminal_request.call_output(&original_id, &original_type);
assert_eq!(
original["internal_chat_message_metadata_passthrough"]["executed_tool_calls"][0]["arguments"],
truncated["arguments"]
recorded["arguments"]
);
assert!(
original["internal_chat_message_metadata_passthrough"]["executed_tool_calls"][0]
@@ -3548,7 +3553,7 @@ text("pressure ready");"#,
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn code_mode_complete_call_survives_unrelated_truncation() -> Result<()> {
async fn code_mode_complete_calls_preserve_large_arguments() -> Result<()> {
skip_if_no_network!(Ok(()));
let server = responses::start_mock_server().await;
@@ -3589,12 +3594,11 @@ async fn code_mode_complete_call_survives_unrelated_truncation() -> Result<()> {
let request = follow_up.single_request();
let overflow =
&request.custom_tool_call_output("call-1")["internal_chat_message_metadata_passthrough"];
assert!(
overflow["executed_tool_calls"]
.as_array()
.is_some_and(|calls| calls.iter().any(|call| call["arguments"]
.get("_codex_executed_tool_call_truncated")
.is_some()))
assert_eq!(
overflow["executed_tool_calls"],
serde_json::json!([{ "name": "test_sync_tool", "arguments": {
"barrier": { "id": "x".repeat(8192), "participants": 1 }
} }]),
);
assert_eq!(overflow["tool_calls_complete"], true);
@@ -9278,8 +9282,7 @@ async fn code_mode_argument_truncation_preserves_later_wait_completeness() -> Re
probe.codex.shutdown_and_wait().await?;
probe_server.shutdown().await;
// One 7 KiB invocation stays under the recorder's per-output argument
// budget. It pushes the yielded delta over the message budget only.
// One 7 KiB invocation pushes the yielded delta over the message budget.
let padding = "x".repeat(LIMIT - base_bytes - 4 * 1024);
let code = r#"
await tools.test_sync_tool({ barrier: { id: "x".repeat(7000), participants: 1 } });
@@ -538,6 +538,8 @@ async fn direct_function_and_tool_search_mark_complete_attempts(
// These calls exceed the old request budget but stay below Direct's retained-history limit.
let budget_arguments =
json!({"plan": [{"step": "x".repeat(7 * 1024), "status": "in_progress"}]});
let oversized_arguments =
json!({"plan": [{"step": "x".repeat(9 * 1024), "status": "in_progress"}]});
let budget_arguments_json = budget_arguments.to_string();
assert!(budget_arguments_json.len() < 8 * 1024);
if budget_calls > 0 {
@@ -549,7 +551,7 @@ async fn direct_function_and_tool_search_mark_complete_attempts(
events.push(ev_function_call(
"plan-oversized",
"update_plan",
&json!({"plan": [{"step": "x".repeat(9 * 1024), "status": "in_progress"}]}).to_string(),
&oversized_arguments.to_string(),
));
}
for index in 0..budget_calls {
@@ -625,12 +627,13 @@ async fn direct_function_and_tool_search_mark_complete_attempts(
assert_eq!(output["output"], json!("Plan updated"));
let metadata = tool_call_metadata(output);
metadata_bytes += serde_json::to_vec(&metadata)?.len();
assert!(
metadata["executed_tool_calls"][0]["arguments"]
.get("_codex_executed_tool_call_truncated")
.is_some()
assert_eq!(
metadata,
json!({
"executed_tool_calls": [{"name": "update_plan", "arguments": oversized_arguments}],
"tool_calls_complete": true,
}),
);
assert_eq!(metadata["tool_calls_complete"], true);
}
for index in 0..budget_calls {
let output = request.function_call_output(&format!("plan-budget-{index}"));
+1 -6
View File
@@ -527,12 +527,7 @@ async fn namespaced_custom_tool_call_preserves_namespace_through_dispatch_and_re
);
let expected_escaped_calls = json!([{
"name": format!("{namespace}__{tool_name}"),
"arguments": {
"_codex_executed_tool_call_truncated": {
"original_bytes": serde_json::to_vec(&escaped_input)?.len(),
"max_bytes": 8 * 1024,
},
},
"arguments": escaped_input,
}]);
assert_eq!(
tool_call_metadata(escaped_request.custom_tool_call_output(escaped_call_id)),