Repository navigation
fix(router): tag-based routing for complexity_router deployments sharing a model_name - #33708
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…nts sharing a model_name
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR fixes a collision bug where two
Confidence Score: 4/5The core fix is correctly scoped and the new tests cover registration, duplicate rejection, and per-tag selection. Two minor concerns around the adaptive-router init fallback and the no-match silent fallback keep this from a clean bill of health. The key structural change (list-based registry + tag selection) is sound, the single-deployment fast-path is preserved, and the tests match real-world scenarios described in the linked issue. The break placement in the adaptive-router init loop and the silent routers[0] fallback when request tags match no deployment are present-but-edge-case concerns that do not affect the primary fix. litellm/router.py — specifically the _finalize_adaptive_router_if_configured inner loop and the _select_complexity_router fallback path
|
| Filename | Overview |
|---|---|
| litellm/router.py | Core fix: changes complexity_routers dict value from a single ComplexityRouter to a list, adds _select_complexity_router for per-request tag-based selection; one subtle issue with break placement in _finalize_adaptive_router_if_configured |
| litellm/router_strategy/complexity_router/complexity_router.py | Adds deployment_tags parameter to ComplexityRouter.init and stores it as self.deployment_tags; straightforward and correct |
| tests/test_litellm/router_strategy/test_complexity_router.py | Adds targeted regression tests for the dual-deployment tag collision bug; all tests are mock-only (no network calls), covering registration, duplicate rejection, tag-based selection, and the pre-routing hook |
Reviews (1): Last reviewed commit: "fix(router): support tag-based routing f..." | Re-trigger Greptile
| for complexity_router in complexity_router_list: | ||
| if not complexity_router.config.adaptive: | ||
| continue | ||
| adaptive_router = complexity_router._ensure_adaptive_router() | ||
| if adaptive_router is not None: | ||
| self.adaptive_routers[model_name] = adaptive_router | ||
| break |
There was a problem hiding this comment.
break fires even when adaptive-router init returns None
The break sits outside the if adaptive_router is not None: guard, so the inner loop exits regardless of whether the first adaptive=True complexity router successfully produced an AdaptiveRouter. If a config-reload path caused the first router's _adaptive_init_attempted to be True with self.adaptive_router=None (a failed prior init), this loop exits without registering anything and silently skips any subsequent routers in the list that might succeed. Moving break inside the if block would ensure the loop keeps searching until it registers a valid adaptive router.
| for router in routers: | ||
| if "default" in router.deployment_tags: | ||
| return router | ||
|
|
||
| return routers[0] |
There was a problem hiding this comment.
Silent fallback to wrong tier config when no tags match
When request_tags is non-empty but no deployment's deployment_tags satisfy is_valid_deployment_tag, the function falls through to the "default" check and finally returns routers[0]. This means a request tagged ["row-dev"] with no matching deployment silently gets the cn tier config (wrong region's model list), which can still produce 401 Not allowed errors for the cn models. Consider whether a hard failure (or at least a warning log) is more appropriate when the request carries tags that match no registered deployment.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Relevant issues
Fixes #33655
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Live proxy against real Anthropic APIs (costs real $), two
auto_router/complexity_routerdeployments sharingmodel_name: smart-router, one taggedregion-aand one taggedregion-b, withenable_tag_filtering: trueBefore the fix (base
litellm_internal_staging), the second deployment is dropped at startupso a
region-brequest is forced onto theregion-aconfig and 401s, exactly as reportedAfter the fix (this branch, commit
73524df72a), both configs register and each tag resolves to its own configregion-aresolves toregion-a-simple(claude-opus-4-1) andregion-bresolves toregion-b-simple(claude-sonnet-4-5), so each tag group now hits its own tier config instead of colliding on the first oneType
🐛 Bug Fix
Changes
Two
auto_router/complexity_routerdeployments that share amodel_namebut carry differenttags(e.g. one tier config per region) used to collide:self.complexity_routerswas keyed bymodel_namealone, so the second registration raised "already exists" and was dropped whenignore_invalid_deploymentsswallowed it. Every request then resolved to the first deployment's tier config regardless of the request's tags, which produced 401Not allowed to access model due to tags configurationfor the second tag groupThe registry now holds every config for a
model_nameand selection happens per request based on tagsComplexityRouternow stores thedeployment_tagsit was built with so the selection above can disambiguate._finalize_adaptive_router_if_configuredwas updated to iterate the list values. Single-deployment setups are unchanged because a one-element list short-circuits to that routerScope is intentionally limited to the complexity router, which is the case reported and reproduced.
auto_routers,adaptive_routersandquality_routersshare the sameDict[model_name, router]shape and the same latent limitation; extending them can follow the same pattern in a separate change (adaptive is more involved because of its per-instance post-call hooks and DB-backed state)Final Attestation
Link to Devin session: https://app.devin.ai/sessions/eb65ae6ee3c04263a44e7a3054cad015