litellm/tests/unit/llms/custom_httpx
joshua-berri c86250164e
fix(responses): bound overlong tool call IDs in the chat bridge (#53390)
* fix(responses): bound overlong tool call ids in the chat to responses bridge

Chat tool call ids longer than 64 characters were copied verbatim into
Responses call_id fields, so OpenAI rejected the request with string too
long. transform_request now replaces any such call_id on function and
custom tool calls and their outputs with its SHA-256 hex digest, so calls
and outputs stay paired across ordinary and replayed history. Shorter ids,
non-string ids and other callers of the shared converter are unchanged.

* style(responses): drop the call id limit observation comment

* fix(responses): bound bridged tool call ids only for endpoints that limit them

The chat to Responses bridge hashed every call_id longer than 64 characters
before routing finished, so custom endpoints that accept long ids got
rewritten ids, and a short id equal to a hash could collide.

The bridge request now keeps the caller's ids. The Responses HTTP handlers,
sync and async, map them after the provider transform and before signing,
only for bridged chat requests whose final URL is OpenAI, a verified Azure
host or a standard Bedrock Mantle host. Each distinct overlong id gets a
64-char SHA-256 based value that avoids every short id already in the
request, so calls, outputs and replayed history stay paired in any order.

* perf(responses): assign bridged call id replacements in linear time

Each overlong id copied the reserved set and the growing replacement map,
so a request with thousands of distinct overlong ids blocked the event loop
for seconds. One request-local taken set now holds the short ids and every
claimed replacement, and the replacement map is frozen once.

* test(responses): cover a long call id whose retry candidate another long id already claimed

* style(responses): remove an unnecessary mutation annotation

* test(responses): cover bridged call ids on faked streams and repeated long ids

* refactor(responses): reuse the Azure v1 host check for bridged call id limits

* fix(responses): bound overlong tool call ids on every bridged chat request

The bridge only shortened call ids longer than 64 characters when the final
URL was a known OpenAI, Azure or Mantle host, so bridged requests through
OpenRouter or a nested LiteLLM proxy still sent the long ids and the OpenAI
backend behind them rejected the request. Every Chat to Responses bridged
request now gets the same collision safe per request mapping at dispatch.
Ids of 64 characters or fewer, native Responses calls and ordinary chat
completions are unchanged.

* test(responses): answer bridged route requests in the stream mode they ask for

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-23 20:09:03 -08:00
..
__init__.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_accept_encoding.py fix(http): stop advertising zstd so streamed responses survive per-event frames (#53439) 2026-11-21 23:58:04 +00:00
test_aiohttp_cleanup_closed.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00
test_aiohttp_handler.py fix(http): diagnose aiohttp connection pool saturation (#49499) 2026-10-31 16:12:30 -07:00
test_aiohttp_so_keepalive.py refactor(llms): expose public names for private provider helpers (#45037) 2026-10-07 08:49:25 -07:00
test_aiohttp_transport.py test(aiohttp): verify streaming timeouts without wall-clock delays (#53189) 2026-11-20 21:20:48 +00:00
test_asgi_handler.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_async_client_cleanup.py test: move 76 live top-level tests to offline unit and integration coverage (#45352) 2026-10-08 10:33:35 -07:00
test_container_handler.py test: catch regressions in the validation lines #44798 added (#47420) 2026-10-20 01:06:37 +00:00
test_credential_leak_prevention.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_gemini_session_leak.py test(unit): stop test modules from putting their own directory on sys.path (#43421) 2026-09-28 12:20:20 -07:00
test_http2_connection_spread.py feat(vertex_ai)!: use HTTP/2 httpx client for search_api vector store (#40631) 2026-10-29 10:31:18 -07:00
test_http2_graceful_goaway.py fix(http): answer HTTP/2 requests in flight at a graceful GOAWAY instead of failing or resending them (#51278) 2026-11-24 01:12:55 +00:00
test_http_handler.py fix(httpx): repair surrogate code points in raw text request bodies (#49599) 2026-11-19 11:48:18 -08:00
test_llm_http_handler.py fix(responses): bound overlong tool call IDs in the chat bridge (#53390) 2026-11-23 20:09:03 -08:00
test_mock_transport.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_sse_lines.py fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00