fix(router): allow usage-based routing to use a deployment up to its rpm limit - #33033
Conversation
…rpm limit The lowest_tpm_rpm v1 and v2 strategies excluded a deployment from selection when rpm_dict[item] + 1 >= rpm, i.e. one request before the configured limit was reached. A request that brings usage to exactly the rpm limit is within budget: the TPM check in the same function uses strict '>', the sibling lowest_cost and lowest_latency strategies use 'item_rpm + 1 > rpm', and the rpm enforcement in pre_call_check raises only when the incremented count exceeds the limit. Change both handlers to 'rpm_dict[item] + 1 > _deployment_rpm' so a deployment stays selectable until its rpm limit, preventing premature exclusion, unnecessary fallbacks and wasted capacity. Adds boundary regression tests for both v1 and v2.
Greptile SummaryThis PR fixes an off-by-one in the RPM eligibility check in both
Confidence Score: 5/5Minimal, well-tested change to routing logic with no behavioral regressions; safe to merge. Two single-character operator changes in the routing filter, each backed by new parameterized tests that specifically exercise the boundary conditions. The fix is consistent with how the TPM check and sibling strategies already behave, and the tests are pure mock tests that will run correctly in CI. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/router_strategy/lowest_tpm_rpm.py | One-character fix: >= → > in RPM filter so a deployment stays selectable until a request would strictly exceed its rpm limit, aligning with the TPM check in the same function. |
| litellm/router_strategy/lowest_tpm_rpm_v2.py | Same >= → > fix applied to the v2 RPM filter; change is minimal and correct. |
| tests/test_litellm/router_strategy/test_lowest_tpm_rpm.py | New test file with parameterized boundary tests for both v1 and v2 strategies covering current_rpm at {8, 9, 10, 11} against a limit of 10; uses only mocked DualCache with no real network calls, consistent with repository rules. |
Reviews (1): Last reviewed commit: "fix(router): allow usage-based routing t..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Heads up: the red |
Relevant issues
Fixes #33032
Pre-Submission checklist
Screenshots / Proof of Fix
Pure routing-logic off-by-one, reproducible offline (no keys/network).
Before (base
3d63eda) — deployment excluded one request early:After (this PR):
New boundary regression tests for both v1 and v2 (fail on base, pass here):
Type
🐛 Bug Fix
Changes
Change the RPM filter in
lowest_tpm_rpm(v1) andlowest_tpm_rpm_v2fromrpm_dict[item] + 1 >= _deployment_rpmtorpm_dict[item] + 1 > _deployment_rpm, so a deployment stays selectable until a request would actually exceed itsrpmlimit. This matches the TPM check in the same function (strict>), the siblinglowest_cost/lowest_latencystrategies (item_rpm + 1 > rpm), and thepre_call_checkenforcement. Prevents premature exclusion, unnecessary fallbacks and wasted capacity.cc @ishaan-jaff @krrish-berri-2 — one-character boundary fix in the two usage-based routers with regression tests. Thanks for maintaining LiteLLM!