Repository navigation
fix(proxy): reject model writes that corrupt an auto-router pseudo-model - #34151
Conversation
Greptile SummaryThis PR prevents model-management writes from corrupting auto-router pseudo-models. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| litellm/router_utils/auto_router_model_naming.py | Adds shared strategy-router classification and validation rules. |
| litellm/proxy/management_endpoints/model_management_endpoints.py | Validates auto-router model writes before create, update, and patch persistence. |
| litellm/router.py | Uses the shared classifier for the four strategy-router predicates. |
| tests/test_litellm/router_utils/test_auto_router_model_naming.py | Tests router classification and coherent or malformed model values. |
| tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py | Tests validation across all three model-management write paths. |
Reviews (2): Last reviewed commit: "fix(proxy): reject model writes that cor..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit dcbff18. Configure here.
An auto-router deployment's litellm_params.model (auto_router/...) is the discriminator the router loads it by, but the model management endpoints accepted any client-supplied value verbatim; a doubled or stripped prefix made router init fail on the next load and ignore_invalid_deployments silently dropped the deployment. Validate writes that supply litellm_params.model at all three endpoints against the merged params and reject incoherent values with an actionable 400. Classification is extracted to router_utils/auto_router_model_naming.py so the Router predicates and the validation share one source
dcbff18 to
1e04aee
Compare
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1e04aee. Configure here.
Relevant issues
/model/new,/model/update, and/model/{model_id}/updatewrites that would mangle an auto-router deployment'slitellm_params.modeldiscriminator (doubled prefix, stripped prefix, or missing required strategy config), returning an actionable 400 instead of letting the router silently void the modelauto_router/prefix) into a sharedrouter_utils/auto_router_model_naming.pyhelper that bothRouter._is_*_router_deploymentand the new write validation use, so the naming contract is single-sourcedmodel_namerenames (including toauto_router/<name>) stay legal, and already-corrupted rows stay healable by writing the correct pseudo-model back through the same fieldLinear ticket
Resolves LIT-4663
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)One CI red is inherited from the base branch, not this diff: osv-scan (pyasn1 0.6.3 in uv.lock, GHSA-8ppf-4f7h-5ppj; fails identically on sibling PRs, the lockfile bump belongs in its own PR). Locally,
make pre-commitalso reds on the pre-existing e2e basedpyright errors in tests/e2e/llm_translation (fix open in #34090); that gate does not run in CI. Everything this diff touches is green: ruff format, strict/LIT budgets, basedpyright budget, gen:api sync, and both mapped test filesScreenshots / Proof of Fix
A customer edited the "LiteLLM Model Name" field of a working complexity auto-router in the dashboard. That field is
litellm_params.model, which for auto-routers is not a provider model at all; it is the internal discriminator (auto_router/complexity_router) the router loads the deployment by. The edit persistedauto_router/auto_router/complexity_routerverbatim, router init then failed on the next load,ignore_invalid_deploymentsswallowed the failure, and the model vanished: calls fail "no healthy deployments", and after a restart the model is gone from/v1/modelsentirely. There is no guard on this field in the UI or the API, so one keystroke in a free-text box silently destroys a working routerRepro and verify below ran against a live proxy (port 4663, real Postgres, real Anthropic calls), config: three claude tier models plus a DB-stored complexity auto-router created via
/model/newBefore the fix (staging HEAD 01d624e):
The stripped variant (
"model": "complexity_router") voids the model the same wayAfter the fix (same commands):
Type
🐛 Bug Fix
Changes
litellm/router_utils/auto_router_model_naming.py:classify_strategy_router_model(faithful to existing Router registration semantics) andvalidate_strategy_router_model_write, which checks a writtenlitellm_params.modelagainst the strategy fields present on the merged deploymentlitellm/router.py: the four_is_*_router_deploymentpredicates now delegate to the shared classifier; no behavior changelitellm/proxy/management_endpoints/model_management_endpoints.py:add_new_model,update_model, andpatch_modelreject incoherent writes with a 400 naming the violation and the fix; only writes that supplylitellm_params.modelare judged, so partial patches and restores of corrupted rows stay legaltests/test_litellm/router_utils/test_auto_router_model_naming.py(classification + malformed/coherent write families) andTestStrategyRouterWriteValidationin the mapped management-endpoints test file (all three endpoint seams, restore path, patch-without-model)What does not change: routing and dispatch, the strategy registries, the dedicated Edit Auto Router modal (it never touches
litellm_params.model), config-file loading, and publicmodel_namerenamesThings a reviewer will ask about: the validator judges the merged final state rather than the transition, which is what keeps a restore of an already-corrupted row legal while still blocking every corruption; and it only runs when the write supplies
litellm_params.model, so it needs no decryption of stored values (presence of strategy fields is unaffected by encryption at rest)QA runbook
auto_router/auto_router/complexity_router, Save: expect a red toast with the "repeats the 'auto_router/' prefix" message, and the model keeps serving requestscomplexity_router: expect the "does not start with 'auto_router/'" toastauto_router/my-routerinstead and Save: expect success, and{"model": "auto_router/my-router"}chat completions return 200curl -X POST /model/newwithlitellm_params.model="auto_router/sem-router"and noauto_router_embedding_model: expect 400 naming the missing fieldFinal Attestation
Note
Medium Risk
Touches proxy model-management write paths for all DB-backed models; logic is narrow (only when
litellm_params.modelis supplied) but incorrect validation could block legitimate creates/updates.Overview
Prevents silent loss of auto-router deployments when admins edit
litellm_params.model(the internalauto_router/...discriminator) via/model/new,/model/update, orPATCH /model/{id}/update. Invalid values—doubled prefix, stripped prefix, missing router name, or strategy config that does not match the chosen router kind—now fail with a 400 and an actionable message instead of persisting a row the router drops underignore_invalid_deployments.Introduces
litellm/router_utils/auto_router_model_naming.pyas the single source forclassify_strategy_router_modelandvalidate_strategy_router_model_write.Router._is_*_router_deploymentdelegates to the classifier (behavior unchanged). Management endpoints merge stored and incoming strategy-router fields and only validate when the write includeslitellm_params.model, so partial patches and fixing already-corrupted rows stay allowed; publicmodel_namerenames are unaffected.Reviewed by Cursor Bugbot for commit 1e04aee. Bugbot is set up for automated code reviews on this repo. Configure here.