mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
## What changed Allow callers to attach eligible Apps tool results as `tool_result` on selected executed tool calls in Responses HTTP and WebSocket requests. Keep text content and optional object-valued `structuredContent`, with a 1 MiB per-result limit and a 15 MiB budget for the enriched message. Attach results after request observers receive the original JSON. Keep result IDs local and suppress WebSocket payload tracing for enriched frames. Preserve the enriched HTTP body on retries to the original endpoint and retry with the original JSON on HTTP 307 and 308 redirects. Codex's default request construction supplies no result bodies. ## Testing Add coverage for result eligibility and size limits, HTTP retry and redirect behavior, and TLS fallback without forwarding the enriched body to a redirect destination. GitOrigin-RevId: c3f2f86f31349e40fcb699d48637c3cbbbe38837
45 lines
1.7 KiB
Rust
45 lines
1.7 KiB
Rust
//! Bounds optional tool observations using the actual outgoing Responses message.
|
|
//! Only the wire copy changes; model-visible input and WebSocket continuation history stay intact.
|
|
|
|
use crate::tools::metadata_metrics;
|
|
use codex_api::MAX_RESPONSE_MESSAGE_BYTES;
|
|
use codex_protocol::models::ResponseItem;
|
|
use codex_protocol::models::bound_executed_tool_calls_for_message;
|
|
use codex_utils_string::serialized_json_bytes;
|
|
use serde::Serialize;
|
|
|
|
pub(super) fn bounded_input<T: Serialize>(
|
|
message: &T,
|
|
input: &[ResponseItem],
|
|
) -> Option<Vec<ResponseItem>> {
|
|
if !input.iter().any(|item| {
|
|
item.executed_tool_call_metadata().is_some_and(|metadata| {
|
|
metadata.executed_tool_calls.is_some()
|
|
|| metadata.cell_id.is_some()
|
|
|| metadata.tool_calls_complete.is_some()
|
|
})
|
|
}) {
|
|
return None;
|
|
}
|
|
// Serialization errors belong to the transport's existing error path, not this soft budget.
|
|
let message_bytes = serialized_json_bytes(message).ok()?;
|
|
if message_bytes <= MAX_RESPONSE_MESSAGE_BYTES {
|
|
return None;
|
|
}
|
|
let before = metadata_metrics::metadata_bytes(input);
|
|
let mut bounded = input.to_vec();
|
|
let overage = message_bytes - MAX_RESPONSE_MESSAGE_BYTES;
|
|
bound_executed_tool_calls_for_message(&mut bounded, before.saturating_sub(overage));
|
|
let after = metadata_metrics::metadata_bytes(&bounded);
|
|
if before == after {
|
|
return None;
|
|
}
|
|
metadata_metrics::record_shedding("message", before, after, codex_otel::global().as_ref());
|
|
// Ordinary content alone can exceed the soft limit. Preserve it and existing error handling.
|
|
Some(bounded)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "client_tool_metadata_tests.rs"]
|
|
mod tests;
|