Files
codex/codex-rs/tools/src/catalog_tool_message.rs
T
Adam Perry @ OpenAI 9a3c131eb4 Deduplicate model catalog strings in memory (#63735)
## Why

Identical instructions and tool descriptions can appear in multiple
model catalog records. Each decode or clone previously allocated its own
copy of that text.

## What changed

Use `CodexCachedStr` for catalog instructions, messages, and tool
overrides. It stores short strings inline and interns longer strings so
independent decodes and clones can share storage. Resolved incremental
tool messages also reuse cached text from overrides and bundled defaults.
JSON and generated TypeScript still represent these values as strings.

## Testing

Add tests for shared storage across catalog fields, independent decodes,
clones, and incremental tool defaults. Cover plain JSON string round
trips and borrowed access to short inline UTF-8 strings.

GitOrigin-RevId: 6f53b4e19f01f6ed52a8fd364279b924cf794be2
2026-11-24 20:21:47 +00:00

50 lines
1.8 KiB
Rust

//! Applies sparse catalog overrides while preserving bundled tool transport requirements.
//! Invalid parameters retain the bundled schema; other tool fields remain harness-owned.
use crate::ResponsesApiTool;
use crate::parse_catalog_tool_parameters;
use codex_protocol::openai_models::ToolMessage;
/// Apply catalog descriptions and parameters without changing the tool's identity or transport.
pub fn with_catalog_tool_message(
mut tool: ResponsesApiTool,
messages: Option<&ToolMessage>,
) -> ResponsesApiTool {
let Some(messages) = messages else {
return tool;
};
if let Some(description) = &messages.description {
description.as_str().clone_into(&mut tool.description);
}
if let Some(parameters) = &messages.parameters {
let parameters = parse_catalog_tool_parameters(parameters).and_then(|mut parameters| {
if let Some(properties) = &tool.parameters.properties {
for (name, bundled_property) in properties.iter() {
if bundled_property.encrypted == Some(true) {
let property = parameters
.properties
.as_mut()
.and_then(|properties| properties.get_mut(name))
.ok_or("schema omits an encrypted parameter")?;
property.encrypted = Some(true);
}
}
}
Ok(parameters)
});
match parameters {
Ok(parameters) => tool.parameters = parameters,
Err(reason) => tracing::warn!(
tool = %tool.name,
reason,
"Invalid catalog tool parameters; using bundled parameters"
),
}
}
tool
}
#[cfg(test)]
#[path = "catalog_tool_message_tests.rs"]
mod tests;