Repository navigation
fix(proxy): honor caller litellm_session_id in spend log session_id - #41004
deepanshupal wants to merge 4 commits into
Conversation
The default path of _get_session_id_for_spend_log never consulted kwargs['litellm_session_id'], so a caller-supplied session was overwritten by the per-call trace id and LiteLLM_SpendLogs.session_id could never group by litellm_session_id. Prefer it after the batch lifecycle's deterministic session: when the caller sent no session the value is only the derived trace-id copy, so sessionless requests are unchanged. Fixes BerriAI#40851
Greptile SummaryThis PR updates spend-log session resolution so a supplied
Confidence Score: 4/5The behavior appears safe, but the redundant test docstrings must be removed to satisfy the repository’s explicit source-comment requirement Session precedence and fallback behavior are adequately covered, with only a repository-guidance violation in the added test docstrings Files Needing Attention: tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py
|
| Filename | Overview |
|---|---|
| litellm/proxy/spend_tracking/spend_tracking_utils.py | Adds caller session precedence after omit and batch handling without changing trace fallbacks |
| tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py | Adds meaningful precedence regressions, but includes two unnecessary explanatory docstrings |
Reviews (1): Last reviewed commit: "fix(proxy): harden spend log session pre..." | Re-trigger Greptile
| assert session_id == "batch-uid-1" | ||
|
|
||
|
|
||
| def test_caller_litellm_session_id_wins_over_the_per_request_trace_id(): |
There was a problem hiding this comment.
Redundant test comments These docstrings only repeat clear test names, violating the repository directive against unnecessary comments. Remove both before merging
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
#40856 was reopened against the release base, and this PR carries the same head against main. Which base do you want this fix on? I'll keep that one and close the duplicate. |
|
Two current checks are unrelated to this spend-log diff. OSV reports the existing |
|
Closing in favour of #44199, which has the same change rebased on main. |
Summary
Fixes #40851. Supersedes #40856 (auto-closed when litellm_internal_staging was merged into main and deleted).
When a caller passes litellm_session_id, the spend log's session_id was still taken from the per-call trace id (standard_logging_payload.trace_id, then litellm_trace_id, then a fresh uuid), so LiteLLM_SpendLogs.session_id never reflected the caller's session and grouping/filtering by session was broken.
The default path of _get_session_id_for_spend_log never consulted kwargs["litellm_session_id"]. Preferring it is safe: when the caller sends no session, get_litellm_params only derives it from session_id/trace_id, so the returned value equals the trace id that won before - sessionless requests are unchanged, and a real caller session now reaches the spend log.
Deliberate behavior preserved: the omit policy still honors only metadata.session_id (the Langfuse key), and the batch lifecycle's deterministic batch-id session still outranks everything so the create row and the poller's cost row stay grouped.
Testing
Prepared with AI assistance; testing and review by me.