mirror of
https://github.com/openai/codex.git
synced 2026-11-08 16:38:30 +00:00
## Why Code-mode tool failure messages larger than 64 KiB were truncated before they reached the host. ## What changed - Remove the tool error size limit from the gRPC protocol and host validation. - Forward failed tool completion messages without truncation. ## Testing - Verify that a multibyte error larger than 64 KiB is preserved exactly. GitOrigin-RevId: 264ae4ba4adea5c19b669e4f41ccfd41a0c30fb5
55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
use codex_code_mode_protocol::grpc;
|
|
use codex_code_mode_protocol::host::MAX_FRAME_BYTES;
|
|
use prost::Message;
|
|
|
|
pub(super) fn request(
|
|
session_id: &str,
|
|
invocation_id: &str,
|
|
result: Result<serde_json::Value, String>,
|
|
) -> grpc::CompleteToolCallRequest {
|
|
request_with_maximum(session_id, invocation_id, result, MAX_FRAME_BYTES)
|
|
}
|
|
|
|
fn request_with_maximum(
|
|
session_id: &str,
|
|
invocation_id: &str,
|
|
result: Result<serde_json::Value, String>,
|
|
maximum_message_bytes: usize,
|
|
) -> grpc::CompleteToolCallRequest {
|
|
let outcome = match result {
|
|
Ok(value) => match serde_json::to_vec(&value) {
|
|
Ok(output_json) => {
|
|
grpc::complete_tool_call_request::Outcome::Succeeded(grpc::ToolCallSucceeded {
|
|
output_json,
|
|
})
|
|
}
|
|
Err(error) => grpc::complete_tool_call_request::Outcome::Failed(grpc::ToolCallFailed {
|
|
message: format!("failed to encode code-mode tool result: {error}"),
|
|
}),
|
|
},
|
|
Err(message) => {
|
|
grpc::complete_tool_call_request::Outcome::Failed(grpc::ToolCallFailed { message })
|
|
}
|
|
};
|
|
let mut request = grpc::CompleteToolCallRequest {
|
|
session_id: session_id.to_string(),
|
|
invocation_id: invocation_id.to_string(),
|
|
outcome: Some(outcome),
|
|
};
|
|
let encoded_bytes = request.encoded_len();
|
|
if encoded_bytes > maximum_message_bytes {
|
|
request.outcome = Some(grpc::complete_tool_call_request::Outcome::Failed(
|
|
grpc::ToolCallFailed {
|
|
message: format!(
|
|
"code-mode tool result of {encoded_bytes} encoded bytes exceeds the gRPC message limit of {maximum_message_bytes} bytes"
|
|
),
|
|
},
|
|
));
|
|
}
|
|
request
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "completion_tests.rs"]
|
|
mod tests;
|