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

+17
View File
@@ -3398,6 +3398,8 @@ impl Session {
let tool_router = turn::built_tools(
self.as_ref(),
turn_context.as_ref(),
// TODO(CDXENT-441): use the step scoped model
turn_context.model_info(),
&environments,
&mcp,
&extension_data,
@@ -3405,6 +3407,21 @@ impl Session {
)
.or_cancel(cancellation_token)
.await??;
// Publish inventory after planning rather than during finalization, so constructing
// additional candidate plans cannot overwrite turn-wide metadata.
if turn_context
.config
.tool_registry
.turn_metadata_includes_tool_info
&& turn_context.model_info().use_responses_lite
{
turn_context.turn_metadata_state.set_tool_namespaces_info(
tool_router
.tool_namespaces_info()
.cloned()
.unwrap_or_default(),
);
}
Ok(Arc::new(StepContext {
settings,
token_budget,