Repository navigation
feat(router): limit heuristic_v2 auto-routers to one without the auto_router license feature - #39468
Conversation
|
PR #39468 labeled |
Greptile SummaryThis PR limits heuristic-v2 auto-routers to one unless a verified signed license grants the
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/proxy/auth/litellm_license.py | Adds the auto-router entitlement resolver and clears cached signed payloads on every rejected verification path. |
| litellm/proxy/management_endpoints/model_management_endpoints.py | Serializes limited heuristic-v2 row writes with a PostgreSQL advisory lock and orders team bookkeeping after successful persistence. |
| litellm/proxy/proxy_server.py | Validates config-file router counts and injects the dynamic license-backed limit into proxy Router instances. |
| litellm/router.py | Enforces the injected registration ceiling while preserving previously serving deployment state after failed upserts. |
| litellm/router_utils/auto_router_model_naming.py | Centralizes heuristic-v2 detection, counting, and an SDK-neutral limit message. |
| tests/test_litellm/proxy/auth/test_litellm_license.py | Covers entitlement resolution and valid-to-rejected signed-license transitions. |
Reviews (8): Last reviewed commit: "feat(router): limit heuristic_v2 auto-ro..." | Re-trigger Greptile
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 3 · PR risk: 0/10 |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
CI note: documentation and code-quality are red only on the router_settings doc row, which is BerriAI/litellm-docs#1152; proxy-endpoints is red on an inherited crowdstrike_aidr cadence test that fails identically at the merge-base. Everything else is green on fb1f831437. @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 4/5. The implementation is well-scoped and the behavior is convincingly covered: entitlement-aware limits are enforced at startup, write endpoints, and router registration; config and DB deployments are handled; expired signed licenses clear feature access; and the tested license/no-license flows match the intended behavior. The runtime evidence demonstrates both rejection and successful routing paths. I’m not giving 5/5 because the PR still has known red CI checks, even though the documented failures appear unrelated or externally blocked, and the multi-pod race noted in the caveats remains an accepted limitation. Those do not indicate a correctness issue in the changed logic, but they prevent full confidence until the CI/docs conditions are resolved. |
fb1f831 to
01a5532
Compare
|
Round pushed as 01a5532: the Router takes a heuristic_v2_router_limit resolver and re-checks license expiry on every write and registration, verify clears the cached payload on failure, the Router message is SDK-neutral with the license remedy appended proxy-side, and the new tests are typed. Rebased onto staging, so proxy-endpoints is green; documentation and code-quality are red only on the router_settings doc row (BerriAI/litellm-docs#1152). @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 4/5. The previously identified correctness issues are addressed: the Router now uses a live license-limit resolver, expiry is re-evaluated on each write and registration, failed license verification clears cached entitlement data, and SDK-facing errors remain license-neutral with the proxy adding the licensing remedy. The new typed tests cover license transitions, config/DB registration, endpoint writes, slot-preserving edits, and unlimited licensed behavior, and the reported proxy-endpoints failure is now green. I’m not giving 5/5 because documentation and code-quality remain red while the external |
a980f1a to
ff81cc8
Compare
|
Round pushed as ff81cc8. Two changes. (1) Per-call license expiry is reverted: |
|
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 ff81cc8. Configure here.
ff81cc8 to
24e2d24
Compare
|
Round pushed as 24e2d24: the heuristic_v2 slot is now claimed atomically. A heuristic_v2 write under a limited license runs in one transaction with |
|
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 24e2d24. Configure here.
|
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 a6ede47. Configure here.
|
@greptileai can you reply here with score and why |
|
Confidence score: 4/5. This is a strong, well-scoped implementation: the entitlement is derived only from a verified, non-expired signed license; enforcement covers config startup, router registration, and create/update APIs; and the Postgres advisory-lock transaction closes the concurrent-write gap while preserving team-model ordering and rollback behavior. The added unit, endpoint, startup, and concurrency-focused tests plus the end-to-end evidence cover the important customer flows. I’m not giving 5/5 because this is a high-impact change across licensing, startup, router state, and transactional model management, with behavior that still depends on the documented multi-pod/config assumptions. The PR also notes documentation/code-quality CI remains red pending the external docs change, so final confidence should increase once those checks are green. |
|
Independent E2E run of a6ede47: proxy on 127.0.0.1:4590 with its own Postgres database ( # one.yaml (two.yaml adds an identical v2-router-b)
model_list:
- model_name: haiku
litellm_params: {model: anthropic/claude-haiku-4-5, api_key: os.environ/ANTHROPIC_API_KEY}
- model_name: sonnet
litellm_params: {model: anthropic/claude-sonnet-4-6, api_key: os.environ/ANTHROPIC_API_KEY}
- model_name: v2-router-a
litellm_params:
model: auto_router/complexity_router
complexity_router_config: {classifier_type: heuristic_v2, tiers: {SIMPLE: haiku, MEDIUM: haiku, COMPLEX: sonnet, REASONING: sonnet}}
general_settings: {master_key: sk-1234, store_model_in_db: true}H=(-H "Authorization: Bearer sk-1234" -H "Content-Type: application/json")
V2='{"model_name":"v2-router-db","litellm_params":{"model":"auto_router/complexity_router","complexity_router_config":{"classifier_type":"heuristic_v2","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'
V1='{"model_name":"v1-router-db","litellm_params":{"model":"auto_router/complexity_router","complexity_router_config":{"classifier_type":"heuristic","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'
P1: curl "${H[@]}" http://127.0.0.1:4590/model/info | jq '.data[] | select(.litellm_params.model=="auto_router/complexity_router") | [.model_name, .litellm_params.complexity_router_config.classifier_type]'
P2: curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"
P3: curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"
P4: curl -si "${H[@]}" http://127.0.0.1:4590/v1/chat/completions -d '{"model":"v2-router-a","messages":[{"role":"user","content":"Say hi in three words"}]}'
P5: curl "${H[@]}" http://127.0.0.1:4590/health/license
P6: curl "${H[@]}" -X PATCH http://127.0.0.1:4590/model/<P3 id>/update -d '{"litellm_params":{"complexity_router_config":{"classifier_type":"heuristic_v2","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'
Startup refusal (L1, and L3 with two.yaml) P2 403 body (same text on the P6 403) L5 license lapse: with the Restarted again with the L6 concurrency: no license, config with no heuristic_v2 router, six Note on L3/L4c: |
…_router license feature
Without the auto_router feature in the signed enterprise license a proxy may hold
one complexity router with classifier_type heuristic_v2 across config.yaml and the
DB; with it the limit is lifted. The ceiling is derived once from LicenseCheck and
handed to the Router, which refuses the extra router at registration. config.yaml
over the limit refuses to start, and /model/new, /model/update and
PATCH /model/{id}/update refuse the write with a 403 before touching the DB.
Expiry follows the existing max_users/max_teams pattern: judged when the
license is verified, not on every call, and a verify that rejects the license
(expired or unreadable) leaves no signed payload behind. The rollback after a
failed upsert re-admits state that was already serving, so it is exempt from the
ceiling: an edit that fails, including one refused by a ceiling that has since
tightened, leaves the router serving its previous configuration.
A write that leaves a row on heuristic_v2 under a limited license runs in one
transaction that takes a Postgres advisory lock before counting the DB rows plus
this proxy's config.yaml routers, so concurrent writes on any pod cannot both
claim the sole slot and no surplus row is ever persisted.
Only the row insert runs under that lock: the team model bookkeeping, which
needs a second pool connection, runs after the transaction has committed.
PATCH /model/{id}/update follows the same order as create: the row is written
through the slot first and the team's model list is updated only afterwards, so
a refused write leaves the team as it was.
The slot transaction bypasses the repository's publish-on-write, so it
publishes the config change once after commit, as delete_team_models does.
a6ede47 to
41f47eb
Compare
|
Rebased onto current litellm_internal_staging as 41f47eb (was conflicting after #39436 landed the access-group rename sync in the same two write blocks). Resolution only, no behavior change: in |
|
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 41f47eb. Configure here.
… the auto_router license feature Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose records own their in-process predicate, SQL spelling and refusal wording. The existing heuristic_v2 capability keeps its own one-router ceiling. A single customization capability combines operator-defined tier_definitions and an operator-written classifier system_prompt, so an unlicensed proxy can have at most one router that customizes either form. The prompt half only applies to classifier types that call an LLM. The shipped default prompt, classification rubric presets, tier_labels renames and tier model choices remain ungated. The signed auto_router license feature makes both ceilings unlimited.
test_no_linear_scans_in_router: BerriAI#39468 added config_deployments() and heuristic_v2_router_limit_violation(), which both scan the whole model_list from admin-only paths (model add/upsert), so add them to the allowlist. The allowlist becomes a mapping so each exemption carries its reason as data. test_missing_model_parameter_curl: a request with no model is rejected by the proxy when nothing can serve it and by the router when a wildcard or default deployment exists, and by the upstream provider when a wildcard forwards it, so the message text is not a stable contract. Assert the contract that holds in every case: HTTP 400 with a non-empty error message. test_model_group_info_e2e: /model_group/info resolves wildcards, so it can never return "anthropic/*" verbatim. cc3f9cd rewrote the assertion to expect the raw pattern after claude-3-5-haiku-20241022 left the price map, which made it unsatisfiable. Assert the expansion instead. test_should_derive_ocr_mapping_status_from_live_tests: the audit needs a native bridge built with the trace-parity feature, which CI never builds, so skip with the harness's own diagnostic instead of erroring. Extract that check out of ensure_trace_bridge as trace_bridge_error so a pytest run reports the state without kicking off a maturin rebuild.
… the auto_router license feature Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose records own their in-process predicate, SQL spelling and refusal wording. The existing heuristic_v2 capability keeps its own one-router ceiling. A single customization capability combines operator-defined tier definitions with every operator-written part of the classifier prompt. The prompt half only applies to classifier types that call an LLM. The shipped default prompt, classification rubric presets, tier-label renames and tier model choices remain ungated. Scope every enforcement point to actual complexity routers. A model-less PATCH or legacy update now decrypts the stored model before accepting strategy-router settings, so a regular model cannot acquire a router config or spend a license slot. Under the existing advisory lock, the cross-pod candidate query returns only model scalars and the count decrypts and classifies them in process; old non-router rows carrying a capability-shaped config no longer block a real complexity router. The signed auto_router license feature makes both ceilings unlimited.
… the auto_router license feature Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose records own their in-process predicate, SQL spelling and refusal wording. The existing heuristic_v2 capability keeps its own one-router ceiling. A single customization capability combines operator-defined tier definitions with every operator-written part of the classifier prompt. The prompt half only applies to classifier types that call an LLM. The shipped default prompt, classification rubric presets, tier-label renames and tier model choices remain ungated. Scope every enforcement point to actual complexity routers. A model-less PATCH or legacy update now decrypts the stored model before accepting strategy-router settings, so a regular model cannot acquire a router config or spend a license slot. Under the existing advisory lock, the cross-pod candidate query returns only model scalars and the count decrypts and classifies them in process; old non-router rows carrying a capability-shaped config no longer block a real complexity router. The signed auto_router license feature makes both ceilings unlimited.
… the auto_router license feature (#39674) Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose records own their in-process predicate, SQL spelling and refusal wording. The existing heuristic_v2 capability keeps its own one-router ceiling. A single customization capability combines operator-defined tier definitions with every operator-written part of the classifier prompt. The prompt half only applies to classifier types that call an LLM. The shipped default prompt, classification rubric presets, tier-label renames and tier model choices remain ungated. Scope every enforcement point to actual complexity routers. A model-less PATCH or legacy update now decrypts the stored model before accepting strategy-router settings, so a regular model cannot acquire a router config or spend a license slot. Under the existing advisory lock, the cross-pod candidate query returns only model scalars and the count decrypts and classifies them in process; old non-router rows carrying a capability-shaped config no longer block a real complexity router. The signed auto_router license feature makes both ceilings unlimited.
TLDR
Problem this solves:
classifier_type: heuristic_v2ships with no entitlement check at allHow it solves it:
allowed_featurescontainingauto_routerlifts the limit/model/new,/model/update,PATCH /model/{id}/updaterefuse with a 403 before the DB writepg_advisory_xact_lock) before counting the DB rows plus this proxy's config.yaml routers, so concurrent writes on any pod cannot both claim the sole slot and no surplus row is ever persisted; no migration, no new column. Only the row write runs under the lock; the team model bookkeeping, which needs a second pool connection, runs after the transaction has committed.PATCH /model/{id}/updatenow orders itself like create (row first, team list second), so a refused write leaves the team's model list untouched. The slot transaction bypasses the repository's publish-on-write, so it publishes the config change to other pods once after commit, the waydelete_team_modelsdoesmax_users/max_teamspattern: the signed payload is judged when the license is verified, and the limit reads that payload at each write and registration; a verify that rejects the license (expired or unreadable) leaves no payload behindUser Flow
Before: an operator on a plain enterprise license (or no license) runs as many heuristic_v2 auto-routers as they like
auto_router/complexity_routerentries set toclassifier_type: heuristic_v2in config.yaml; both show up in GET /model/infoAfter: the same operator gets exactly one heuristic_v2 auto-router until the license carries the
auto_routerfeatureconfig.yaml model_list: At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router. A LiteLLM license with the 'auto_router' feature lifts the limit.classifier_type: heuristicrouter still gets 200"allowed_features": ["auto_router"]and they restart: both config.yaml routers load and POST /model/new for a third heuristic_v2 router returns 200Relevant issues
heuristic_v2without gatingLinear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
Rig: proxy from this worktree on
127.0.0.1:4590with its own Postgres database, tiers served by real Claude models through the sandbox gateway (each chat completion below is billed,x-litellm-response-costshown). The signed licenses for the After legs were produced with a throwaway RSA keypair whose public key temporarily replacedlitellm/proxy/auth/public_key.pemin the rig only (the file is untouched in this PR); the payload was verified through the real signature path and the server log shows the parsedallowed_featuresfor each legShared setup
Before (a5639b8)
No license, config.yaml with two heuristic_v2 routers
curl "${H[@]}" http://127.0.0.1:4590/model/infofiltered to auto-routerscurl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"curl "${H[@]}" http://127.0.0.1:4590/v1/chat/completions -d '{"model":"v2-router-a","messages":[{"role":"user","content":"Say hi in three words"}]}'After (41f47eb)
No license, config.yaml with two heuristic_v2 routers
No license, config.yaml with one heuristic_v2 router
curl "${H[@]}" http://127.0.0.1:4590/model/infofiltered to auto-routerscurl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"v2-router-a(response headers)License lapses: a DB heuristic_v2 row created under the feature, then a restart without it
auto_routerlicense and the one-router config:curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"curl "${H[@]}" http://127.0.0.1:4590/model/infofiltered to auto-routersPlain enterprise license (signed,
"allowed_features": []), config.yaml with one heuristic_v2 router'allowed_features': []curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"License with the feature (signed,
"allowed_features": ["auto_router"]), config.yaml with two heuristic_v2 routers'allowed_features': ['auto_router']curl "${H[@]}" http://127.0.0.1:4590/model/infofiltered to auto-routerscurl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"v2-router-a(response headers)Concurrent creates: six
POST /model/newheuristic_v2 requests fired together, no license, config.yaml with no heuristic_v2 routerBefore (ff81cc8, the pre-transaction head): the endpoint judged the live router, which only updates on reload, so every request saw the slot free
After (41f47eb): the advisory lock serialises the six transactions and the count runs inside each
Concurrent team-scoped creates: six
POST /model/newheuristic_v2 requests withmodel_info.team_idfired together, signed license with"allowed_features": []The team path runs
team_model_addon a second pool connection, so this is the burst that would stall if it ran under the lockTeam-scoped PATCH: rename and switch to heuristic_v2 in one request while the slot is held, signed license with
"allowed_features": []Type
🆕 New Feature
Caveats (if any)
Low
The slot transaction counts config.yaml routers from this pod's live router; pods running different config.yaml files would each add their own config routers to the count, which is the same assumption the startup validator already makes
CI: the
documentationandcode-qualityjobs stay red until docs(proxy): document router_settings.heuristic_v2_router_limit litellm-docs#1152 (themax_heuristic_v2_routersrow in the router_settings reference) merges; CI checks the docs repo out unpinned from mainA license verified through the license API (no signed payload) carries no feature list, so it keeps the one-router limit by design
A license that expires while the proxy is running keeps lifting the limit until the next license verification (startup or config load), exactly as
max_users,max_teamsand everypremium_usergate behave today; the license module is not special-cased for this feature. An already-expired signed license no longer populatesairgapped_license_data, somax_users/max_teamsalso stop binding for it (it is not premium either way)The dashboard still offers Heuristic v2 in the classifier picker; over the limit the 403 message above surfaces as the save error. Disabling the option in the UI from
/health/licenseis a follow-uprouter_settings.heuristic_v2_router_limitin config.yaml is ignored (managed outside config), so the ceiling can only come from the licenseThe Router-side message is SDK-neutral; the "license lifts the limit" sentence is appended by the proxy on the 403 and the startup refusal, so the registration log line for a refused DB row carries the neutral message only
Final Attestation
Note
Medium Risk
Changes model registration, proxy model-management transactions, and license feature parsing; mis-counting or lock ordering could block legitimate writes or allow brief over-limit state across pods with mismatched config.
Overview
Caps
heuristic_v2complexity auto-routers at one unless a signed airgapped license includesallowed_features: auto_router; API-only license verification does not lift the cap.Enforcement is layered so extra routers are not silently dropped under
ignore_invalid_deployments: config.yaml fails startup when over limit; Router registration rejects newcomers (edits keep their slot); model create/update/PATCH return 403 before persisting. The proxy passes a liveheuristic_v2_router_limitresolver intoRouterand treatsrouter_settings.heuristic_v2_router_limitas managed outside config.DB writes that would leave a row on
heuristic_v2under a limited license run in a transaction withpg_advisory_xact_lock, count other DB rows plus config.yaml routers, then publish config after commit. Team model list updates run after the row write so a refused slot does not mutate team ACLs.License verification now clears
airgapped_license_dataon expiry or failed verify so stale features cannot keep lifting the limit.Reviewed by Cursor Bugbot for commit 41f47eb. Bugbot is set up for automated code reviews on this repo. Configure here.