mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
## What changed - Subscribe each gRPC code-mode session to nested tool calls and forward tool and notification callbacks to its delegate. - Complete tool calls through the host while bounding oversized results and errors. - Track callback ownership and cancellation so completed cells drain notifications, terminated cells cancel them, and shutdown revokes outstanding work. - Validate callback identifiers, cell ownership, enabled tools, and pending callback limits without serializing independent callbacks or sessions. ## Testing - Add integration and state tests for callback forwarding, completion ordering, cancellation, malformed callbacks, delegate panics, oversized results, and concurrent work. GitOrigin-RevId: 005afbb90eea0eb77d746b930a1a96ca6dfcd4e7
46 lines
1.6 KiB
Rust
46 lines
1.6 KiB
Rust
use codex_code_mode_protocol::grpc;
|
|
use pretty_assertions::assert_eq;
|
|
use prost::Message;
|
|
|
|
use super::MAX_TOOL_ERROR_BYTES;
|
|
use super::TRUNCATED_SUFFIX;
|
|
use super::request;
|
|
use super::request_with_maximum;
|
|
|
|
#[test]
|
|
fn completion_size_includes_the_protobuf_envelope() {
|
|
let output = serde_json::Value::String("a".repeat(100));
|
|
let raw_json_bytes = serde_json::to_vec(&output).expect("valid JSON").len();
|
|
let completion = request_with_maximum("session", "invocation", Ok(output), raw_json_bytes);
|
|
|
|
assert!(matches!(
|
|
completion.outcome,
|
|
Some(grpc::complete_tool_call_request::Outcome::Failed(grpc::ToolCallFailed {
|
|
message,
|
|
})) if message.contains("encoded bytes exceeds the gRPC message limit")
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn delegate_errors_are_truncated_at_a_utf8_boundary() {
|
|
let error = "🦀".repeat(MAX_TOOL_ERROR_BYTES);
|
|
let completion = request("session", "invocation", Err(error));
|
|
let Some(grpc::complete_tool_call_request::Outcome::Failed(failure)) = completion.outcome
|
|
else {
|
|
panic!("expected a failed tool completion");
|
|
};
|
|
|
|
assert!(failure.message.len() <= MAX_TOOL_ERROR_BYTES);
|
|
assert!(failure.message.ends_with(TRUNCATED_SUFFIX));
|
|
assert!(failure.message.starts_with('🦀'));
|
|
}
|
|
|
|
#[test]
|
|
fn completion_at_exact_message_limit_is_accepted() {
|
|
let value = serde_json::json!({ "ok": true });
|
|
let expected = request("session", "invocation", Ok(value.clone()));
|
|
let actual = request_with_maximum("session", "invocation", Ok(value), expected.encoded_len());
|
|
|
|
assert_eq!(actual, expected);
|
|
}
|