Files
codex/codex-rs/codex-api/src/common_tests.rs
T
ssetty-oai b5d9f7116e Include nested Apps tool results in Code Mode sampling requests (#62423)
## Why

Result body capture covered direct Apps calls, leaving eligible calls made inside Code Mode without their result bodies in follow-up sampling metadata.

## What changed

Capture eligible nested MCP results and bind them to the originating `exec` or `wait` output for the current turn. Send `tool_result` and `tool_result_call_id` together when both fit the request budget. Keep the bodies out of conversation history and reclaim capture capacity when the output binding is lost.

Require analytics to be enabled and the provider to allow request metadata before starting turn-level capture. Check the call's credentials at dispatch and again when recording the result.

## Testing

Add coverage for yielded and finished outputs, late results, retries with replacement output items, capture budget recovery, and the request size boundary for sending the body and call ID together.

GitOrigin-RevId: 0983261ac39021099d14efa5c9a9acac47ac9269
2026-11-19 03:58:29 +00:00

41 lines
1.6 KiB
Rust

//! Checks that private nested call IDs and their results share the wire budget.
#![cfg(test)]
use super::MAX_RESPONSE_MESSAGE_BYTES;
use super::with_tool_results;
use codex_protocol::models::ToolResultBody;
use pretty_assertions::assert_eq;
use serde_json::Value;
use serde_json::json;
use std::sync::Arc;
#[test]
fn nested_call_id_and_result_fit_the_wire_budget_together() {
let call_id = "private-\"id\\\nλ";
let result = json!({"content": [{"type": "text", "text": "private result"}]});
let mcp_result = serde_json::from_value(result.clone()).unwrap();
let mut body = ToolResultBody::from_mcp_result(&mcp_result).unwrap();
body.set_nested_call_id(call_id);
assert!(!format!("{body:?}").contains("private"));
let bodies = [(0, 0, Arc::new(body))];
let mut request = json!({"input": [{"internal_chat_message_metadata_passthrough": {
"executed_tool_calls": [{"name": "search", "arguments": {}}]
}}]})
.to_string();
let enriched = with_tool_results(&request, &bodies).unwrap();
let wire: Value = serde_json::from_str(&enriched).unwrap();
assert_eq!(
wire["input"][0]["internal_chat_message_metadata_passthrough"]["executed_tool_calls"][0],
json!({"name": "search", "arguments": {}, "tool_result": result, "tool_result_call_id": call_id})
);
request.push_str(&" ".repeat(MAX_RESPONSE_MESSAGE_BYTES - enriched.len()));
assert_eq!(
with_tool_results(&request, &bodies).unwrap().len(),
MAX_RESPONSE_MESSAGE_BYTES
);
request.push(' ');
assert!(with_tool_results(&request, &bodies).is_none());
}