Repository navigation
fix(router): strip encrypted reasoning on an auto-router tier change instead of a 503 - #40280
Conversation
|
Docs PR: BerriAI/litellm-docs#1272 |
|
@greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Score: 4/5 This is a strong, focused fix. The routing change correctly distinguishes a genuine same-model-group availability failure from an intentional auto-router tier change, while preserving the existing fail-fast behavior for an empty/same-group pool. The input helper mutates the list in place, preserves readable reasoning summaries, removes the undecryptable payload and stale item ID, and the tests cover both the cross-group success path and the empty-pool regression path. The passing Buildkite status and documented real-provider validation further support the implementation. I’m holding back a point because the discriminator relies on every routed deployment exposing the canonical |
Greptile SummaryThis PR changes encrypted-content affinity handling so Responses API follow-ups can continue after a routed model-group change.
Confidence Score: 4/5The PR should not merge until routed-group membership uses the same pattern and team-public resolution semantics as deployment selection. Pattern and team-public requests can resolve a valid same-group deployment pool while Files Needing Attention: litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py
|
| Filename | Overview |
|---|---|
| litellm/responses/utils.py | Adds in-place removal of undecryptable reasoning items while preserving readable string or block content. |
| litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py | Adds cross-group stripping, but exact-name deployment lookup misclassifies pattern and team-public routing groups. |
| tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py | Adds focused regression coverage but omits pattern-routed and team-public same-group cases. |
Reviews (2): Last reviewed commit: "fix(router): strip encrypted reasoning o..." | Re-trigger Greptile
| return bool(healthy_deployments) and all( | ||
| deployment.get("model_name") != originating.model_name for deployment in healthy_deployments | ||
| ) |
There was a problem hiding this comment.
Routing groups are misclassified When an origin member is cooled, distinct member names mark the same routing group as cross-tier and silently strip reasoning.
Knowledge Base Used: Routing and resilience
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed. The group test now compares the origin's model group to the routed model param, not pool member names, so a cooled origin in its own group can no longer read as cross-tier. Same-group unavailability still fails fast.
| stripped: Final = tuple(ResponsesAPIRequestUtils._without_encrypted_reasoning(item) for item in items) | ||
| items[:] = (item for item in stripped if item is not None) # rebind-ok: list shared with fallback snapshot |
There was a problem hiding this comment.
Mixed histories lose reasoning Multi-deployment histories select the first origin, then remove every encrypted reasoning item, including items decryptable by the selected deployment.
Knowledge Base Used: Routing and resilience
There was a problem hiding this comment.
On a tier change we strip all encrypted reasoning and dispatch, so no foreign blob is ever forwarded (after-arm outbound bodies show 0 encrypted_content). Selectively keeping the current tier's own reasoning needs pinning to the decrypting deployment; tracked as follow-up on LIT-7195.
There was a problem hiding this comment.
You're right—given this PR's explicit contract, dropping every encrypted reasoning item on a cross-model-group tier change is intentional, and the tests confirm that no foreign blob is forwarded. My comment conflated information loss with a regression. Selective retention would require affinity to the decrypting deployment and is appropriately a follow-up on LIT-7195. I'll withdraw this finding.
| def _blocks(value: object) -> tuple[object, ...]: | ||
| return tuple(cast(list[object], value)) if isinstance(value, list) else () # cast-ok: untyped client json |
There was a problem hiding this comment.
Fixed. Readability now accepts a plain-string summary or content, not just list blocks, so string-form reasoning text is kept when the encrypted payload is stripped. Added a regression test.
| return | ||
| items: Final = cast(list[object], request_input) # cast-ok: untyped client json | ||
| stripped: Final = tuple(ResponsesAPIRequestUtils._without_encrypted_reasoning(item) for item in items) | ||
| items[:] = (item for item in stripped if item is not None) # rebind-ok: list shared with fallback snapshot |
There was a problem hiding this comment.
Lines exceed repository limit These reformatted statements exceed the required 120-character Python limit, including the same pattern elsewhere, and must be wrapped before merge.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
No added line exceeds 120 (git diff vs base shows none). The lines you flagged are pre-existing in this file, untouched by the change, so left as-is to avoid a drive-by reformat.
There was a problem hiding this comment.
You're right. The added lines in litellm/responses/utils.py are within the 120-character limit; the overlong lines I referenced are pre-existing and untouched. I retract this comment—it should be dismissed.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
d94733b to
b5d6545
Compare
|
@greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Score: 4/5 This is a strong, targeted fix. The cross-model-group branch in I’m not giving it 5/5 only because the new discriminator depends on |
|
CI note: the only red, proxy-infra test_migrate_diff_stops_at_its_budget_and_takes_its_process_tree_with_it, fails identically on a clean litellm_internal_staging checkout (added today by #39509) and is unrelated to this diff, which touches only the Responses affinity check. Not introduced here. |
b5d6545 to
98bde78
Compare
|
Pushed Design B: the tier-change discriminator now keys on deployment-id membership in the routed group, not model-group name, plus a hardening test for provider-qualified spellings @greptileai can you reply here with a score and why that score? bugbot run |
|
Score: 4.5/5 This is a strong revision. The discriminator now uses authoritative deployment-id membership for the routed group, avoiding false tier-change detection when model names differ by provider qualification or aliasing. The added regression test covers that case and verifies both fail-fast behavior and preservation of encrypted reasoning. The cross-group and same-group branches are clearly separated, and the in-place stripping behavior remains covered. I have no blocking findings. The only reason this is not a 5/5 is that the latest CI/e2e status is still pending, so the score assumes the pending Buildkite run passes. |
|
@greptile review |
| # routed group instead of failing. Same-group unavailability falls through to the fail-fast | ||
| # below, preserving the cooldown contract. | ||
| if originating is not None and self.router is not None: | ||
| routed_group_model_ids: Final = frozenset(str(mid) for mid in self.router.get_model_ids(model_name=model)) |
There was a problem hiding this comment.
Pattern and team-public routes bypass this index, so same-group unavailability can strip replayable reasoning instead of failing fast.
Knowledge Base Used: Routing and resilience
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed. The router now stashes the candidate deployment ids it resolved for the route (group, model_name, team, pattern), and the check tests id membership against that set instead of the index. Regression tests added.
98bde78 to
49ba6fe
Compare
|
Addressed the P1: the router now publishes the candidate deployment ids it resolved for the route (group, model_name, team, pattern) and the discriminator tests id membership against that set, closing the team and pattern gaps @greptileai can you reply here with a score and why that score? bugbot run |
|
Score: 5/5 The P1 is addressed. The router now snapshots deployment IDs from the actual route resolution before subsequent filtering, and the affinity check uses origin deployment-ID membership rather than reconstructing group membership from |
49ba6fe to
f970957
Compare
|
Rebased onto the latest staging to clear a test_router.py merge conflict (kept both the new drop_params tests and the LIT-7195 stash test). No logic change @greptileai can you reply here with a score and why that score? bugbot run |
|
Score: 4.5/5 No new logic concerns from the rebase: the deployment-ID candidate snapshot, cross-group stripping, same-group fail-fast behavior, and provider-qualified-name regression coverage remain intact. The I’m holding back 0.5 only because the latest Buildkite E2E status is still pending; assuming it remains green, this is a 5/5 with no blocking findings. |
f970957 to
652a78b
Compare
|
Rebased onto the latest staging (clean, no conflicts, no logic change) to pick up recent merges @greptileai can you reply here with a score and why that score? bugbot run |
|
Score: 4.5/5 The rebase is clean and does not introduce logic changes. The deployment-ID candidate snapshot still covers group, team, and pattern routing; cross-group requests strip encrypted reasoning in place while preserving readable context; and same-group unavailability retains the existing fail-fast behavior. The regression tests also remain intact, including the provider-qualified-name, candidate-ID, and router stash cases. I’m holding back 0.5 only because the latest Buildkite E2E status is still pending. Assuming that run remains green, this is a 5/5 with no blocking findings. |
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
652a78b to
98cb68f
Compare
|
Addressed the Veria deployment-id oracle: unknown/forged origins now strip and dispatch identically to cross-group ones, so existing and nonexistent ids are indistinguishable. Also rebased onto latest staging @greptileai can you reply here with a score and why that score? bugbot run |
|
Score: 5/5 The latest revision addresses the remaining routing concern: unknown or forged origins now take the same strip-and-dispatch path as cross-group origins, while the distinguishable |
98cb68f to
9686a04
Compare
|
The unit-test failures were mine, not staging: I was stashing a frozenset of deployment ids into request_kwargs, which crashed JSON serialization on the provider path. Moved that to a read-only router method (no request_kwargs, no id leak) and rebased onto latest staging @greptileai can you reply here with a score and why that score? bugbot run |
…instead of a 503 A Responses API follow-up that replays reasoning.encrypted_content is pinned to the deployment that minted it. Behind an auto-router the pre-routing hook rebinds the model to the tier it picked before the candidate pool is built, so a turn that classifies into a different tier never finds the origin and the affinity check raised its fail-fast 503, whose text claims a cooldown that does not exist When the deployment that minted the reasoning is not a member of the model group this turn is routed to, strip the encrypted reasoning (keeping any readable summary, string or block form) and dispatch to the routed group. Membership is tested by deployment id against the candidate set the router itself resolved for the route (routing group, model_name, team, and pattern alike), not by model-group name, so an alias, a provider-qualified spelling, a team-public name, or a pattern route of the same group is not misread as a tier change. An unknown origin (a removed deployment, or a forged/unauthenticated marker) is handled the same as a cross-group one and its reasoning is stripped, so a real cross-group id and a nonexistent id return the same response and cannot be used to enumerate deployment ids. Unavailability within the origin's own group keeps the existing 429/503 fail-fast, so the cooldown contract is unchanged Resolves LIT-7195 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KAumQbhzk6jdWWHFLA8Jar
9686a04 to
0450cf9
Compare
|
Fixed the code-quality router coverage gate by adding a direct unit test for the new helper, and rebased. Unit-test shards were already green after the frozenset fix @greptileai can you reply here with a score and why that score? bugbot run |
|
Score: 9/10 The fix is implemented correctly and the follow-up coverage is strong:
The one-point deduction is for intentional scope limitations: tier changes currently drop all encrypted reasoning rather than retaining selectively decryptable items, and the Anthropic |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0450cf9. Configure here.
…olver (#40491) get_candidate_model_ids_for_route (added in #40280 for the encrypted-content affinity check) reconstructed the candidate pool by unioning the model_name and team indexes with pattern_router.route. That diverged from how the router actually resolves a route: it took a union instead of the first matching path, and pattern_router.route only matches the literal name, so a provider-qualified pattern (matched by get_deployments_by_pattern, which retries the {provider}/{model} form) was missed and the default deployment was ignored. For an affinity follow-up on a wildcard or team-public route, that mismatch could strip encrypted reasoning on a same-group cooldown, or return a 503 on a real cross-path switch. Delegate the non-model_name case to _try_early_resolve_deployments_for_model_not_in_names, the same resolver _common_checks_available_deployment uses, so candidate membership follows the router's real precedence. With include_team_models left off it stays read-only and does not raise. Behavior for concrete model groups and routing groups is unchanged. Claude-Session: https://claude.ai/code/session_01KAumQbhzk6jdWWHFLA8Jar Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…ng deployment is not in the routed group The cross-group branch of EncryptedContentAffinityCheck removed only the signature from Anthropic-shaped thinking blocks, which left unsigned thinking blocks that Anthropic and Bedrock reject (thinking.signature: Field required). Drop the whole block, the way #40280 drops undecryptable Responses input items, so the routed request carries the conversation text with no reasoning item for those turns

TLDR
Problem this solves:
/v1/responsestraffic replaying encrypted reasoning is hitHow it solves it:
User Flow
Before: a developer runs Codex CLI (
store: false, replayingreasoning.encrypted_content) against an auto-router whose tiers span different models, and the second turn diesauto-router, turn 1 classifies to the reasoning tier and returns a reasoning item carryingencrypted_contentThe deployment that produced this encrypted_content is currently unavailable (likely cooled down) ..., though nothing is cooled downAfter: the same session completes; the tier-changed turn is answered by the new tier
Relevant issues
Resolves the customer report of
ServiceUnavailableErroron an auto-router that works when the model is called directlyLinear ticket
Resolves LIT-7195
Type
🐛 Bug Fix
Changes
EncryptedContentAffinityCheck.async_filter_deployments: when the routed pool holds no deployment of the origin's model group, strip the encrypted reasoning and dispatch instead of raisingResponsesAPIRequestUtils.strip_encrypted_reasoning_from_input: drop reasoning items carryingencrypted_content, keeping any readable summary, mutating the list in place so the fallback snapshot stays consistentCaveats
Low
session_affinityon the auto-router pins the tier for callers who need continuity over per-turn routing/v1/messagesmirror (foreign signedthinkingblocks on a tier change) is a separate path, tracked as follow-upScreenshots / Proof of Fix
Rig: an auto-router with tiers on different models (
gpt-5-minireasoning,gpt-5-nanosimple,claude-haiku-4-5bridge),optional_pre_call_checks: ["encrypted_content_affinity"], real provider calls through the sandbox gateway. Each case is two/v1/responsesturns withstore: falseandinclude: ["reasoning.encrypted_content"]; turn 2 replays turn 1's reasoning item. Keywords force the turn-2 tier.Before (01c68c1)
auto-router, turn 2 changes to a native tier
openai/gpt-5-mini, response carries 1 encrypted reasoning item503 ServiceUnavailableError: The deployment that produced this encrypted_content is currently unavailable (likely cooled down) ...; the proxy log showscooldown deployments: []on that turnauto-router, turn 2 changes to a bridge (Anthropic) tier
gpt-5-mini)auto-router, turn 2 stays on the same tier
gpt-5-mini)gpt-5-mini), reasoning replayeddirect model (control)
gpt-5-miniCodex CLI, two-turn session
ERROR: unexpected status 503 Service Unavailable ... url: http://127.0.0.1:PORT/v1/responses, exit 1After (b5d6545)
auto-router, turn 2 changes to a native tier
openai/gpt-5-mini), 1 encrypted reasoning itemopenai/gpt-5-nano; the outbound provider body carries 0 encrypted_content blobs (stripped), the visible turns intactauto-router, turn 2 changes to a bridge (Anthropic) tier
gpt-5-mini)anthropic/claude-haiku-4-5, 0 encrypted blobs outboundauto-router, turn 2 stays on the same tier
gpt-5-mini)gpt-5-mini); the outbound body still replays the encrypted reasoning blob (pin preserved)direct model (control)
gpt-5-miniCodex CLI, two-turn session
three-turn chain (continuity of the stripped turn)
Final Attestation
Note
Medium Risk
Changes routing and request mutation for Responses API encrypted reasoning; wrong membership logic could strip needed blobs or still 503, but behavior is heavily tested and scoped to affinity-marked input.
Overview
Fixes false 503 (and removed-deployment 400) on
/v1/responsesfollow-ups when encrypted_content affinity cannot pin to the origin—especially auto-router tier changes that look like a cooldown but are not.Encrypted content affinity now distinguishes same routed group, origin unavailable (still 429/503 fail-fast) from origin not a candidate for this route (tier change, no boundary peer, removed/forged marker). In the latter case it mutates request
inputin place viastrip_encrypted_reasoning_from_input: dropencrypted_content(and encodedid) on reasoning items, keep readable summary/content, then load-balance the routed pool. Unknown origins skip candidate lookup so responses do not leak deployment-id existence.Router adds read-only
get_candidate_model_ids_for_route(aliases, routing groups, team/pattern routes) so membership is by deployment id, not model-group name spelling.Reviewed by Cursor Bugbot for commit 0450cf9. Bugbot is set up for automated code reviews on this repo. Configure here.