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
This commit is contained in:
Adam Perry @ OpenAI
2026-11-24 20:21:47 +00:00
committed by copyberry
parent 7a24022794
commit 9a3c131eb4
91 changed files with 799 additions and 508 deletions
@@ -40,7 +40,7 @@ fn exec_override_renders_only_known_literal_placeholders() {
/*incremental_exec_enabled*/ true,
Some(&CodeModeToolMessages {
exec: Some(ToolMessage {
description: Some(" \nDefaults to 10000 ms. {{ default_exec_yield_time_ms }} ms.\n{{ image_helper }}\n{{ unknown }} {{default_exec_yield_time_ms}}\t ".to_string()),
description: Some(" \nDefaults to 10000 ms. {{ default_exec_yield_time_ms }} ms.\n{{ image_helper }}\n{{ unknown }} {{default_exec_yield_time_ms}}\t ".into()),
..Default::default()
}),
..Default::default()
@@ -72,13 +72,11 @@ fn exec_override_preserves_empty_and_whitespace_only_text() {
/*incremental_exec_enabled*/ false,
Some(&CodeModeToolMessages {
exec: Some(ToolMessage {
description: Some(description_override.to_string()),
description: Some(description_override.into()),
..Default::default()
}),
deferred_nested_tools_guidance: Some(
"No deferred tools; omit this.".to_string()
),
mcp_typescript_preamble: Some("No MCP tools; omit this.".to_string()),
deferred_nested_tools_guidance: Some("No deferred tools; omit this.".into()),
mcp_typescript_preamble: Some("No MCP tools; omit this.".into()),
..Default::default()
}),
)
@@ -165,11 +163,11 @@ fn exec_override_preserves_runtime_sections() {
/*incremental_exec_enabled*/ false,
Some(&CodeModeToolMessages {
exec: Some(ToolMessage {
description: Some(String::new()),
description: Some("".into()),
..Default::default()
}),
deferred_nested_tools_guidance: guidance.map(str::to_string),
mcp_typescript_preamble: preamble.map(str::to_string),
deferred_nested_tools_guidance: guidance.map(Into::into),
mcp_typescript_preamble: preamble.map(Into::into),
..Default::default()
}),
)
@@ -214,11 +212,11 @@ fn ranked_search_guidance_honors_overrides() {
/*incremental_exec_enabled*/ false,
Some(&CodeModeToolMessages {
exec: Some(ToolMessage {
description: Some(String::new()),
description: Some("".into()),
..Default::default()
}),
deferred_nested_tools_guidance: guidance.map(str::to_string),
mcp_typescript_preamble: Some(String::new()),
deferred_nested_tools_guidance: guidance.map(Into::into),
mcp_typescript_preamble: Some("".into()),
..Default::default()
}),
);
@@ -249,7 +247,7 @@ fn mcp_types_stay_stable_when_a_deferred_tool_changes_its_output_schema() {
DeferredToolDiscovery::Catalog,
/*incremental_exec_enabled*/ false,
Some(&CodeModeToolMessages {
mcp_typescript_preamble: preamble.map(str::to_string),
mcp_typescript_preamble: preamble.map(Into::into),
..Default::default()
}),
)
@@ -295,11 +293,11 @@ fn nested_guidance_survives_catalog_changes_and_respects_overrides() {
/*incremental_exec_enabled*/ false,
Some(&CodeModeToolMessages {
exec: Some(ToolMessage {
description: Some(String::new()),
description: Some("".into()),
..Default::default()
}),
deferred_nested_tools_guidance: guidance.map(str::to_string),
mcp_typescript_preamble: Some(String::new()),
deferred_nested_tools_guidance: guidance.map(Into::into),
mcp_typescript_preamble: Some("".into()),
..Default::default()
}),
)