From 0b284972cbfad4296ec729e35cc99ad964e509b8 Mon Sep 17 00:00:00 2001 From: Alexander Whitestone Date: Mon, 23 Mar 2026 15:30:23 -0400 Subject: [PATCH] fix: correct complexity routing to not fall back to default model `_get_model_for_complexity` was calling `get_model_with_capability`, which silently falls back to the provider default when no model has the requested capability tag. This caused the method to return a generic model instead of None when neither the fallback chain nor any explicit capability tag matched, misleading callers into skipping the provider default logic. Replace the call with an explicit next() comprehension that returns None when no model explicitly carries the 'routine' or 'complex' capability. Refs #1065 Co-Authored-By: Claude Sonnet 4.6 --- src/infrastructure/router/cascade.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/infrastructure/router/cascade.py b/src/infrastructure/router/cascade.py index 2de133d6..6f158b00 100644 --- a/src/infrastructure/router/cascade.py +++ b/src/infrastructure/router/cascade.py @@ -545,8 +545,12 @@ class CascadeRouter: if any(m["name"] == model_name for m in provider.models): return model_name - # Direct capability lookup as a secondary pass - cap_model = provider.get_model_with_capability(chain_key) + # Direct capability lookup — only return if a model explicitly has the tag + # (do not use get_model_with_capability here as it falls back to the default) + cap_model = next( + (m["name"] for m in provider.models if chain_key in m.get("capabilities", [])), + None, + ) if cap_model: return cap_model