litellm/tests/unit/proxy/response_polling
edvinsq d941699343
fix(responses): reject an unresolvable previous_response_id on the chat completions bridge (#53766)
* fix(responses): reject an unresolvable previous_response_id on the chat completions bridge

A follow-up whose earlier turns cannot be found in the spend logs now answers 400 previous_response_not_found, matching OpenAI, before any provider call, so it is never answered without context or billed. The sync litellm.responses() bridge path now rebuilds history the same way as the async path.

* fix(responses): keep param on the input token count's previous_response_id 400

The input token count route rebuilt the bridge error with param null, so a client could not tell the count was refused on previous_response_id. The chat count error now carries the exception's param through to the proxy response

* fix(responses): give SDK installs the previous_response_id 400 and type WebSocket turn errors by status

An SDK install without the proxy extras now gets the same 400 instead of a 500, the hint names the proxy's spend logs, and managed WebSocket turn failures carry the per-status error type plus OpenAI's code and param

* fix(responses): refuse a sync follow-up that would query the proxy's database off its event loop

* fix(responses): refuse sync follow-ups without querying the proxy database and keep sync compaction working

* fix(ui): resend the whole conversation when the proxy cannot resolve previous_response_id

The chat page and the Playground send only the new message with previous_response_id. When the
proxy answers 400 on that id, they now retry once with the full conversation and continue the
session from the new response. The 400 message also says the prompt storage setting must not be
turned off in the key's or team's metadata

* fix(ui): keep sending the whole conversation after the proxy could not resolve previous_response_id

After one resend without previous_response_id, later turns send the full history until the chat, session toggle, model or conversation resets, so a lost session never answers the follow-up without context

* fix(responses): count an unresolvable previous_response_id as the caller's error and keep its code in background polls

* fix(ui): declare the Playground chat hook's model change reset in its return type

* test(responses): drop the fixed wait from the router failure-count test

The router counts failures inline before the refused call returns, so the
test checks the deployment's state right after the calls

* fix(responses): never retry or fall back on an unresolvable previous_response_id, and let input that carries its history through

The router now ends retries and skips fallbacks for the 400, so a retry policy or a fallback group no longer runs it again or forwards the unknown id

The 400 is a client error, so it sends no Slack llm_exceptions alert

A follow-up whose input already holds an earlier assistant reply or tool call goes through without the stored turns, and input holding only a tool output still gets the 400

A background follow-up that gets the 400 polls failed with previous_response_not_found, and every other background failure keeps its old error

* fix(ui): start a new trace when the Playground model changes

A model change already starts a new Responses session, but the old trace id
stayed. The first turn after the change resends the whole conversation under
that trace id, so with store_prompts_in_spend_logs on, the next bridged
follow-up was rebuilt from both the old chain and the resent history and the
provider got the earlier turns twice

* fix(router): end the fallback chain when a fallback refuses a follow-up

A fallback hop that cannot find a follow-up's earlier turns now ends the call with its 400 instead of sending the same id to the next fallback, and the SDK's num_retries no longer reruns that 400

* fix(router): answer with the fallback's 400 when it cannot find the previous response

When the first group fails for another reason and a fallback refuses a follow-up because its previous_response_id is unknown, the caller now gets that 400 with param previous_response_id instead of the first group's error, so a client can resend the whole conversation

The walk still ends at the refusing fallback and never calls the next one

* fix(router): let the next fallback answer a follow-up to a response a provider holds

* fix(router): treat previous_response_id 400s as the caller's error and keep the usual all-fail error

A provider 400 naming previous_response_id no longer counts against the deployment or cools it down. A follow-up to a turn a native Responses deployment holds keeps its fallbacks with fallback_on_unsupported_params off, and when every fallback fails the caller gets the router's usual error

A follow-up to a turn the chat bridge answered ends the walk for every provider, Gemini included

* fix(router): don't cool down a fallback deployment on a previous_response_id 400

A provider's 400 naming previous_response_id at a fallback hop went through the
fallback cooldown path, which lacked the exit the first logged failure already had,
so a store: false turn's follow-ups cooled the native fallback down

* fix(responses): let a native turn on a provider without resp_ ids reach the next fallback

A native Responses turn counted as provider-held only when its original id
started with resp_, so an xAI turn, whose ids are UUIDs, ended the fallback
walk at the first bridged group with the 400 even though a native xAI
fallback could answer it. A turn now counts as provider-held when its
provider has a native Responses config and its id is not a chat completion
id

* fix(responses): answer a non-string previous_response_id on the chat bridge with a 400

A previous_response_id that is not a string, such as 123 or a list, reached the
bridge's check for whether a provider holds the turn and crashed there, so the
caller got a 500 or a 400 carrying a traceback. The bridge now refuses it with
an invalid_request_error naming previous_response_id before it looks the turn
up or calls the provider

* fix(responses): stop retrying and falling back on a non-string previous_response_id

The chat bridge's 400 for a previous_response_id that is not a string was a
plain BadRequestError. A BadRequestErrorRetries policy and the SDK's
num_retries retried it, a fallback group got the same bad id, and the Slack
llm_exceptions alert fired. It now raises the same error class as a follow-up
to a turn no provider holds, so retries and fallbacks end and the router and
proxy treat it as the caller's error

* test(proxy): read the lost previous_response_id from a spend log double

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 13:32:42 +00:00
..
__init__.py ci: move tests/proxy_unit_tests to tests/unit/proxy and run the proxy-db shards from litellm-tests (#42903) 2026-09-24 22:59:11 +00:00
test_response_polling_handler.py fix(responses): reject an unresolvable previous_response_id on the chat completions bridge (#53766) 2026-11-25 13:32:42 +00:00