litellm/tests/test_litellm/proxy/middleware
devin-ai-integration[bot] e7cd97c6b6
fix(proxy): release unclaimed budget reservations at request end (#42304)
* fix(proxy): release unclaimed budget reservations at request end

* fix(proxy): release unclaimed budget reservations of websocket sessions too

* test(proxy): drop the structural middleware inheritance check

* fix(proxy): claim the budget reservation on streaming pass-through before its cost callback

The SSE chunk processor hands its success handler to the logging worker
after the response, so the request-end release freed the reservation
first and left the key unguarded until the worker drained. Claim it at
both end-of-stream hand-offs, the immediate enqueue and the coroutine
parked for deferred dispatch.

Give the xai realtime test double the litellm_params attribute every
real Logging object carries, since the wrapper now reads it.

* test(pass-through): give the vertex streaming test doubles a litellm_params dict

The spec'd Logging mocks in test_vertex_ai_anthropic_streaming_cost_injection.py
lacked the instance attribute the chunk processor now reads to claim the budget
reservation. Also restores main's _lazy_openapi_snapshot.json: the branch's copy
had been regenerated under Python 3.14, which dedents one docstring description
that the CI regeneration on Python 3.12 keeps indented, and the PR adds no lazily
loaded route, so main's file is the correct one.

* fix(pass-through): claim the budget reservation only after its cost callback is enqueued

Every pass-through success hand-off stamped callback_bound before handing the
coroutine to the logging worker. When that enqueue raised, the reservation stayed
claimed with no callback left to reconcile it, so the request-end release skipped it
and the reserved cost stayed pinned on the key's counter. Enqueue first, then claim,
so a failed hand-off leaves the reservation for the request-end release.

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-09-21 19:51:12 -07:00
..
test_admission_control_middleware.py feat(proxy): per-worker admission control that rejects excess requests with 503 (#39352) 2026-09-03 18:19:04 -07:00
test_billable_request_metrics_middleware.py Merge remote-tracking branch 'origin/main' into litellm_azure_speech_passthrough 2026-09-18 18:42:22 +00:00
test_budget_reservation_release_middleware.py fix(proxy): release unclaimed budget reservations at request end (#42304) 2026-09-21 19:51:12 -07:00
test_in_flight_requests_middleware.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_per_request_root_path_middleware.py feat(proxy): resolve root_path per request from a configured prefix list (SERVER_ROOT_PATHS) (#35935) 2026-09-07 11:54:59 -07:00
test_prometheus_auth_middleware.py fix(claude_code_gateway): scope the protobuf body skip to the OTLP routes and match the metrics middleware on the route path 2026-09-18 17:23:59 -07:00
test_prometheus_auth_middleware_asgi.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_security_headers_middleware.py feat(proxy): configurable response headers and login-page hint (#30792) 2026-06-18 18:12:45 -07:00