fix(router): tag-based routing broken when encrypted_content_affinity is enabled - #25347
Conversation
…s in encrypted_content_affinity_check
Using setdefault('litellm_metadata', {}) unconditionally created an empty
litellm_metadata key for chat completions and embeddings. This caused
_get_metadata_variable_name_from_kwargs to return 'litellm_metadata' instead
of 'metadata', so tag-based routing looked for tags in the wrong dict and
ignored all tag filters.
Fix: only set the encrypted_content_affinity_enabled flag when litellm_metadata
already exists (Responses API path). Chat completions and embeddings never have
this key, so nothing is created and tag routing works correctly.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a bug where enabling The fix is minimal and precise:
Confidence Score: 5/5Safe to merge — the fix is minimal, correct, and well-tested with targeted regression tests. The only finding is a P2 style issue (mid-file import in the test file) that has no impact on correctness or runtime behavior. The core fix is sound: replacing unconditional No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py | Core fix: guards encrypted_content_affinity_enabled assignment behind an existence check instead of unconditional setdefault, preventing spurious litellm_metadata injection into non-Responses-API call paths. |
| tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py | Two new regression tests for the fix; bulk of remaining changes are Black reformats. Contains a mid-file module-level import for the new tests. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["async_filter_deployments called"] --> B{"'litellm_metadata' in request_kwargs?"}
B -- "Yes (Responses API path)" --> C["Set encrypted_content_affinity_enabled = True\nin request_kwargs['litellm_metadata']"]
B -- "No (chat / embeddings path)" --> D["Skip flag injection\n(no spurious key created)"]
C --> E{"Encoded model_id in input?"}
D --> E
E -- "Yes" --> F["Pin request to matching deployment"]
E -- "No" --> G["Return all healthy deployments\n(normal load balancing)"]
F --> H["Tag-based routing reads from\ncorrect 'metadata' dict ✓"]
G --> H
Reviews (1): Last reviewed commit: "fix(router): don't create litellm_metada..." | Re-trigger Greptile
- Add 8 content PRs that merged directly to the release branch outside the listed staging PRs: #23769 (Ramp callback), #25252 (JWT OAuth2 override), #25254 (AWS GovCloud mode), #25258 (batch-limit cleanup), #25334 (router custom_llm_provider), #25345 (Triton embeddings), #25347 (tag-based routing), #25358 (Baseten pricing attribution) - Add @kedarthakkar to new contributors (first-ever PR via #23769) - Update RELEASE_NOTES_GENERATION_INSTRUCTIONS: require walking git log range between release tags in addition to staging PRs, and verify new-contributor status per author rather than trusting the GH release body floor
- Add 8 content PRs that merged directly to the release branch outside the listed staging PRs: #23769 (Ramp callback), #25252 (JWT OAuth2 override), #25254 (AWS GovCloud mode), #25258 (batch-limit cleanup), #25334 (router custom_llm_provider), #25345 (Triton embeddings), #25347 (tag-based routing), #25358 (Baseten pricing attribution) - Add @kedarthakkar to new contributors (first-ever PR via #23769) - Update RELEASE_NOTES_GENERATION_INSTRUCTIONS: require walking git log range between release tags in addition to staging PRs, and verify new-contributor status per author rather than trusting the GH release body floor
…s in encrypted_content_affinity_check (BerriAI#25347) Using setdefault('litellm_metadata', {}) unconditionally created an empty litellm_metadata key for chat completions and embeddings. This caused _get_metadata_variable_name_from_kwargs to return 'litellm_metadata' instead of 'metadata', so tag-based routing looked for tags in the wrong dict and ignored all tag filters. Fix: only set the encrypted_content_affinity_enabled flag when litellm_metadata already exists (Responses API path). Chat completions and embeddings never have this key, so nothing is created and tag routing works correctly.
- Add 8 content PRs that merged directly to the release branch outside the listed staging PRs: BerriAI#23769 (Ramp callback), BerriAI#25252 (JWT OAuth2 override), BerriAI#25254 (AWS GovCloud mode), BerriAI#25258 (batch-limit cleanup), BerriAI#25334 (router custom_llm_provider), BerriAI#25345 (Triton embeddings), BerriAI#25347 (tag-based routing), BerriAI#25358 (Baseten pricing attribution) - Add @kedarthakkar to new contributors (first-ever PR via BerriAI#23769) - Update RELEASE_NOTES_GENERATION_INSTRUCTIONS: require walking git log range between release tags in addition to staging PRs, and verify new-contributor status per author rather than trusting the GH release body floor
- Add 8 content PRs that merged directly to the release branch outside the listed staging PRs: BerriAI#23769 (Ramp callback), BerriAI#25252 (JWT OAuth2 override), BerriAI#25254 (AWS GovCloud mode), BerriAI#25258 (batch-limit cleanup), BerriAI#25334 (router custom_llm_provider), BerriAI#25345 (Triton embeddings), BerriAI#25347 (tag-based routing), BerriAI#25358 (Baseten pricing attribution) - Add @kedarthakkar to new contributors (first-ever PR via BerriAI#23769) - Update RELEASE_NOTES_GENERATION_INSTRUCTIONS: require walking git log range between release tags in addition to staging PRs, and verify new-contributor status per author rather than trusting the GH release body floor
|
This seems break the encrypted content tagging when stream: true in responses api |
Relevant issues
Fixes LIT-2326
Pre-Submission checklist
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewType
🐛 Bug Fix
Changes
EncryptedContentAffinityCheck.async_filter_deploymentsusedrequest_kwargs.setdefault("litellm_metadata", {})unconditionally, creating an emptylitellm_metadatakey for every call type (chat completions, embeddings, etc.). This caused_get_metadata_variable_name_from_kwargsto return"litellm_metadata"instead of"metadata", so tag-based routing looked for tags in the wrong dict and ignored all tag filters.Fix: only set
encrypted_content_affinity_enabledwhenlitellm_metadataalready exists inrequest_kwargs(Responses API path). Chat completions and embeddings never have this key, so no spurious key is created and tag routing works correctly.Testing