Finalize model-specific tool plans in ToolRouter (#41195)

## Why

Planning tools for a candidate model must not change the selected model or its
Responses Lite tool inventory. Otherwise, preparing a fallback can overwrite
metadata before the current model's request is sent.

## What changed

- Build tool registries and visible specs from an explicit `ModelInfo`.
- Store the finalized tool mode, code-mode names, namespace inventory, and
  terminal and child-management capabilities on `ToolRouter`.
- Publish namespace inventory only after selecting the step's router, and use
  that router's mode when dispatching and recording tool calls.

## Testing

Added coverage for candidate-model isolation, fallback compaction metadata,
code-mode worker selection, normalized tool names, and router capabilities.

GitOrigin-RevId: 56df2de8f42c7e93a4c4dcd117720e40a0cca3db
This commit is contained in:
Abhinav authored and copyberry committed 2026-08-27 20:01:39 +00:00
1 parent 8aea62b2d8
commit 0182ff3480
13 files changed
+532 -127

No files matched your search

+11 -1
View File
@@ -106,7 +106,7 @@ impl ToolCallRuntime {
executed_tool_calls.record_tool_call(
&call,
&source,
super::effective_tool_mode(&self.step_context.turn),
self.step_context.tool_router.tool_mode(),
);
}
let router = &self.step_context.tool_router;
@@ -349,6 +349,7 @@ impl Drop for ToolCallTimingGuard {
#[cfg(test)]
mod tests {
use super::*;
use std::collections::BTreeMap;
use std::time::Duration;
use crate::session::step_context::StepContext;
@@ -362,6 +363,7 @@ mod tests {
use codex_extension_api::ToolCallOutcome;
use codex_protocol::models::FunctionCallOutputBody;
use codex_protocol::models::FunctionCallOutputPayload;
use codex_protocol::openai_models::ToolMode;
use pretty_assertions::assert_eq;
use tokio::sync::Notify;
use tokio::sync::oneshot;
@@ -425,6 +427,10 @@ mod tests {
let router = Arc::new(ToolRouter::from_parts(
ToolRegistry::from_tools([handler]),
Vec::new(),
ToolMode::Direct,
BTreeMap::new(),
/*tool_namespaces_info*/ None,
&[],
));
let step_context = step_context.with_tool_router_for_test(router);
let tracker = Arc::new(tokio::sync::Mutex::new(TurnDiffTracker::new()));
@@ -610,6 +616,10 @@ mod tests {
let router = Arc::new(ToolRouter::from_parts(
ToolRegistry::from_tools([handler]),
Vec::new(),
ToolMode::Direct,
BTreeMap::new(),
/*tool_namespaces_info*/ None,
&[],
));
let step_context = step_context.with_tool_router_for_test(router);
let tracker = Arc::new(tokio::sync::Mutex::new(TurnDiffTracker::new()));