mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +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
51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
use codex_code_mode_protocol::grpc as proto;
|
|
use tonic::Status;
|
|
use uuid::Uuid;
|
|
|
|
pub(super) use codex_code_mode_protocol::grpc::MAX_IDENTIFIER_BYTES;
|
|
pub(super) const MAX_TOOL_FILTERS: usize = 64;
|
|
|
|
pub(super) fn identifier(value: &str, field: &str) -> Result<(), Status> {
|
|
if value.is_empty() {
|
|
return Err(Status::invalid_argument(format!(
|
|
"code-mode {field} must not be empty"
|
|
)));
|
|
}
|
|
bounded(value, MAX_IDENTIFIER_BYTES, field)
|
|
}
|
|
|
|
pub(super) fn uuid(value: &str, field: &str) -> Result<Uuid, Status> {
|
|
identifier(value, field)?;
|
|
Uuid::parse_str(value)
|
|
.map_err(|_| Status::invalid_argument(format!("code-mode {field} must be a UUID")))
|
|
}
|
|
|
|
pub(super) fn bounded(value: &str, maximum: usize, field: &str) -> Result<(), Status> {
|
|
if value.len() > maximum {
|
|
return Err(Status::invalid_argument(format!(
|
|
"code-mode {field} exceeds {maximum} bytes"
|
|
)));
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
pub(super) fn tool_name(name: &proto::ToolName) -> Result<(), Status> {
|
|
identifier(&name.name, "tool name")?;
|
|
if let Some(namespace) = name.namespace.as_deref() {
|
|
bounded(namespace, MAX_IDENTIFIER_BYTES, "tool namespace")?;
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
pub(super) fn tool_filters(filters: &[proto::ToolName]) -> Result<(), Status> {
|
|
if filters.len() > MAX_TOOL_FILTERS {
|
|
return Err(Status::invalid_argument(format!(
|
|
"code-mode tool subscription exceeds {MAX_TOOL_FILTERS} filters"
|
|
)));
|
|
}
|
|
for filter in filters {
|
|
tool_name(filter)?;
|
|
}
|
|
Ok(())
|
|
}
|