Repository navigation
fix(health): send max_output_tokens on the responses health probe - #52436
narmstrong-berri wants to merge 1 commit into
Conversation
|
[AI] @greptileai review Generated by Claude Code |
| params: Final = {k: v for k, v in model_params.items() if k != "max_tokens"} | ||
| if max_tokens is not None: | ||
| params.setdefault("max_output_tokens", max_tokens) | ||
| return params |
There was a problem hiding this comment.
🟡 Mutable Responses probe parameter construction
When max_tokens exists, params.setdefault mutates the probe dictionary. The mandatory no-mutation rule applies to this new helper.
| params: Final = {k: v for k, v in model_params.items() if k != "max_tokens"} | |
| if max_tokens is not None: | |
| params.setdefault("max_output_tokens", max_tokens) | |
| return params | |
| return { | |
| **({"max_output_tokens": max_tokens} if max_tokens is not None else {}), | |
| **{k: v for k, v in model_params.items() if k != "max_tokens"}, | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
[AI] Fixed. _responses_probe_params no longer mutates anything. It builds the params without max_tokens in one comprehension and returns a new mapping with max_output_tokens added, at 4d96374.
Generated by Claude Code
[Medium impact] The PR appears safe to merge.
|
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5f170fe to
4d96374
Compare
4d96374 to
603adbc
Compare
|
Reproduced the unbounded probe on main and this fixes it. |
Handwritten 1-3 sentence description
Add max_output_tokens to responses health checks
Details
TLDR
Problem this solves:
max_tokenscap is dropped before reaching the providerHow it solves it:
max_tokenstomax_output_tokensfor the Responses probemax_output_tokenson the deployment still winsUser Flow
Before: an admin health checking a Responses API deployment pays for an uncapped answer on every probe
model_info.mode: responsesPOST /v1/responseswith onlymodelandinput, so the reply length is unboundedAfter: the same probe is capped
POST /v1/responseswithmax_output_tokensset from the health check token capPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live proxy proof
No OpenAI credentials exist in this environment, so two
openai/deployments point theirapi_baseat a local stub that serves the OpenAI/v1/responsesroute and records each request body. Both setmodel_info.mode: responsesandmodel_info.health_check_max_tokens: 37, which is the cap_resolve_health_check_max_tokensreads, andresponses-probe-nullalso setsmax_output_tokens: nullin itslitellm_params. The client callsGET /health?model=<name>with the master key for each oneBefore is
532df6ef85655e56d82e334e1ab071c5c7fc29e9(parent of the fix commit) and after is4d963742b4df41c3ba55ea29d81839be847c00a2(branch tip ofnate_fix_responses_health_max_output_tokens). The same proxy command, config, Redis, and stub were used for bothProxy command, run from the repo root of each checkout (
run_proxy.sh)A dedicated Redis on 6402 (
redis-server --port 6402 --save '' --appendonly no) backsrouter_settingsandgeneral_settings.coordination_redis. The two workers were confirmed in each run by twoStarted server processlines, and no checkout printed that the workers flag is ignored with reload. The master key is a randomsk-value exported asLITELLM_MASTER_KEY(the proxy refuses the well knownsk-1234). The provider keys are placeholder strings since the deployments point at the local stubProxy config (one config shared by the three proofs)
Stub (stub.py, run as python stub.py 4251, prints every request it receives)
Client script (client.sh, run with LITELLM_MASTER_KEY exported)
Before
Both probes report healthy, but the bodies the stub received carry no
max_output_tokens, so the provider is free to generate an unbounded reply on every health checkAfter
The same calls send
max_output_tokens: 37for both deployments, including the one that setsmax_output_tokens: null, and nomax_tokenskeyWorker PIDs (after)
Unit tests
Scope is the
responsesentry of the health check mode handlers in litellm/litellm_core_utils/health_check_helpers.py.responsesis in_MAX_TOKEN_SUPPORT_MODES(litellm/proxy/health_check.py), so the probe params carrymax_tokens, butlitellm.aresponseshas no such parameter and the cap never reached the provider. A small helper_responses_probe_paramsnow removesmax_tokensand sets it asmax_output_tokensunless the deployment already sets a non-null one, somax_output_tokens: nullstill gets the cap. No other mode handler changes. Below-minimum values are still raised to the provider's floor by the existing Responses transformation (16 for OpenAI).The bug was found by the Dec 1 integration contract tests (draft PR #50853). The test skipped with BUG for it is
tests/integration/routing/test_dec1_healthchk_probe_requests.py::test_a_responses_probe_posts_the_default_prompt_to_the_responses_api.The new regression test
test_a_responses_probe_is_bounded_by_the_health_check_max_tokensrunsahealth_checkinresponsesmode withmax_tokens: 37against a mocked/v1/responsesendpoint and checks the body sent carriesmax_output_tokens: 37and nomax_tokens. A second cell setsmax_output_tokens: Noneon the deployment. Both cells failed before the fix withKeyError: 'max_output_tokens'and pass at the tip.Type
Bug Fix
Final Attestation
Generated by Claude Code