Honor tool-description-first ordering in Code Mode (#51704)

## What changed

Apply `code_mode_tool_description_first` when preparing nested tool definitions for Code Mode execution and tool search. When enabled, place each tool's description before its namespace description; otherwise, preserve namespace-first ordering.

Reuse cached MCP definitions only when both the input schema budget and description-order setting match.

## Testing

Extend deferred app tool integration tests to cover both description orders with and without ranked search, including consistency between search results and `ALL_TOOLS`. Extend the MCP cache test to reject reuse when the description-order setting changes.

GitOrigin-RevId: 1e3f84d2d95c200aef21ad710d367274b2169b4b
This commit is contained in:
swastik-oai
2026-10-07 14:32:44 +00:00
committed by copyberry
parent 95ec468619
commit 0a2a64e942
8 changed files with 97 additions and 25 deletions
@@ -4,6 +4,7 @@ use crate::tools::context::ToolPayload;
use crate::tools::context::boxed_tool_output;
use crate::tools::registry::CoreToolRuntime;
use crate::tools::registry::ToolExecutor;
use codex_features::Feature;
use codex_prompts::ResolvedModelMessages;
use codex_tools::IndirectNamespacePrefixes;
use codex_tools::ToolName;
@@ -55,12 +56,18 @@ impl CodeModeExecuteHandler {
.config
.code_mode
.tool_input_schema_max_bytes;
let tool_description_first = step_context
.turn
.config
.features
.enabled(Feature::CodeModeToolDescriptionFirst);
let mut enabled_tools = Vec::with_capacity(self.nested_tool_specs.len());
for (spec, cached_runtime) in &self.nested_tool_specs {
let definitions = prepare_code_mode_tool_definitions(
cached_runtime.as_deref(),
|| Cow::Borrowed(spec.as_ref()),
code_mode_input_schema_max_bytes,
tool_description_first,
);
match definitions {
Cow::Borrowed(definitions) => enabled_tools.extend_from_slice(definitions),
@@ -1,5 +1,6 @@
//! Prepares nested tool definitions for execution and search.
//! Cached definitions stay borrowed; rendered schemas are dropped after augmentation.
//! Description order follows the session-static feature setting.
use crate::tools::registry::CoreToolRuntime;
use codex_code_mode::ToolDefinition;
@@ -10,10 +11,12 @@ pub(crate) fn prepare_code_mode_tool_definitions<'a>(
runtime: Option<&'a dyn CoreToolRuntime>,
spec: impl FnOnce() -> Cow<'a, ToolSpec>,
code_mode_input_schema_max_bytes: Option<usize>,
tool_description_first: bool,
) -> Cow<'a, [ToolDefinition]> {
if let Some(definitions) = runtime
.and_then(|runtime| runtime.cached_code_mode_definitions(code_mode_input_schema_max_bytes))
{
if let Some(definitions) = runtime.and_then(|runtime| {
runtime
.cached_code_mode_definitions(code_mode_input_schema_max_bytes, tool_description_first)
}) {
return Cow::Borrowed(definitions);
}
@@ -21,6 +24,7 @@ pub(crate) fn prepare_code_mode_tool_definitions<'a>(
let mut definitions = codex_tools::collect_code_mode_tool_definitions(
std::iter::once(spec.as_ref()),
code_mode_input_schema_max_bytes,
tool_description_first,
);
for definition in &mut definitions {
definition.input_schema = None;