Skip to content

fix(router): clamp least_busy request counter at zero (salvage of #25393, credit @mango766) - #34444

Draft
Bartok9 wants to merge 1 commit into
BerriAI:litellm_oss_daily_2026_07_20from
Bartok9:salvage/least-busy-clamp-credit-mango766
Draft

fix(router): clamp least_busy request counter at zero (salvage of #25393, credit @mango766)#34444
Bartok9 wants to merge 1 commit into
BerriAI:litellm_oss_daily_2026_07_20from
Bartok9:salvage/least-busy-clamp-credit-mango766

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 23, 2026

Copy link
Copy Markdown

Salvage

Rebases and lands the core fix from #25393 by @mango766 (also adjacent to #25325 by @rudra717). Originals went quiet / CONFLICTING against current tips.

Problem

least_busy increments the per-deployment counter pre-call and decrements on success/failure. Under races the count can go negative, after which that deployment always wins the min and starves the rest.

Fix

Clamp every decrement with max(request_count_value - 1, 0) on sync/async success and failure handlers.

Tests

tests/test_litellm/router_strategy/test_least_busy_clamp.py

Credit

Original approach and issue framing: @mango766 (#25393). Related clamp lwork: @rudra717 (#25325).

AI-assisted rebuild; human-reviewed. Does not include the tie-break jitter portion of #25393 — clamp only for a clean micro-merge.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/router_strategy/least_busy.py 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Bartok9
Bartok9 force-pushed the salvage/least-busy-clamp-credit-mango766 branch from 8b3e272 to 8b376c0 Compare August 9, 2026 23:40
@CLAassistant

CLAassistant commented Aug 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Bartok9
Bartok9 changed the base branch from litellm_oss_daily_2026_07_20 to main August 9, 2026 23:46
@Bartok9
Bartok9 force-pushed the salvage/least-busy-clamp-credit-mango766 branch from 8b376c0 to c807497 Compare August 9, 2026 23:58
@Bartok9
Bartok9 changed the base branch from main to litellm_internal_staging August 9, 2026 23:58
@codspeed-hq

codspeed-hq Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing Bartok9:salvage/least-busy-clamp-credit-mango766 (debbca5) with main (6a919ae)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_oss_daily_2026_07_20 (5d4c4d0) during the generation of this report, so main (6a919ae) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Bartok9
Bartok9 force-pushed the salvage/least-busy-clamp-credit-mango766 branch from 1c1ca57 to 71fc798 Compare August 10, 2026 23:13
@Bartok9
Bartok9 changed the base branch from litellm_internal_staging to litellm_oss_daily_2026_07_20 August 10, 2026 23:13
@Bartok9
Bartok9 changed the base branch from litellm_oss_daily_2026_07_20 to litellm_internal_staging August 10, 2026 23:16
@Bartok9
Bartok9 force-pushed the salvage/least-busy-clamp-credit-mango766 branch from 71fc798 to debbca5 Compare August 10, 2026 23:20
@Bartok9
Bartok9 changed the base branch from litellm_internal_staging to litellm_oss_daily_2026_07_20 August 10, 2026 23:37
@Bartok9
Bartok9 force-pushed the salvage/least-busy-clamp-credit-mango766 branch from debbca5 to 71fc798 Compare August 10, 2026 23:38
@Bartok9

Bartok9 commented Aug 18, 2026

Copy link
Copy Markdown
Author

Sera doctor_ci: triage of 3 red checks:

  • osv-scan — pre-existing upstream lockfile vulns (per culture); not ours, not chasing.
  • lint / LiteLLM LintingCan't find action.yml...cache-prisma-binaries. Upstream workflow references .github/actions/cache-prisma-binaries which checkout did not resolve (upstream CI infra bug, not our diff).
  • misc / Run tests — 2 failures in tests/test_litellm/interactions/test_openapi_compliance.py: test_status_enum_values (daily branch OpenAPI spec now includes queued but test expects old set) and test_content_schema_uses_discriminator (daily spec now has discriminator). Both are daily-branch drift, addressed by fix(interactions): add queued to Interaction status enum (OSS daily) #34318 when it lands. Our PR touches least_busy router only — zero overlap with these tests.

CI last ran 2026-08-10 on stale daily tip. No code change needed here; will re-evaluate after #34318 lands. Agent-Owner: sera

@Bartok9
Bartok9 force-pushed the salvage/least-busy-clamp-credit-mango766 branch from 71fc798 to 5cfc1dd Compare August 19, 2026 23:11
@Bartok9

Bartok9 commented Aug 20, 2026

Copy link
Copy Markdown
Author

doctor_ci 2026-08-20: triage of 2 red checks on this draft.

This PR's own code and test_least_busy_clamp.py are unaffected. No code change needed from our side.

@Bartok9

Bartok9 commented Aug 21, 2026

Copy link
Copy Markdown
Author

Doctor watch (2026-08-21): misc / Run tests failed, but our change is isolated to least_busy.py (4-line clamp) + a trivial max() test that does not import litellm. The base branch litellm_oss_daily_2026_07_20 is the latest daily but is stale; this looks like flake / pre-existing base-drift on the daily branch, not a real conflict in our diff. osv-scan is pre-existing upstream lockfile vuln. No code change needed — will re-check on next watch.

Signed-off-by: Bartok9 <259807879+Bartok9@users.noreply.github.com>
@Bartok9
Bartok9 force-pushed the salvage/least-busy-clamp-credit-mango766 branch from 5cfc1dd to 7bd39c5 Compare August 22, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants