Reduce cloning when building Responses requests (#34825)

## Why

Preparing Responses API requests rebuilt tool definitions as a generic JSON
tree, and incremental WebSocket requests cloned their full item prefix for
comparison.

## What changed

- Serialize tool definitions into shared raw JSON that can be embedded directly
  in HTTP and WebSocket requests.
- Compare incremental request prefixes in place while still ignoring internal
  message metadata.

## Testing

- Verify raw tool JSON matches the existing value encoding.
- Preserve the serialized WebSocket request payload.

GitOrigin-RevId: 66e2921792c332e8904954dafa597f6d39abcf29
This commit is contained in:
jif authored and copyberry committed 2026-07-22 21:00:01 +00:00
1 parent bbfc3f0152
commit 12c115d558
12 files changed
+145 -42

No files matched your search

@@ -907,7 +907,10 @@ mod tests {
use codex_protocol::models::ResponseItem;
use pretty_assertions::assert_eq;
use serde_json::json;
use serde_json::value::RawValue;
use serde_json::value::to_raw_value;
use std::collections::HashMap;
use std::sync::Arc;
#[test]
fn direct_serialization_preserves_websocket_request_payload() {
@@ -923,11 +926,17 @@ mod tests {
phase: None,
internal_chat_message_metadata_passthrough: None,
}],
tools: Some(vec![json!({
"type": "function",
"name": "lookup",
"parameters": {"type": "object"}
})]),
tools: Some(
Arc::<RawValue>::from(
to_raw_value(&vec![json!({
"type": "function",
"name": "lookup",
"parameters": {"type": "object"}
})])
.expect("serialize tools"),
)
.into(),
),
tool_choice: "auto".to_string(),
parallel_tool_calls: true,
reasoning: None,