Skip to content

fix(http_handler): bypass cache when shared_session is provided for aiohttp tracing#20630

Merged
krrishdholakia merged 13 commits intolitellm_oss_staging_02_07_2026from
litellm_fix_aiohttp_tracing
Feb 7, 2026
Merged

fix(http_handler): bypass cache when shared_session is provided for aiohttp tracing#20630
krrishdholakia merged 13 commits intolitellm_oss_staging_02_07_2026from
litellm_fix_aiohttp_tracing

Conversation

@shin-bot-litellm
Copy link
Contributor

Description

Fixes #20174 - aiohttp client tracing logs not visible when using LiteLLM.

Problem

When users pass a shared_session with trace_configs to acompletion(), the get_async_httpx_client() function was ignoring the user's session and returning a cached client. This meant the user's tracing configuration was never used, so aiohttp tracing logs were never emitted.

Root Cause

In get_async_httpx_client():

_cached_client = cache.get_cache(_cache_key_name)
if _cached_client:
    return _cached_client  # <-- User's shared_session is completely ignored!

The cache lookup happened before checking if shared_session was provided, so any cached client for that provider was returned, ignoring the user's custom session configuration.

Solution

When shared_session is provided, bypass the cache entirely and create a new handler that uses the user's session directly. This preserves the user's ClientSession configuration including:

  • trace_configs (for aiohttp tracing)
  • Custom connector settings
  • Any other session-level configuration

Test Plan

  • Added test_shared_session_bypasses_cache - verifies cache is bypassed when shared_session is provided
  • Added test_shared_session_each_call_gets_new_handler - verifies each call with a different shared_session gets its own handler
  • All existing tests continue to pass (34 tests in test_http_handler.py)

krrishdholakia and others added 13 commits February 6, 2026 17:34
…CP + Agent guardrail support (#20619)

* fix: fix styling

* fix(custom_code_guardrail.py): add http support for custom code guardrails

allows users to call external guardrails on litellm with minimal code changes (no custom handlers)

Test guardrail integrations more easily

* feat(a2a/): add guardrails for agent interactions

allows the same guardrails for llm's to be applied to agents as well

* fix(a2a/): support passing guardrails to a2a from the UI

* style(code-editor): allow editing custom code guardrails on ui + add examples of pre/post calls for custom code guardrails

* feat(mcp/): support custom code guardrails for mcp calls

allows custom code guardrails to work on mcp input

* feat(chatui.tsx): support guardrails on mcp tool calls on playground
…20618)

* fix(mypy): resolve missing return statements and type casting issues

* fix(pangea): use elif to prevent UnboundLocalError and handle None messages

Address Greptile review feedback:
- Make branches mutually exclusive using elif to prevent input_messages from being overwritten
- Handle case where data.get('messages') returns None to avoid passing invalid payload to Pangea API

---------

Co-authored-by: Shin <shin@openclaw.ai>
…lable on Internet (#20607)

* update MCPAuthenticatedUser

* add available_on_public_internet for MCPs

* update claude.md

* init IPAddressUtils

* init available_on_public_internet

* add on REST endpoints

* filter with IP

* TestIsInternalIp

* _extract_mcp_headers_from_request

* init get_mcp_client_ip

* _get_general_settings

* allowed_server_ids

* address PR comments

* get_mcp_server_by_name fix

* fix server

* fix review comments

* get_public_mcp_servers

* address _get_allowed_mcp_servers
* update MCPAuthenticatedUser

* add available_on_public_internet for MCPs

* update claude.md

* init IPAddressUtils

* init available_on_public_internet

* add on REST endpoints

* filter with IP

* TestIsInternalIp

* _extract_mcp_headers_from_request

* init get_mcp_client_ip

* _get_general_settings

* allowed_server_ids

* address PR comments

* get_mcp_server_by_name fix

* fix server

* fix review comments

* get_public_mcp_servers

* address _get_allowed_mcp_servers

* test fix

* fix linting

* inint ui types

* add ui for managing MCP private/public

* add ui

* fixes

* add to schema

* add types

* fix endpoint

* add endpoint

* update manager

* test mcp

* dont use external party for ip address
[Fix] /key/list user_id Empty String Edge Case
- a2a_protocol/exception_mapping_utils.py: Fix type ignore comment for None assignment
- caching/redis_cache.py: Add type ignore for async ping return type
- caching/redis_cluster_cache.py: Add type ignore for async ping return type
- llms/deprecated_providers/palm.py: Add type ignore for palm.generate_text
- proxy/auth/handle_jwt.py: Add type ignore for jwt.decode options argument

All changes add appropriate type: ignore comments to handle library typing inconsistencies.
Replace text-embedding-004 with gemini-embedding-001.

The old model was deprecated and returns 404:
'models/text-embedding-004 is not found for API version v1beta'

Co-authored-by: Shin <shin@openclaw.ai>
…iohttp tracing

When users pass a shared_session with trace_configs to acompletion(),
the get_async_httpx_client() function was ignoring it and returning
a cached client without the user's tracing configuration.

This fix bypasses the cache when shared_session is provided, ensuring
the user's ClientSession (with its trace_configs, connector settings, etc.)
is actually used for the request.

Fixes #20174
@vercel
Copy link

vercel bot commented Feb 7, 2026

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

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 7, 2026 4:14am

Request Review

@CLAassistant
Copy link

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.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 7, 2026

Greptile Overview

Greptile Summary

Fixed aiohttp client tracing by bypassing cache when user provides a shared_session. The fix adds an early-return path in get_async_httpx_client() that creates a new handler when shared_session is provided, ensuring the user's ClientSession configuration (including trace_configs) is preserved rather than being ignored by the cache lookup.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is well-targeted, addressing a specific bug where cached clients were preventing user-provided sessions from being used. The change adds an early-return path that bypasses caching when shared_session is provided, which is the correct approach. Tests comprehensively verify the new behavior, and the logic is straightforward with clear documentation.
  • No files require special attention

Important Files Changed

Filename Overview
litellm/llms/custom_httpx/http_handler.py Added early-return logic to bypass cache when shared_session is provided, preserving user's session configuration for aiohttp tracing
tests/test_litellm/llms/custom_httpx/test_http_handler.py Added comprehensive tests to verify cache bypass behavior when shared_session is provided

Sequence Diagram

sequenceDiagram
    participant User
    participant acompletion
    participant get_async_httpx_client
    participant Cache
    participant AsyncHTTPHandler

    Note over User: User provides shared_session<br/>with trace_configs

    User->>acompletion: acompletion(shared_session=session)
    acompletion->>get_async_httpx_client: get_async_httpx_client(llm_provider, shared_session)
    
    alt shared_session is provided
        Note over get_async_httpx_client: NEW: Bypass cache logic
        get_async_httpx_client->>AsyncHTTPHandler: Create new handler with shared_session
        AsyncHTTPHandler-->>get_async_httpx_client: Return new handler
        get_async_httpx_client-->>acompletion: Return handler with user's session
        Note over acompletion: User's trace_configs are preserved
    else shared_session is None
        get_async_httpx_client->>Cache: Check cache for existing client
        alt Cache hit
            Cache-->>get_async_httpx_client: Return cached client
        else Cache miss
            get_async_httpx_client->>AsyncHTTPHandler: Create new handler
            AsyncHTTPHandler-->>get_async_httpx_client: Return new handler
            get_async_httpx_client->>Cache: Store in cache
        end
        get_async_httpx_client-->>acompletion: Return handler
    end
Loading

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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@krrishdholakia krrishdholakia changed the base branch from main to litellm_oss_staging_02_07_2026 February 7, 2026 07:55
@krrishdholakia krrishdholakia merged commit a951cca into litellm_oss_staging_02_07_2026 Feb 7, 2026
55 of 67 checks passed
Sameerlite pushed a commit that referenced this pull request Feb 12, 2026
…iohttp tracing (#20630)

* Add http support to custom code guardrails + Unified guardrails for MCP + Agent guardrail support (#20619)

* fix: fix styling

* fix(custom_code_guardrail.py): add http support for custom code guardrails

allows users to call external guardrails on litellm with minimal code changes (no custom handlers)

Test guardrail integrations more easily

* feat(a2a/): add guardrails for agent interactions

allows the same guardrails for llm's to be applied to agents as well

* fix(a2a/): support passing guardrails to a2a from the UI

* style(code-editor): allow editing custom code guardrails on ui + add examples of pre/post calls for custom code guardrails

* feat(mcp/): support custom code guardrails for mcp calls

allows custom code guardrails to work on mcp input

* feat(chatui.tsx): support guardrails on mcp tool calls on playground

* fix(mypy): resolve missing return statements and type casting issues (#20618)

* fix(mypy): resolve missing return statements and type casting issues

* fix(pangea): use elif to prevent UnboundLocalError and handle None messages

Address Greptile review feedback:
- Make branches mutually exclusive using elif to prevent input_messages from being overwritten
- Handle case where data.get('messages') returns None to avoid passing invalid payload to Pangea API

---------

Co-authored-by: Shin <shin@openclaw.ai>

* [Feat] MCP Gateway - Allow setting MCP Servers as Private/Public available on Internet (#20607)

* update MCPAuthenticatedUser

* add available_on_public_internet for MCPs

* update claude.md

* init IPAddressUtils

* init available_on_public_internet

* add on REST endpoints

* filter with IP

* TestIsInternalIp

* _extract_mcp_headers_from_request

* init get_mcp_client_ip

* _get_general_settings

* allowed_server_ids

* address PR comments

* get_mcp_server_by_name fix

* fix server

* fix review comments

* get_public_mcp_servers

* address _get_allowed_mcp_servers

* fixing user_id

* [Feat] IP-Based Access Control for MCP Servers (#20620)

* update MCPAuthenticatedUser

* add available_on_public_internet for MCPs

* update claude.md

* init IPAddressUtils

* init available_on_public_internet

* add on REST endpoints

* filter with IP

* TestIsInternalIp

* _extract_mcp_headers_from_request

* init get_mcp_client_ip

* _get_general_settings

* allowed_server_ids

* address PR comments

* get_mcp_server_by_name fix

* fix server

* fix review comments

* get_public_mcp_servers

* address _get_allowed_mcp_servers

* test fix

* fix linting

* inint ui types

* add ui for managing MCP private/public

* add ui

* fixes

* add to schema

* add types

* fix endpoint

* add endpoint

* update manager

* test mcp

* dont use external party for ip address

* Add OpenAI/Azure release test suite with HTTP client lifecycle regression detection (#20622)

* docs (#20626)

* docs

* fix(mypy): resolve type checking errors in 5 files (#20627)

- a2a_protocol/exception_mapping_utils.py: Fix type ignore comment for None assignment
- caching/redis_cache.py: Add type ignore for async ping return type
- caching/redis_cluster_cache.py: Add type ignore for async ping return type
- llms/deprecated_providers/palm.py: Add type ignore for palm.generate_text
- proxy/auth/handle_jwt.py: Add type ignore for jwt.decode options argument

All changes add appropriate type: ignore comments to handle library typing inconsistencies.

* fix(test): update deprecated gemini embedding model (#20621)

Replace text-embedding-004 with gemini-embedding-001.

The old model was deprecated and returns 404:
'models/text-embedding-004 is not found for API version v1beta'

Co-authored-by: Shin <shin@openclaw.ai>

* ui new buil

* fix(http_handler): bypass cache when shared_session is provided for aiohttp tracing

When users pass a shared_session with trace_configs to acompletion(),
the get_async_httpx_client() function was ignoring it and returning
a cached client without the user's tracing configuration.

This fix bypasses the cache when shared_session is provided, ensuring
the user's ClientSession (with its trace_configs, connector settings, etc.)
is actually used for the request.

Fixes #20174

---------

Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
Co-authored-by: Shin <shin@openclaw.ai>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: yuneng-jiang <yuneng.jiang@gmail.com>
Co-authored-by: Alexsander Hamir <alexsanderhamirgomesbaptista@gmail.com>
Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
ishaan-jaff added a commit that referenced this pull request Feb 21, 2026
…ed for aiohttp tracing (#20630)"

This reverts commit 7ee36c2a3ac6d83aaef82c6bf83231b5fbc1c9ed.

Co-Authored-By: Warp <agent@warp.dev>
ishaan-jaff added a commit that referenced this pull request Feb 21, 2026
ishaan-jaff added a commit that referenced this pull request Feb 21, 2026
…s provided for aiohttp tracing (#20630)""

This reverts commit 0b69c21.
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.

[Bug]: Not able to see aiohttp client tracing logs

6 participants