Skip to content

[litellm-agent] Staging → litellm_internal_staging (5/6/2026) - #27250

Closed
oss-pr-review-agent-shin[bot] wants to merge 2 commits into
litellm_internal_stagingfrom
litellm_agent_oss_staging_05_06_2026
Closed

[litellm-agent] Staging → litellm_internal_staging (5/6/2026)#27250
oss-pr-review-agent-shin[bot] wants to merge 2 commits into
litellm_internal_stagingfrom
litellm_agent_oss_staging_05_06_2026

Conversation

@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor

Automated staging PR created by litellm-agent.

This branch collects PRs approved by the agent on 5/6/2026.

pnookala-godaddy and others added 2 commits May 5, 2026 13:49
Iterate user/key/team/team_member/org/end_user/tag spend dicts in sorted
order inside each Prisma transaction so concurrent pods acquire row locks
in the same order, avoiding PostgreSQL deadlocks under load.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ pnookala-godaddy
❌ oss-pr-review-agent-shin[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR applies a consistent sorted iteration order to all spend-update transaction loops across the proxy's DB write layer, so concurrent pods acquire row locks in the same order and avoid PostgreSQL deadlocks. A parametrized mock test verifies the sorted order for all 8 spend buckets (user, key, team, team_member, org, end_user, tag, agent).

  • Six loops in db_spend_update_writer.py and one in utils.py now call sorted(transactions.items()) before iterating, with inline comments explaining the deadlock-prevention rationale.
  • The composite key format for team_member_list_transactions ("team_id::<v>::user_id::<v>") means a lexicographic string sort is equivalent to a (team_id, user_id) tuple sort, which is correctly noted in the comment.
  • The new test is mock-only and consistent with the repository's CI rule for the tests/test_litellm/ folder.

Confidence Score: 5/5

This PR is safe to merge — it changes only iteration order within existing transactions, not the data written, and all paths are covered by mock tests.

The change is a targeted, low-risk addition of sorted() to dictionary iteration in spend-flush loops. The sort is deterministic, doesn't alter the values written, and is backed by a comprehensive parametrized test suite. The composite-key sort assumption for team_member entries is correct given the fixed-length prefix format. No new DB paths, no API changes, and no real network calls in the tests.

No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/db/db_spend_update_writer.py Adds sorted() to 5 spend-update transaction loops (user, key, team, team_member, org) and the shared _update_entity_spend_in_db helper to enforce a consistent row-lock acquisition order and prevent cross-pod PostgreSQL deadlocks.
litellm/proxy/utils.py Applies the same sorted() fix to the end_user spend loop in ProxyUpdateSpend.update_end_user_spend, completing deadlock prevention coverage across all spend buckets.
tests/test_litellm/proxy/db/test_db_spend_update_writer.py Adds a parametrized mock-only test covering all 8 spend buckets to assert that _commit_spend_updates_to_db iterates each bucket in sorted order; no real network calls are made.

Reviews (1): Last reviewed commit: "Merge PR #27221 into agent staging branc..." | Re-trigger Greptile

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor Author

🤖 litellm-agent: Merged into staging branch litellm_agent_oss_staging_05_06_2026. Staging PR: #27250


Triage Summary
Sorts dictionary iteration order by ID before issuing batched spend-update writes in db_spend_update_writer.py and proxy/utils.py, ensuring consistent lock acquisition order across pods to prevent database deadlocks. Adds 143 lines of parametrized tests covering user, key, team, team_member, and org transaction buckets to verify sorted ordering is preserved.

Merge Confidence: 5/5 ✅ READY
Ready to ship.

All checks green. Greptile 5/5, no blocking pattern findings, CircleCI passed.

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