Skip to content

test(logging): isolate bridged call recorder per request - #51339

Merged
mateo-berri merged 2 commits into
mainfrom
litellm_fix_callback_test_isolation
Nov 14, 2026
Merged

mateo-berri merged 2 commits into
mainfrom
litellm_fix_callback_test_isolation

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Keep unrelated background work from making the bridged-call tests fail. The test now records only its own request without changing application behavior

Details

Summary

A delayed synchronous Responses log can reach the global recorder installed by the next test. Scope the recorder to each completion request with success_callback=[recorder], keeping the call-type, response, content and cost assertions unchanged

TLDR

Problem this solves

  • Earlier requests can contaminate the next test's recorder

How it solves it

  • Attach the recorder only to the request being checked

User Flow

Before, a maintainer can see an unrelated unit-test failure

  1. Run the bridged-call checks after the Responses summary checks
  2. A delayed result from the earlier request makes the check fail

After, the same check receives only the request it is testing

  1. Run the bridged-call checks after the Responses summary checks
  2. The check validates the current request and passes

Pre-Submission checklist

  • The existing regression test preserves all assertions
  • The affected test file passes locally
  • All required CI checks have finished
  • The diff fixes one test-isolation problem
  • Automated reviews have finished at the latest commit

Screenshots / Proof of Fix

E2E exception at dc5e7d2

Only test-recorder wiring changes. Both non-streaming callers keep their existing assertions. No application code, API semantics, provider behavior or logging implementation changes, so focused test proof covers the entire diff. Live proxy/provider e2e was skipped

Fresh detached worktrees compare current main 454424c36c3be559fabafd2647406b792de7d2e5 with refreshed head dc5e7d2ee094954c268e7ba356eb66d3e17dc837. With the existing ChatGPT text test immediately before the bridged-call check and a 0.5-second executor delay, base fails 3/3 times with ('responses', 'responses') instead of ('completion', 'completion'). Head passes 3/3 times

Without delay injection, head passes 60/60 runs using four parallel pytest processes and hash seed 50408. The affected file and price-map tests pass all 364 cases, including the 258 callback cases. make check passes, and all 565 assertion AST nodes remain unchanged. No call-type filtering, queue skipping, sleeps or retries were added to the test

The previous CI failure on duplicate gemini/gemini-decision-1 keys was pre-existing on main, reproduced at unchanged base 7461a996cc. The upstream fix #51341 is now merged and included through the main update. This PR still changes only the callback test file, with no cost-map edits

At this tip, all 96 CI checks pass. Greptile review 40920151 is 5/5, Cursor Bugbot review 5869176263 reports no new issues, and the final review-thread sweep found no unresolved threads

Reproduce the delayed-executor check

Use an already bootstrapped checkout at either revision. Save the following diagnostic plugin outside the checkout as delay_executor_plugin.py. Its delay is fault injection only and is not part of the committed fix

import time


def pytest_configure(config):
    from litellm.litellm_core_utils.thread_pool_executor import executor
    original_submit = executor.submit

    def late_submit(fn, *args, **kwargs):
        def late():
            time.sleep(0.5)
            return fn(*args, **kwargs)
        return original_submit(late)

    executor.submit = late_submit

Set QA_ROOT to the directory containing that plugin and run this sequence three times from each checkout root

PYTHONPATH="$PWD:$QA_ROOT" PYTHONHASHSEED=50408 LITELLM_LOCAL_MODEL_COST_MAP=True \
  .venv/bin/python -m pytest -p no:cacheprovider -p no:randomly -q -o addopts= \
  -p delay_executor_plugin \
  tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py::test_responses_text_reaches_the_codex_backend_whole \
  'tests/unit/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py::test_bridged_chat_call_is_logged_with_the_callers_call_type[openai-responses-only-completion]'

For the natural-scheduling check, omit -p delay_executor_plugin and repeat the same two-test sequence 60 times at head

Run the affected file, price-map regression checks and repository gates

PYTHONPATH="$PWD" LITELLM_LOCAL_MODEL_COST_MAP=True .venv/bin/python -m pytest \
  tests/unit/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py \
  tests/unit/test_model_prices_and_context_window.py \
  -p no:randomly -q -o addopts=
make check

Taxonomy audit, T1 and T5. Every assertion remains intact, and the changed test no longer installs a process-global recorder

Link to Devin session: https://app.devin.ai/sessions/6784ce00e6f841d5952aad26f4b817b4
Open in Devin Desktop: https://app.devin.ai/desktop/session/6784ce00e6f841d5952aad26f4b817b4?variant=devin
Requested by: @mateo-berri


Note

Low Risk
Test-only callback wiring change with no application or logging behavior modifications.

Overview
Fixes test isolation for test_bridged_chat_call_is_logged_with_the_callers_call_type by no longer wiring the call recorder through litellm.callbacks.

The recorder is attached only on the completion under test via success_callback=[recorder] on both litellm.completion and litellm.acompletion, so delayed logging from earlier tests cannot hit the global callback list. All existing assertions (call type, response shape, content, and cost) are unchanged.

Reviewed by Cursor Bugbot for commit dc5e7d2. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@veria-ai

veria-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This test-only change appears safe to merge.

Summary

This PR attaches the bridged-call test recorder to each request instead of installing it globally. Both callers retain their existing checks for call type, response, content and cost. No actionable issues were found.

  • The bridged-call test records logs only for the request it checks.

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit dc5e7d2. Configure here.

@mateo-berri
mateo-berri enabled auto-merge (squash) November 12, 2026 04:40
@mateo-berri
mateo-berri requested a review from a team November 12, 2026 04:47
@mateo-berri
mateo-berri merged commit c6aa2a3 into main Nov 14, 2026
100 checks passed
@mateo-berri
mateo-berri deleted the litellm_fix_callback_test_isolation branch November 14, 2026 05:34
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