Skip to content

fix(router): strip encrypted reasoning on an auto-router tier change instead of a 503 - #40280

Merged
tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit7195_autorouter_reasoning_strip
Sep 9, 2026
Merged

tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit7195_autorouter_reasoning_strip

Conversation

@tin-berri

@tin-berri tin-berri commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Auto-router 503s the 2nd Codex turn once it changes tier
  • The error blames a cooldown that never happened
  • Only /v1/responses traffic replaying encrypted reasoning is hit

How it solves it:

  • On a tier change, strip the origin's encrypted reasoning and dispatch
  • Keep the readable summary so the new model has context
  • Same-group unavailability keeps the existing fail-fast

User Flow

Before: a developer runs Codex CLI (store: false, replaying reasoning.encrypted_content) against an auto-router whose tiers span different models, and the second turn dies

  1. They send POST https://litellm-domain/v1/responses with model auto-router, turn 1 classifies to the reasoning tier and returns a reasoning item carrying encrypted_content
  2. They send turn 2 replaying that item; it classifies to a different tier
  3. The response is 503 The deployment that produced this encrypted_content is currently unavailable (likely cooled down) ..., though nothing is cooled down
  4. Pointing Codex straight at the reasoning-tier model instead, the same two turns both return 200

After: the same session completes; the tier-changed turn is answered by the new tier

  1. They send the same turn 1 POST https://litellm-domain/v1/responses and get the reasoning item back
  2. They send the same turn 2; it classifies to a different tier
  3. The proxy forwards the visible history without the undecryptable reasoning and returns 200 from the new tier
  4. A later turn that classifies back to the first tier still returns 200

Relevant issues

Resolves the customer report of ServiceUnavailableError on an auto-router that works when the model is called directly

Linear 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 raising
  • ResponsesAPIRequestUtils.strip_encrypted_reasoning_from_input: drop reasoning items carrying encrypted_content, keeping any readable summary, mutating the list in place so the fallback snapshot stays consistent

Caveats

Low

  • Reasoning continuity across a tier change is not preserved; the new tier reasons fresh. session_affinity on the auto-router pins the tier for callers who need continuity over per-turn routing
  • Selectively keeping the current tier's own reasoning across a tier ping-pong (mixed-origin history) needs pinning to the decrypting deployment; a tier change strips all encrypted reasoning today, which is safe (no foreign blob forwarded) but drops replayable reasoning. Tracked as follow-up on LIT-7195
  • The Anthropic /v1/messages mirror (foreign signed thinking blocks on a tier change) is a separate path, tracked as follow-up

Screenshots / Proof of Fix

Rig: an auto-router with tiers on different models (gpt-5-mini reasoning, gpt-5-nano simple, claude-haiku-4-5 bridge), optional_pre_call_checks: ["encrypted_content_affinity"], real provider calls through the sandbox gateway. Each case is two /v1/responses turns with store: false and include: ["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

  1. Turn 1 -> 200, served by openai/gpt-5-mini, response carries 1 encrypted reasoning item
  2. Turn 2 (forced to the simple tier) -> 503 ServiceUnavailableError: The deployment that produced this encrypted_content is currently unavailable (likely cooled down) ...; the proxy log shows cooldown deployments: [] on that turn

auto-router, turn 2 changes to a bridge (Anthropic) tier

  1. Turn 1 -> 200 (gpt-5-mini)
  2. Turn 2 (forced to the Claude tier) -> 503, same message

auto-router, turn 2 stays on the same tier

  1. Turn 1 -> 200 (gpt-5-mini)
  2. Turn 2 -> 200 (gpt-5-mini), reasoning replayed

direct model (control)

  1. Turn 1 -> 200, Turn 2 -> 200; both on gpt-5-mini

Codex CLI, two-turn session

  1. Turn 1 (ZEBRA) -> answered
  2. Turn 2 (KIWI, resumed session) -> ERROR: unexpected status 503 Service Unavailable ... url: http://127.0.0.1:PORT/v1/responses, exit 1

After (b5d6545)

auto-router, turn 2 changes to a native tier

  1. Turn 1 -> 200 (openai/gpt-5-mini), 1 encrypted reasoning item
  2. Turn 2 (forced to the simple tier) -> 200, served by openai/gpt-5-nano; the outbound provider body carries 0 encrypted_content blobs (stripped), the visible turns intact

auto-router, turn 2 changes to a bridge (Anthropic) tier

  1. Turn 1 -> 200 (gpt-5-mini)
  2. Turn 2 (forced to the Claude tier) -> 200, served by anthropic/claude-haiku-4-5, 0 encrypted blobs outbound

auto-router, turn 2 stays on the same tier

  1. Turn 1 -> 200 (gpt-5-mini)
  2. Turn 2 -> 200 (gpt-5-mini); the outbound body still replays the encrypted reasoning blob (pin preserved)

direct model (control)

  1. Turn 1 -> 200, Turn 2 -> 200; both on gpt-5-mini

Codex CLI, two-turn session

  1. Turn 1 (ZEBRA) -> answered, exit 0
  2. Turn 2 (KIWI, resumed session) -> answered by the simple tier, exit 0

three-turn chain (continuity of the stripped turn)

  1. Turn 1 (ZEBRA) -> 200, deployment A (reasoning tier)
  2. Turn 2 (KIWI) -> 200, deployment B (simple tier), origin reasoning stripped
  3. Turn 3 (KIWI) -> 200, deployment B again; turn 2's fresh reasoning, minted by B, is replayed and pinned to B

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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/responses follow-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 input in place via strip_encrypted_reasoning_from_input: drop encrypted_content (and encoded id) 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.

@tin-berri

Copy link
Copy Markdown
Contributor Author

Docs PR: BerriAI/litellm-docs#1272

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@codspeed

codspeed Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_lit7195_autorouter_reasoning_strip (0450cf9) with litellm_internal_staging (7c6e33e)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (c7163a8) during the generation of this report, so 7c6e33e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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 model_name, and the tests do not directly cover a mixed pool containing both the origin model group and a different group, or the full three-turn fallback/continuity path. Those are coverage risks rather than a demonstrated correctness issue.

@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes encrypted-content affinity handling so Responses API follow-ups can continue after a routed model-group change.

  • Cross-group routing strips encrypted reasoning while preserving readable summaries and shared fallback input state.
  • Same-group unavailability is intended to retain the existing fail-fast behavior.
  • Regression tests cover cross-group stripping, string summaries, same-group cooldowns, and model-group spelling differences.
  • The new membership lookup does not mirror pattern and team-public route resolution, leaving those same-group cases misclassified.

Confidence Score: 4/5

The 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 get_model_ids(model_name=model) returns no matching IDs. If the originating deployment is unavailable, the new branch then strips its reasoning and dispatches instead of preserving the same-group fail-fast contract. The previous routing-group and string-content findings are fixed, while the mixed-history and line-length findings were withdrawn.

Files Needing Attention: litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py

Important Files Changed

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

Comment on lines +221 to +223
return bool(healthy_deployments) and all(
deployment.get("model_name") != originating.model_name for deployment in healthy_deployments
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +556 to +557
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread litellm/responses/utils.py Outdated
Comment on lines +579 to +580
def _blocks(value: object) -> tuple[object, ...]:
return tuple(cast(list[object], value)) if isinstance(value, list) else () # cast-ok: untyped client json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 String reasoning is deleted Cross-tier requests treat supported string content as unreadable, deleting plaintext reasoning and depriving the selected model of visible context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread litellm/responses/utils.py Resolved
@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/router.py 84.21% 3 Missing ⚠️
litellm/responses/utils.py 92.30% 2 Missing ⚠️
...re_call_checks/encrypted_content_affinity_check.py 93.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from d94733b to b5d6545 Compare September 8, 2026 20:14
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Score: 4/5

This is a strong, targeted fix. The cross-model-group branch in litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py:289 correctly distinguishes an auto-router tier change from same-group unavailability, preserves the existing affinity pinning/fail-fast behavior, and mutates the shared input list so fallback routing sees the stripped state. The helper in litellm/responses/utils.py:546 also preserves readable summaries while removing undecryptable reasoning, and the tests cover both the positive tier-change path and the negative same-group path. The reported Buildkite E2E check is green as well.

I’m not giving it 5/5 only because the new discriminator depends on originating.model_name != model, so an explicit test for provider-qualified or otherwise normalized model-group names would further protect against false tier-change detection. That is a minor hardening gap rather than a blocker; the implementation and evidence otherwise support merging.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tin-berri

Copy link
Copy Markdown
Contributor Author

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.

@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from b5d6545 to 98bde78 Compare September 9, 2026 00:22
@tin-berri

Copy link
Copy Markdown
Contributor Author

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

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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.

@tin-berri
tin-berri enabled auto-merge (squash) September 9, 2026 00:29
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptile review

@tin-berri
tin-berri disabled auto-merge September 9, 2026 00:30
# 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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from 98bde78 to 49ba6fe Compare September 9, 2026 00:55
@tin-berri

Copy link
Copy Markdown
Contributor Author

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

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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 model_name. This closes the team-public and pattern-route gaps while avoiding false stripping for same-group requests. Cross-group requests still strip encrypted reasoning in place, and same-group unavailability preserves the existing fail-fast behavior. The regression coverage and latest Buildkite E2E status are green, so I have no remaining blocking findings.

@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from 49ba6fe to f970957 Compare September 9, 2026 01:06
@tin-berri

Copy link
Copy Markdown
Contributor Author

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

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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 test_router.py merge resolution also keeps both the existing drop_params tests and the new LIT-7195 candidate-ID test, so I see no coverage regression from the conflict resolution.

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.

@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from f970957 to 652a78b Compare September 9, 2026 02:13
@tin-berri

Copy link
Copy Markdown
Contributor Author

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

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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.

@veria-ai

veria-ai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from 652a78b to 98cb68f Compare September 9, 2026 05:45
@tin-berri

Copy link
Copy Markdown
Contributor Author

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

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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 BadRequestError path is removed. The router carries the deployment IDs resolved for the route through request_kwargs, preserving fail-fast behavior for same-group unavailability, including team and pattern routes. Regression coverage includes unknown origins, cross-group stripping, same-group failures, alternate route spellings, and candidate-ID plumbing. No blocking issues remain; the latest CI/E2E status is still pending.

@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from 98cb68f to 9686a04 Compare September 9, 2026 17:34
@tin-berri

Copy link
Copy Markdown
Contributor Author

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
@tin-berri
tin-berri force-pushed the litellm_lit7195_autorouter_reasoning_strip branch from 9686a04 to 0450cf9 Compare September 9, 2026 17:48
@tin-berri

Copy link
Copy Markdown
Contributor Author

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

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Score: 9/10

The fix is implemented correctly and the follow-up coverage is strong:

  • Cross-group and unknown-origin requests strip encrypted reasoning in place while preserving readable summaries.
  • Same-group unavailability still fails fast, preserving the existing cooldown behavior.
  • Candidate deployment resolution is centralized in Router and covers aliases, routing groups, team routes, and pattern routes without relying on fragile model-name comparisons.
  • Tests now cover the helper directly, cross-group stripping, same-group fail-fast behavior, string and block summaries, unknown markers, and shared-list identity.
  • The unit-test shards were green, and the current CI status is successful.

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 thinking path remains a follow-up. There is also some broad formatting churn in the existing test file, which increases review surface without changing behavior. I found no blocking correctness issues.

@tin-berri
tin-berri merged commit c82c9cb into litellm_internal_staging Sep 9, 2026
82 checks passed
@tin-berri
tin-berri deleted the litellm_lit7195_autorouter_reasoning_strip branch September 9, 2026 18:04
@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread litellm/router.py Resolved
tin-berri added a commit that referenced this pull request Sep 9, 2026
…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>
mateo-berri added a commit that referenced this pull request Sep 10, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants