Skip to content

fix: improve Langfuse test isolation to prevent flaky failures#21093

Merged
krrishdholakia merged 1 commit intoBerriAI:litellm_oss_staging_02_14_2026from
jquinter:fix/langfuse-test-isolation-clean
Feb 14, 2026
Merged

fix: improve Langfuse test isolation to prevent flaky failures#21093
krrishdholakia merged 1 commit intoBerriAI:litellm_oss_staging_02_14_2026from
jquinter:fix/langfuse-test-isolation-clean

Conversation

@jquinter
Copy link
Contributor

Problem

The test_log_langfuse_v2_handles_null_usage_values test was intermittently failing in CI with:

AssertionError: Expected 'generation' to have been called once. Called 0 times.

The test passed consistently locally but failed randomly in CI, blocking builds.

Root Cause

The test was creating fresh mocks to avoid state pollution, but this didn't fully isolate from the setUp method's mock configuration, leading to inconsistent behavior in CI.

Fix

Instead of creating entirely new mocks, properly reset the existing setUp mocks using .reset_mock():

self.mock_langfuse_client.reset_mock()
self.mock_langfuse_trace.reset_mock()
self.mock_langfuse_generation.reset_mock()

This ensures clean mock state while maintaining proper mock chain configuration.

Testing

poetry run pytest tests/test_litellm/integrations/test_langfuse.py::TestLangfuseUsageDetails::test_log_langfuse_v2_handles_null_usage_values -v

✅ Test passes consistently

Note

This is a clean version of PR #21073, which accidentally included unrelated changes from other branches.

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Feb 13, 2026

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

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 13, 2026 5:45pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

This PR fixes a flaky test (test_log_langfuse_v2_handles_null_usage_values) by replacing the pattern of creating entirely fresh mock objects with resetting the existing setUp mocks via reset_mock(). The original approach created new mocks that bypassed the setUp mock chain, but this didn't fully isolate from setUp's configuration, causing intermittent CI failures where generation was never called.

  • Replaces fresh mock creation with reset_mock() on self.mock_langfuse_client, self.mock_langfuse_trace, and self.mock_langfuse_generation
  • Re-establishes the mock chain (trace -> generation, trace -> span) after reset
  • Updates assertions to reference self.mock_langfuse_* instead of local mock_* variables
  • Minor style note: reset_mock() does not clear the side_effect on child mocks set during setUp, so the return_value set on self.mock_langfuse_client.trace is technically shadowed by the surviving side_effect — but this is harmless since both return the same object

Confidence Score: 4/5

  • This PR is safe to merge — it only modifies test code and the functional behavior is correct.
  • Score of 4 reflects that this is a test-only change that correctly addresses the flaky test. The mock reset approach is sound and the test assertions are properly updated. One minor point: the side_effect from setUp survives the reset and shadows the newly-set return_value, but this is harmless since both return the same mock object. No production code is affected.
  • No files require special attention — tests/test_litellm/integrations/test_langfuse.py has a minor style improvement opportunity but no functional issues.

Important Files Changed

Filename Overview
tests/test_litellm/integrations/test_langfuse.py Refactors test mock setup in test_log_langfuse_v2_handles_null_usage_values to use reset_mock() on existing setUp mocks instead of creating fresh mocks. The change is functionally correct and should fix the CI flakiness. Minor note: reset_mock() does not clear side_effect on child mocks, but this is harmless since the side_effect returns the same object.

Sequence Diagram

sequenceDiagram
    participant Test as Test Method
    participant Client as mock_langfuse_client
    participant Trace as mock_langfuse_trace
    participant Gen as mock_langfuse_generation

    Note over Test,Gen: Before (Original - Fresh Mocks)
    Test->>Test: Create new mock_client, mock_trace, mock_generation
    Test->>Test: logger.Langfuse = mock_client
    Test->>Test: call _log_langfuse_v2()
    Test->>Client: trace() → sometimes fails due to setUp interference

    Note over Test,Gen: After (Fixed - Reset Existing Mocks)
    Test->>Client: reset_mock()
    Test->>Trace: reset_mock()
    Test->>Gen: reset_mock()
    Test->>Trace: Re-wire generation.return_value
    Test->>Client: Re-wire trace.return_value
    Test->>Test: call _log_langfuse_v2()
    Test->>Client: trace() → reliably returns mock_langfuse_trace
    Client->>Trace: generation() → returns mock_langfuse_generation
    Test->>Trace: assert generation.assert_called_once()
Loading

Last reviewed commit: 610664f

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +260 to +272
self.mock_langfuse_client.reset_mock()
self.mock_langfuse_trace.reset_mock()
self.mock_langfuse_generation.reset_mock()

# Re-setup the trace and generation chain with clean state
self.mock_langfuse_generation.trace_id = "test-trace-id"
mock_span = MagicMock()
mock_span.end = MagicMock()

mock_trace.generation.return_value = mock_generation
mock_trace.span.return_value = mock_span

mock_client = MagicMock()
mock_client.trace.return_value = mock_trace

# Use our fresh mock client
self.logger.Langfuse = mock_client
self.mock_langfuse_trace.span.return_value = mock_span
self.mock_langfuse_trace.generation.return_value = self.mock_langfuse_generation

# Ensure trace returns our mock
self.mock_langfuse_client.trace.return_value = self.mock_langfuse_trace
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant return_value due to active side_effect

reset_mock() on a parent MagicMock resets call counts recursively but does not clear side_effect or return_value on child mocks. The setUp method sets self.mock_langfuse_client.trace.side_effect = _trace_side_effect (line 56), and this side_effect survives the reset_mock() call on line 260.

When both side_effect and return_value are set on a mock, Python's unittest.mock gives side_effect precedence. So the return_value set on line 272 is effectively ignored — the side_effect from setUp is what actually runs when .trace() is called.

This happens to work correctly because _trace_side_effect returns self.mock_langfuse_trace, which is the same object being set as return_value. However, for clarity and to avoid confusion for future maintainers, consider explicitly clearing the side_effect:

Suggested change
self.mock_langfuse_client.reset_mock()
self.mock_langfuse_trace.reset_mock()
self.mock_langfuse_generation.reset_mock()
# Re-setup the trace and generation chain with clean state
self.mock_langfuse_generation.trace_id = "test-trace-id"
mock_span = MagicMock()
mock_span.end = MagicMock()
mock_trace.generation.return_value = mock_generation
mock_trace.span.return_value = mock_span
mock_client = MagicMock()
mock_client.trace.return_value = mock_trace
# Use our fresh mock client
self.logger.Langfuse = mock_client
self.mock_langfuse_trace.span.return_value = mock_span
self.mock_langfuse_trace.generation.return_value = self.mock_langfuse_generation
# Ensure trace returns our mock
self.mock_langfuse_client.trace.return_value = self.mock_langfuse_trace
# Reset the mock to ensure clean state
self.mock_langfuse_client.reset_mock()
self.mock_langfuse_trace.reset_mock()
self.mock_langfuse_generation.reset_mock()
# Re-setup the trace and generation chain with clean state
self.mock_langfuse_generation.trace_id = "test-trace-id"
mock_span = MagicMock()
mock_span.end = MagicMock()
self.mock_langfuse_trace.span.return_value = mock_span
self.mock_langfuse_trace.generation.return_value = self.mock_langfuse_generation
# Clear side_effect from setUp so return_value takes effect
self.mock_langfuse_client.trace.side_effect = None
self.mock_langfuse_client.trace.return_value = self.mock_langfuse_trace
self.logger.Langfuse = self.mock_langfuse_client

The test was creating fresh mocks but not fully isolating from setUp state,
causing intermittent CI failures with 'Expected generation to be called once.
Called 0 times.'

Instead of creating fresh mocks, properly reset the existing setUp mocks to
ensure clean state while maintaining proper mock chain configuration.
@jquinter jquinter force-pushed the fix/langfuse-test-isolation-clean branch from 610664f to 74a2cbd Compare February 13, 2026 17:44
@krrishdholakia krrishdholakia changed the base branch from main to litellm_oss_staging_02_14_2026 February 14, 2026 06:54
@krrishdholakia krrishdholakia merged commit 51dcdde into BerriAI:litellm_oss_staging_02_14_2026 Feb 14, 2026
7 of 17 checks passed
Sameerlite pushed a commit that referenced this pull request Feb 16, 2026
The test was creating fresh mocks but not fully isolating from setUp state,
causing intermittent CI failures with 'Expected generation to be called once.
Called 0 times.'

Instead of creating fresh mocks, properly reset the existing setUp mocks to
ensure clean state while maintaining proper mock chain configuration.
sameetn pushed a commit to sameetn/litellm that referenced this pull request Feb 16, 2026
…AI#21093)

The test was creating fresh mocks but not fully isolating from setUp state,
causing intermittent CI failures with 'Expected generation to be called once.
Called 0 times.'

Instead of creating fresh mocks, properly reset the existing setUp mocks to
ensure clean state while maintaining proper mock chain configuration.
krrishdholakia added a commit that referenced this pull request Feb 16, 2026
* fix: SSO PKCE support fails in multi-pod Kubernetes deployments

* fix: virutal key grace period from env/UI

* fix: refactor, race condition handle, fstring sql injection

* fix: add async call to avoid server pauses

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: add await in tests

* add modify test to perform async run

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix grace period with better error handling on frontend and as per best practices

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: as per request changes

* Update litellm/proxy/utils.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Fix errors when callbacks are invoked for file delete operations:

* Fix errors when callbacks are invoked for file operations

* Fix: pass deployment credentials to afile_retrieve in managed_files post-call hook

* Fix: bypass managed files access check in batch polling by calling afile_content directly

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: afile_retrieve returns unified ID for batch output files

* fix: batch retrieve returns unified input_file_id

* fix(chatgpt): drop unsupported responses params for Codex

Co-authored-by: Cursor <cursoragent@cursor.com>

* test(chatgpt): ensure Codex request filters unsupported params

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix deleted managed files returning 403 instead of 404

* Add comments

* Update litellm/proxy/utils.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: thread deployment model_info through batch cost calculation

batch_cost_calculator only checked the global cost map, ignoring
deployment-level custom pricing (input_cost_per_token_batches etc.).
Add optional model_info param through the batch cost chain and pass
it from CheckBatchCost.

* fix(deps): add pytest-postgresql for db schema migration tests

The test_db_schema_migration.py test requires pytest-postgresql but it was
missing from dependencies, causing import errors:

  ModuleNotFoundError: No module named 'pytest_postgresql'

Added pytest-postgresql ^6.0.0 to dev dependencies to fix test collection
errors in proxy_unit_tests.

This is a pre-existing issue, not related to PR #21277.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(test): replace caplog with custom handler for parallel execution

The cost calculation log level tests were failing when run with pytest-xdist
parallel execution because caplog doesn't work reliably across worker processes.
This causes "ValueError: I/O operation on closed file" errors.

Solution: Replace caplog fixture with a custom LogRecordHandler that directly
attaches to the logger. This approach works correctly in parallel execution
because each worker process has its own handler instance.

Fixes test failures in PR #21277 when running with --dist=loadscope.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(test): correct async mock for video generation logging test

The test was failing with AuthenticationError because the mock wasn't
intercepting the actual HTTP handler calls. This caused real API calls
with no API key, resulting in 401 errors.

Root cause: The test was patching the wrong target using string path
'litellm.videos.main.base_llm_http_handler' instead of using patch.object
on the actual handler instance. Additionally, it was mocking the sync
method instead of async_video_generation_handler.

Solution: Use patch.object with side_effect pattern on the correct
async handler method, following the same pattern used in
test_video_generation_async().

Fixes test failure in PR #21277 when running with --dist=loadscope.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(test): add cleanup fixture and no_parallel mark for MCP tests

Two MCP server tests were failing when run with pytest-xdist parallel
execution (--dist=loadscope):
- test_mcp_routing_with_conflicting_alias_and_group_name
- test_oauth2_headers_passed_to_mcp_client

Both tests showed assertion failures where mocks weren't being called
(0 times instead of expected 1 time).

Root cause: These tests rely on global_mcp_server_manager singleton
state and complex async mocking that doesn't work reliably with
parallel execution. Each worker process can have different state
and patches may not apply correctly.

Solution:
1. Added autouse fixture to clean up global_mcp_server_manager registry
   before and after each test for better isolation
2. Added @pytest.mark.no_parallel to these specific tests to ensure
   they run sequentially, avoiding parallel execution issues

This approach maintains test reliability while allowing other tests
in the file to still benefit from parallelization.

Fixes test failures exposed by PR #21277.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Regenerate poetry.lock with Poetry 2.3.2

Updated lock file to use Poetry 2.3.2 (matching main branch standard).
This addresses Greptile feedback about Poetry version mismatch.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Remove unused pytest import and add trailing newline

- Removed unused pytest import (caplog fixture was removed)
- Added missing trailing newline at end of file

Addresses Greptile feedback (minor style issues).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Remove redundant import inside test method

The module litellm.videos.main is already imported at the top of
the file (line 21), so the import inside the test method is redundant.

Addresses Greptile feedback (minor style issue).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Fix converse anthropic usage object according to v1/messages specs

* Add routing based on if reasoning is supported or not

* add fireworks_ai/accounts/fireworks/models/kimi-k2p5 in model map

* Removed stray .md file

* fix(bedrock): clamp thinking.budget_tokens to minimum 1024

Bedrock rejects thinking.budget_tokens values below 1024 with a 400
error. This adds automatic clamping in the LiteLLM transformation
layer so callers (e.g. router with reasoning_effort="low") don't
need to know about the provider-specific minimum.

Fixes #21297

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: improve Langfuse test isolation to prevent flaky failures (#21093)

The test was creating fresh mocks but not fully isolating from setUp state,
causing intermittent CI failures with 'Expected generation to be called once.
Called 0 times.'

Instead of creating fresh mocks, properly reset the existing setUp mocks to
ensure clean state while maintaining proper mock chain configuration.

* feat(s3): add support for virtual-hosted-style URLs (#21094)

Add s3_use_virtual_hosted_style parameter to support AWS S3 virtual-hosted-style URL format (bucket.endpoint/key) alongside the existing path-style format (endpoint/bucket/key).

This enables compatibility with S3-compatible services like MinIO and aligns with AWS S3 official terminology.

* Addressed greptile comments to extract common helpers and return 404

* Allow effort="max" for Claude Opus 4.6 (#21112)

* fix(aiohttp): prevent closing shared ClientSession in AiohttpTransport (#21117)

When a shared ClientSession is passed to LiteLLMAiohttpTransport,
calling aclose() on the transport would close the shared session,
breaking other clients still using it.

Add owns_session parameter (default True for backwards compatibility)
to AiohttpTransport and LiteLLMAiohttpTransport. When a shared session
is provided in http_handler.py, owns_session=False is set to prevent
the transport from closing a session it does not own.

This aligns AiohttpTransport with the ownership pattern already used
in AiohttpHandler (aiohttp_handler.py).

* perf(spend): avoid duplicate daily agent transaction computation (#21187)

* fix: proxy/batches_endpoints/endpoints.py:309:11: PLR0915 Too many statements (54 > 50)

* fix mypy

* Add doc for OpenAI Agents SDK with LiteLLM

* Add doc for OpenAI Agents SDK with LiteLLM

* Update docs/my-website/sidebars.js

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix mypy

* Update tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Add blog fffor Managing Anthropic Beta Headers

* Add blog fffor Managing Anthropic Beta Headers

* correct the time

* Fix: Exclude tool params for models without function calling support (#21125) (#21244)

* Fix tool params reported as supported for models without function calling (#21125)

JSON-configured providers (e.g. PublicAI) inherited all OpenAI params
including tools, tool_choice, function_call, and functions — even for
models that don't support function calling. This caused an inconsistency
where get_supported_openai_params included "tools" but
supports_function_calling returned False.

The fix checks supports_function_calling in the dynamic config's
get_supported_openai_params and removes tool-related params when the
model doesn't support it. Follows the same pattern used by OVHCloud
and Fireworks AI providers.

* Style: move verbose_logger to module-level import, remove redundant try/except

Address review feedback from Greptile bot:
- Move verbose_logger import to top-level (matches project convention)
- Remove redundant try/except around supports_function_calling() since it
  already handles exceptions internally via _supports_factory()

* fix(index.md): cleanup str

* fix(proxy): handle missing DATABASE_URL in append_query_params (#21239)

* fix: handle missing database url in append_query_params

* Update litellm/proxy/proxy_cli.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix(mcp): revert StreamableHTTPSessionManager to stateless mode (#21323)

PR #19809 changed stateless=True to stateless=False to enable progress
notifications for MCP tool calls. This caused the mcp library to enforce
mcp-session-id headers on all non-initialize requests, breaking MCP
Inspector, curl, and any client without automatic session management.

Revert to stateless=True to restore compatibility with all MCP clients.
The progress notification code already handles missing sessions gracefully
(defensive checks + try/except), so no other changes are needed.

Fixes #20242

* UI - Content Filters, help edit/view categories and 1-click add categories + go to next page  (#21223)

* feat(ui/): allow viewing content filter categories on guardrail info

* fix(add_guardrail_form.tsx): add validation check to prevent adding empty content filter guardrails

* feat(ui/): improve ux around adding new content filter categories

easy to skip adding a category, so make it a 1-click thing

* Fix OCI Grok output pricing (#21329)

* fix(proxy): fix master key rotation Prisma validation errors

_rotate_master_key() used jsonify_object() which converts Python dicts
to JSON strings. Prisma's Python client rejects strings for Json-typed
fields — it requires prisma.Json() wrappers or native dicts.

This affected three code paths:
- Model table (create_many): litellm_params and model_info converted to
  strings, plus created_at/updated_at were None (non-nullable DateTime)
- Config table (update): param_value converted to string
- Credentials table (update): credential_values/credential_info
  converted to strings

Fix: replace jsonify_object() with model_dump(exclude_none=True) +
prisma.Json() wrappers for all Json fields. Wrap model delete+insert
in a Prisma transaction for atomicity. Add try/except around MCP
server rotation to prevent non-critical failures from blocking the
entire rotation.

---------

Co-authored-by: Harshit Jain <harshitjain0562@gmail.com>
Co-authored-by: Harshit Jain <48647625+Harshit28j@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Ephrim Stanley <ephrim.stanley@point72.com>
Co-authored-by: Jay Prajapati <79649559+jayy-77@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Julio Quinteros Pro <jquinter@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Sameer Kankute <sameer@berri.ai>
Co-authored-by: mjkam <mjkam@naver.com>
Co-authored-by: Fly <48186978+tuzkiyoung@users.noreply.github.com>
Co-authored-by: Kristoffer Arlind <13228507+KristofferArlind@users.noreply.github.com>
Co-authored-by: Constantine <Runixer@gmail.com>
Co-authored-by: Emerson Gomes <emerson.gomes@thalesgroup.com>
Co-authored-by: Atharva Jaiswal <92455570+AtharvaJaiswal005@users.noreply.github.com>
Co-authored-by: Krrish Dholakia <krrishdholakia@gmail.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
krrishdholakia added a commit that referenced this pull request Feb 17, 2026
* fix: SSO PKCE support fails in multi-pod Kubernetes deployments

* fix: virutal key grace period from env/UI

* fix: refactor, race condition handle, fstring sql injection

* fix: add async call to avoid server pauses

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: add await in tests

* add modify test to perform async run

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix grace period with better error handling on frontend and as per best practices

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: as per request changes

* Update litellm/proxy/utils.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Fix errors when callbacks are invoked for file delete operations:

* Fix errors when callbacks are invoked for file operations

* Fix: pass deployment credentials to afile_retrieve in managed_files post-call hook

* Fix: bypass managed files access check in batch polling by calling afile_content directly

* Update tests/test_litellm/proxy/management_endpoints/test_ui_sso.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: afile_retrieve returns unified ID for batch output files

* fix: batch retrieve returns unified input_file_id

* fix(chatgpt): drop unsupported responses params for Codex

Co-authored-by: Cursor <cursoragent@cursor.com>

* test(chatgpt): ensure Codex request filters unsupported params

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix deleted managed files returning 403 instead of 404

* Add comments

* Update litellm/proxy/utils.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix: thread deployment model_info through batch cost calculation

batch_cost_calculator only checked the global cost map, ignoring
deployment-level custom pricing (input_cost_per_token_batches etc.).
Add optional model_info param through the batch cost chain and pass
it from CheckBatchCost.

* fix(deps): add pytest-postgresql for db schema migration tests

The test_db_schema_migration.py test requires pytest-postgresql but it was
missing from dependencies, causing import errors:

  ModuleNotFoundError: No module named 'pytest_postgresql'

Added pytest-postgresql ^6.0.0 to dev dependencies to fix test collection
errors in proxy_unit_tests.

This is a pre-existing issue, not related to PR #21277.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(test): replace caplog with custom handler for parallel execution

The cost calculation log level tests were failing when run with pytest-xdist
parallel execution because caplog doesn't work reliably across worker processes.
This causes "ValueError: I/O operation on closed file" errors.

Solution: Replace caplog fixture with a custom LogRecordHandler that directly
attaches to the logger. This approach works correctly in parallel execution
because each worker process has its own handler instance.

Fixes test failures in PR #21277 when running with --dist=loadscope.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(test): correct async mock for video generation logging test

The test was failing with AuthenticationError because the mock wasn't
intercepting the actual HTTP handler calls. This caused real API calls
with no API key, resulting in 401 errors.

Root cause: The test was patching the wrong target using string path
'litellm.videos.main.base_llm_http_handler' instead of using patch.object
on the actual handler instance. Additionally, it was mocking the sync
method instead of async_video_generation_handler.

Solution: Use patch.object with side_effect pattern on the correct
async handler method, following the same pattern used in
test_video_generation_async().

Fixes test failure in PR #21277 when running with --dist=loadscope.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(test): add cleanup fixture and no_parallel mark for MCP tests

Two MCP server tests were failing when run with pytest-xdist parallel
execution (--dist=loadscope):
- test_mcp_routing_with_conflicting_alias_and_group_name
- test_oauth2_headers_passed_to_mcp_client

Both tests showed assertion failures where mocks weren't being called
(0 times instead of expected 1 time).

Root cause: These tests rely on global_mcp_server_manager singleton
state and complex async mocking that doesn't work reliably with
parallel execution. Each worker process can have different state
and patches may not apply correctly.

Solution:
1. Added autouse fixture to clean up global_mcp_server_manager registry
   before and after each test for better isolation
2. Added @pytest.mark.no_parallel to these specific tests to ensure
   they run sequentially, avoiding parallel execution issues

This approach maintains test reliability while allowing other tests
in the file to still benefit from parallelization.

Fixes test failures exposed by PR #21277.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Regenerate poetry.lock with Poetry 2.3.2

Updated lock file to use Poetry 2.3.2 (matching main branch standard).
This addresses Greptile feedback about Poetry version mismatch.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Remove unused pytest import and add trailing newline

- Removed unused pytest import (caplog fixture was removed)
- Added missing trailing newline at end of file

Addresses Greptile feedback (minor style issues).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Remove redundant import inside test method

The module litellm.videos.main is already imported at the top of
the file (line 21), so the import inside the test method is redundant.

Addresses Greptile feedback (minor style issue).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Fix converse anthropic usage object according to v1/messages specs

* Add routing based on if reasoning is supported or not

* add fireworks_ai/accounts/fireworks/models/kimi-k2p5 in model map

* Removed stray .md file

* fix(bedrock): clamp thinking.budget_tokens to minimum 1024

Bedrock rejects thinking.budget_tokens values below 1024 with a 400
error. This adds automatic clamping in the LiteLLM transformation
layer so callers (e.g. router with reasoning_effort="low") don't
need to know about the provider-specific minimum.

Fixes #21297

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: improve Langfuse test isolation to prevent flaky failures (#21093)

The test was creating fresh mocks but not fully isolating from setUp state,
causing intermittent CI failures with 'Expected generation to be called once.
Called 0 times.'

Instead of creating fresh mocks, properly reset the existing setUp mocks to
ensure clean state while maintaining proper mock chain configuration.

* feat(s3): add support for virtual-hosted-style URLs (#21094)

Add s3_use_virtual_hosted_style parameter to support AWS S3 virtual-hosted-style URL format (bucket.endpoint/key) alongside the existing path-style format (endpoint/bucket/key).

This enables compatibility with S3-compatible services like MinIO and aligns with AWS S3 official terminology.

* Addressed greptile comments to extract common helpers and return 404

* Allow effort="max" for Claude Opus 4.6 (#21112)

* fix(aiohttp): prevent closing shared ClientSession in AiohttpTransport (#21117)

When a shared ClientSession is passed to LiteLLMAiohttpTransport,
calling aclose() on the transport would close the shared session,
breaking other clients still using it.

Add owns_session parameter (default True for backwards compatibility)
to AiohttpTransport and LiteLLMAiohttpTransport. When a shared session
is provided in http_handler.py, owns_session=False is set to prevent
the transport from closing a session it does not own.

This aligns AiohttpTransport with the ownership pattern already used
in AiohttpHandler (aiohttp_handler.py).

* perf(spend): avoid duplicate daily agent transaction computation (#21187)

* fix: proxy/batches_endpoints/endpoints.py:309:11: PLR0915 Too many statements (54 > 50)

* fix mypy

* Add doc for OpenAI Agents SDK with LiteLLM

* Add doc for OpenAI Agents SDK with LiteLLM

* Update docs/my-website/sidebars.js

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix mypy

* Update tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Add blog fffor Managing Anthropic Beta Headers

* Add blog fffor Managing Anthropic Beta Headers

* correct the time

* Fix: Exclude tool params for models without function calling support (#21125) (#21244)

* Fix tool params reported as supported for models without function calling (#21125)

JSON-configured providers (e.g. PublicAI) inherited all OpenAI params
including tools, tool_choice, function_call, and functions — even for
models that don't support function calling. This caused an inconsistency
where get_supported_openai_params included "tools" but
supports_function_calling returned False.

The fix checks supports_function_calling in the dynamic config's
get_supported_openai_params and removes tool-related params when the
model doesn't support it. Follows the same pattern used by OVHCloud
and Fireworks AI providers.

* Style: move verbose_logger to module-level import, remove redundant try/except

Address review feedback from Greptile bot:
- Move verbose_logger import to top-level (matches project convention)
- Remove redundant try/except around supports_function_calling() since it
  already handles exceptions internally via _supports_factory()

* fix(index.md): cleanup str

* fix(proxy): handle missing DATABASE_URL in append_query_params (#21239)

* fix: handle missing database url in append_query_params

* Update litellm/proxy/proxy_cli.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* fix(migrations): Make vector stores migration idempotent with IF NOT EXISTS

- Add IF NOT EXISTS to ALTER TABLE ADD COLUMN statements
- Add IF NOT EXISTS to CREATE INDEX statements
- Prevents migration failures when columns/indexes already exist from manual fixes
- Follows PostgreSQL best practices for idempotent migrations

---------

Co-authored-by: Harshit Jain <harshitjain0562@gmail.com>
Co-authored-by: Harshit Jain <48647625+Harshit28j@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Ephrim Stanley <ephrim.stanley@point72.com>
Co-authored-by: Jay Prajapati <79649559+jayy-77@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Julio Quinteros Pro <jquinter@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Sameer Kankute <sameer@berri.ai>
Co-authored-by: mjkam <mjkam@naver.com>
Co-authored-by: Fly <48186978+tuzkiyoung@users.noreply.github.com>
Co-authored-by: Kristoffer Arlind <13228507+KristofferArlind@users.noreply.github.com>
Co-authored-by: Constantine <Runixer@gmail.com>
Co-authored-by: Emerson Gomes <emerson.gomes@thalesgroup.com>
Co-authored-by: Atharva Jaiswal <92455570+AtharvaJaiswal005@users.noreply.github.com>
Co-authored-by: Krrish Dholakia <krrishdholakia@gmail.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
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