Skip to content

[Fix] Failure callbacks silently skipped when customLogger not initialized#24826

Merged
ishaan-berri merged 2 commits intomainfrom
litellm_/dazzling-jackson
Mar 31, 2026
Merged

[Fix] Failure callbacks silently skipped when customLogger not initialized#24826
ishaan-berri merged 2 commits intomainfrom
litellm_/dazzling-jackson

Conversation

@yuneng-berri
Copy link
Copy Markdown
Collaborator

Summary

Failure Path (Before Fix)

The sync and async failure handlers in litellm_logging.py guarded plain-function callback dispatch with customLogger is not None. However, customLogger is a module-level global initialized to None and only set to a CustomLogger() instance inside the success handler path. If a request failed without any prior successful request in the process, customLogger stayed None and the failure callback (e.g. Router's async_deployment_callback_on_failure for RPM tracking) was silently skipped.

Fix

Initialize customLogger on demand in both the sync and async failure handlers, matching the pattern already used in the success handlers.

Testing

  • test_call_router_callbacks_on_failure now passes (was consistently failing in CI)
  • test_call_router_callbacks_on_success continues to pass

Type

🐛 Bug Fix

… fire

The sync and async failure handlers guarded plain-function callbacks with
`customLogger is not None`, but customLogger was only initialized in the
success handler path. If a request failed without any prior success in the
process, the failure callback was silently skipped.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 31, 2026 2:30am

Request Review

@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 sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq bot commented Mar 31, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing litellm_/dazzling-jackson (3308fb9) with main (632beb0)

Open in CodSpeed

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 31, 2026

Greptile Summary

This PR fixes a real bug where callable failure callbacks (both sync and async) were silently skipped whenever customLogger — a module-level global initialized to None — had not yet been set by a prior success path or set_callbacks. The fix applies on-demand lazy initialization of customLogger in both the sync and async failure handlers, matching the pattern already present in the async success handler.

Key changes:

  • failure_handler (sync): replaced if callable(callback) and customLogger is not None with if callable(callback): + lazy customLogger = CustomLogger() guard
  • async_failure_handler (async): same change applied

Remaining inconsistencies (not introduced by this PR):

  • pre_call (line 1077) and the sync success handler (line 2421) still use the old customLogger is not None pattern, which can silently skip callable callbacks under the same conditions this PR addresses
  • No test files were modified in this PR — the referenced passing tests (test_call_router_callbacks_on_failure) are separate evidence of correctness

Confidence Score: 4/5

Safe to merge; the targeted fix is correct, but two analogous silent-skip sites remain unfixed in pre_call and the sync success handler

The fix is correct and directly addresses the stated bug with the appropriate lazy-init pattern. Score is 4 rather than 5 because two peer code paths (pre_call at line 1077 and sync success at line 2421) retain the same customLogger is not None pattern that this PR was created to eliminate, leaving them susceptible to the same class of silent callback skipping.

litellm/litellm_core_utils/litellm_logging.py — lines 1077 and 2421 still use the unfixed pattern

Important Files Changed

Filename Overview
litellm/litellm_core_utils/litellm_logging.py Fixes silent skip of callable failure callbacks when customLogger is None; two analogous old-pattern sites remain at pre_call (line 1077) and sync success handler (line 2421)

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Request fails] --> B[failure_handler / async_failure_handler]
    B --> C{Iterate callbacks}
    C --> D{isinstance CustomLogger?}
    D -- Yes --> E[callback.log_failure_event / async_log_failure_event]
    D -- No --> F{callable callback?}
    F -- No --> C
    F -- Yes --> G{customLogger is None?}
    G -- Yes BEFORE FIX --> H[❌ Silent skip]
    G -- Yes AFTER FIX --> I[customLogger = CustomLogger]
    I --> J[customLogger.log_event / async_log_event]
    G -- No --> J
    E --> C
    J --> C

    style H fill:#f44,color:#fff
    style I fill:#4a4,color:#fff
    style J fill:#4a4,color:#fff
Loading

Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Mar 31, 2026

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
29375658 Triggered JSON Web Token 3308fb9 tests/test_litellm/proxy/auth/test_handle_jwt.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@ishaan-berri ishaan-berri merged commit ead71c9 into main Mar 31, 2026
94 of 108 checks passed
@ishaan-berri ishaan-berri deleted the litellm_/dazzling-jackson branch March 31, 2026 02:50
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.

3 participants