Repository navigation
fix(logging): preserve callback order in get_combined_callback_list - #33008
6 commits merged into
Conversation
chore(ci): promote internal staging to main
|
@greptileai review |
Greptile SummaryThis PR fixes a non-deterministic callback ordering bug in
Confidence Score: 5/5Safe to merge — a minimal, targeted one-line change with no side effects for callers that have no duplicate callbacks. The production change is a single-line swap of a well-understood Python idiom. The dict.fromkeys form is guaranteed by the language spec to preserve insertion order and requires no new dependencies. The test suite covers the key ordering scenarios and demonstrates the fix behaves correctly. The one test whose comment overstates its regression-detection ability is a documentation concern, not a correctness issue. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/litellm_logging.py | One-line fix replacing list(set(...)) with list(dict.fromkeys(...)) to preserve insertion order during callback deduplication. |
| tests/test_litellm/litellm_core_utils/test_litellm_logging.py | Adds TestGetCombinedCallbackListOrder with 8 tests covering first-occurrence ordering, disjoint inputs, subset cases, multiple duplicates, None early-return path, and an empty-input smoke test. |
Reviews (1): Last reviewed commit: "test(logging): assert get_combined_callb..." | Re-trigger Greptile
Greptile SummaryReplaces the non-deterministic
Confidence Score: 5/5Safe to merge — the change is a single-line targeted fix with no impact on non-duplicate callback lists and strictly better behavior for duplicate ones. The fix is minimal and correct: No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/litellm_logging.py | Single-line fix replacing list(set(...)) with list(dict.fromkeys(...)) in get_combined_callback_list to preserve insertion order during deduplication — correct and safe |
| tests/test_litellm/litellm_core_utils/test_litellm_logging.py | Adds TestGetCombinedCallbackListOrder class with 8 regression tests covering first-occurrence ordering, disjoint inputs, subset relationships, multiple duplicates, None dynamic path, and determinism across 100 calls; no network calls, uses existing logging_obj fixture |
Reviews (2): Last reviewed commit: "test(logging): assert get_combined_callb..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
assassindiv
left a comment
There was a problem hiding this comment.
The core logic change in litellm/litellm_core_utils/litellm_logging.py is sound. Replacing list(set(...)) with list(dict.fromkeys(...)) correctly ensures that callback deduplication preserves the original insertion order, preventing potential race conditions for downstream callbacks that depend on a deterministic execution order.
The accompanying regression tests in tests/test_litellm/litellm_core_utils/test_litellm_logging.py provide good coverage for the expected deduplication order behaviors.
One note on test_is_deterministic_across_calls: since PYTHONHASHSEED remains constant within the scope of a single process execution, list(set(...)) would naturally return a consistent order across 100 iterations here. While the test is still valuable as a sanity check and documentation for the desired behavior, the other five ordering assertions are what effectively validate the cross-process fix.
Overall, the implementation is correct and ready to merge.
|
Can someone take a look when you have a chance? |
2 similar comments
|
Can someone take a look when you have a chance? |
|
Can someone take a look when you have a chance? |
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
|
Greptile P2 acknowledged on 07-15 (the determinism test coverage is already in place; not reshaping the logging path for a stale-block warning). All threads resolved. CI green. |
chore(ci): promote internal staging to main
|
All Greptile P2 threads resolved (the determinism test already covers the ordering this PR targets). CI green. Standing by for review. |
|
Synced with upstream (was 92+ behind, now 0). CI now FAILURE on osv-scan (mcp==1.26.0 has 3 high-severity CVEs, pre-existing dep in uv.lock). The fix itself landed in upstream #33005 already — this PR is now functionally redundant. Can close as superseded if you want. |
|
Re-synced with upstream (was 92 behind, now 0). CI still FAILURE on osv-scan (mcp==1.26.0 has 3 high-severity CVEs — pre-existing dep in uv.lock). The fix itself is already in upstream #33005, so this PR is functionally redundant. Can be closed as superseded. |
chore(ci): promote internal staging to main
7ac5172
Relevant issues
Fixes #33003
Linear ticket
Pre-Submission checklist
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Before the fix (source reverted):
(The 4 that "pass" on the unpatched code are either exercising the early-return path that doesn't go through the buggy line, or are order-equality assertions whose specific inputs happened to land in set-iteration-order that matched the expected order in this single process — the version-determinism test that runs 100 iterations kills the underlying non-determinism property.)
After the fix:
The full 117-test litellm_logging test file is green with the fix applied.
Type
Changes
litellm/litellm_core_utils/litellm_logging.py:3073— replacedlist(set(dynamic_success_callbacks + global_callbacks))withlist(dict.fromkeys(dynamic_success_callbacks + global_callbacks)).dict.fromkeysis the canonical Python idiom for "dedupe while preserving insertion order" (language-spec guarantee since CPython 3.7;pyproject.toml'srequires-python = ">=3.10, <3.14"is well above).tests/test_litellm/litellm_core_utils/test_litellm_logging.py— addedTestGetCombinedCallbackListOrderclass with 8 tests covering: first-occurrence-wins, disjoint inputs, both subset directions, multiple duplicates,dynamic=Noneearly-return path, version-determinism across 100 invocations, and an empty-input smoke.Risks
Minimal. The fix changes behavior only of the dedup path; non-duplicate callers are unaffected (
list(concat)of a list with no duplicates is the same). For callbacks that already ignored order: identical observable behavior. For callbacks that happened to rely on the buggy random order: they now get a stable order matching input order — strictly better.Future work
# [TODO]: move this to being an async log stream event functionbreadcrumbs inlitellm_logging.py:2558and:2589are real refactor breadcrumbs from a previous logging refactor — out of scope here.CustomLoggerbase class is a larger scaffolding effort — out of scope here.