Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
fix(translation): preserve root tool names during namespace restoration (#1272)
David Gardnerf688c6242272
diff --git a/crates/switchyard-translation/src/codex_namespaces.rs b/crates/switchyard-translation/src/codex_namespaces.rsindex 7c757513e..8fe25502c 100644--- a/crates/switchyard-translation/src/codex_namespaces.rs+++ b/crates/switchyard-translation/src/codex_namespaces.rs@@ -81,12 +81,8 @@ pub fn namespace_description<'a>(/// Reverse map from an upstream tool name to its Codex tool name and namespace.///-/// The exact qualified name is always registered. A model often returns a near-/// miss instead, so two fallback spellings are registered when neither can be-/// confused with another tool:-///-/// * the qualified name without the `mcp__` prefix-/// * the bare tool name, only when exactly one namespace claims it+/// The exact qualified name is always registered. The name without the `mcp__`+/// prefix is also registered unless it matches another qualified name.pub fn qualified_tool_origins(extensions: &ProviderExtensions,) -> HashMap<String, (String, String)> {@@ -101,12 +97,6 @@ pub fn qualified_tool_origins(}).collect();- // A bare name claimed by more than one namespace cannot be guessed, and a- // fallback must never shadow a name that is itself a real qualified tool.- let mut bare_claims: HashMap<&str, usize> = HashMap::new();- for (_, tool, _) in &split {- *bare_claims.entry(tool.as_str()).or_default() += 1;- }let qualified_names: HashSet<&str> = split.iter().map(|(qualified, _, _)| qualified.as_str())@@ -121,11 +111,6 @@ pub fn qualified_tool_origins(origins.entry(spelling).or_insert_with(|| origin.clone());}}- if bare_claims.get(tool.as_str()) == Some(&1) && !qualified_names.contains(tool.as_str()) {- origins- .entry(tool.clone())- .or_insert_with(|| origin.clone());- }// The exact spelling always wins over a fallback.origins.insert(qualified.clone(), origin);}diff --git a/crates/switchyard-translation/tests/response_translation.rs b/crates/switchyard-translation/tests/response_translation.rsindex 1c654fde5..0861d3dba 100644--- a/crates/switchyard-translation/tests/response_translation.rs+++ b/crates/switchyard-translation/tests/response_translation.rs@@ -861,7 +861,7 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->"tool_calls": [{"id": "call_1","type": "function",- "function": {"name": "lookup", "arguments": "{\"q\":\"rust\"}"}+ "function": {"name": "search", "arguments": "{\"q\":\"rust\"}"}}, {"id": "call_2", "type": "function","function": {"name": "mcp__docs__search", "arguments": "{\"query\":\"streaming\"}"}@@ -888,7 +888,7 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->assert_eq!(output["output"],json!([- {"type": "function_call", "call_id": "call_1", "name": "lookup",+ {"type": "function_call", "call_id": "call_1", "name": "search","arguments": "{\"q\": \"rust\"}"},{"type": "function_call", "call_id": "call_2", "name": "mcp__docs__search","arguments": "{\"query\": \"streaming\"}"},@@ -913,6 +913,7 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->&json!({"input": "Search and list files","tools": [+ {"type": "function", "name": "search", "parameters": {}},{"type": "namespace", "name": "mcp__docs", "tools": [{"type": "function", "name": "search", "parameters": {}}]},@@ -925,7 +926,7 @@ fn openai_chat_response_with_tool_call_translates_to_responses_output_item() ->let empty = ProviderExtensions::default();let mut restored = output.clone();restored["output"] = json!([- {"type": "function_call", "call_id": "call_1", "name": "lookup",+ {"type": "function_call", "call_id": "call_1", "name": "search","arguments": "{\"q\": \"rust\"}"},{"type": "function_call", "call_id": "call_2", "name": "search","namespace": "mcp__docs", "arguments": "{\"query\": \"streaming\"}"},