mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
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
This commit is contained in:
@@ -26,6 +26,10 @@ use std::task::Poll;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "common_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
pub const WS_REQUEST_HEADER_TRACEPARENT_CLIENT_METADATA_KEY: &str = "ws_request_header_traceparent";
|
||||
pub const WS_REQUEST_HEADER_TRACESTATE_CLIENT_METADATA_KEY: &str = "ws_request_header_tracestate";
|
||||
|
||||
@@ -81,12 +85,22 @@ pub(crate) fn with_tool_results(
|
||||
return None;
|
||||
}
|
||||
const FIELD: &str = r#","tool_result":"#;
|
||||
let Some(next_remaining) = remaining.checked_sub(FIELD.len() + body.compact_bytes()) else {
|
||||
const CALL_ID_FIELD: &str = r#","tool_result_call_id":"#;
|
||||
let call_id_field_bytes = body
|
||||
.nested_call_id_json()
|
||||
.map_or(0, |_| CALL_ID_FIELD.len());
|
||||
let Some(next_remaining) =
|
||||
remaining.checked_sub(FIELD.len() + body.compact_bytes() + call_id_field_bytes)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
enriched.push_str(&json[cursor..close]);
|
||||
enriched.push_str(FIELD);
|
||||
enriched.push_str(body.as_json());
|
||||
if let Some(id) = body.nested_call_id_json() {
|
||||
enriched.push_str(CALL_ID_FIELD);
|
||||
enriched.push_str(id);
|
||||
}
|
||||
cursor = close;
|
||||
remaining = next_remaining;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user