Repository navigation
fix(router): inspect image content without translating routed requests - #49371
Conversation
|
@greptileai please review the image-routing fix at 2d7ac70, including malformed payload handling and preservation of valid image routing. |
|
bugbot run — please review 2d7ac70 for image-routing regressions, malformed payload handling, and preservation of supported native image formats. |
[Medium impact] The reviewed changes appear safe to merge, with no blocking issue found SummaryThe router now checks native request content for images instead of translating requests through guardrail handlers
No actionable issues were found. The previous-review merge bases differed, so this review used the full PR diff. No previous Greptile threads were supplied Reviews (4) · Last reviewed commit: "test: make monthly budget reset coverage..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
|
@greptileai please review e2632a8, including the screenshot-content, tool-output, and URL-alias regression fix. Local tests and canonical gates pass. |
|
bugbot run — please review e2632a8 and confirm the screenshot-routing finding is resolved. Four targeted HTTP probes now select vision. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai please review aac32c6f7b7, including the deterministic monthly budget regression test. All 492 affected local tests and canonical lint gates pass. |
|
bugbot run on aac32c6f7b7 please. The followup only fixes calendar-dependent budget test setup; production budget behavior remains unchanged. |
aac32c6 to
49f479e
Compare
|
@greptileai please review rebased tip 49f479e. Main budget helper changes are preserved; deterministic coverage, 493 affected tests, and canonical gates pass. |
|
bugbot run on rebased tip 49f479e please. Image patches are unchanged; the monthly budget regression now uses explicit dates. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 49f479e. Configure here.
Routed moderation and embedding requests can fail with 500 before reaching their provider because image detection translates unrelated request bodies. This fix inspects native image content directly, preserves valid image routing, and lets malformed Messages requests reach the provider's existing 400 response.
Details
TLDR
Problem this solves:
How it solves it:
User Flow
Before: ordinary requests fail with an internal server error.
POST https://litellm-domain/v1/moderationswith a list of strings, or embeddings with empty messages.str.getor missingmodel).POST https://litellm-domain/v1/messages; observe HTTP 500 for streaming and non-streaming requests.After: requests receive their expected provider response.
Relevant context
f7f87e6193e151db09ce3db40f26dcff5333a59b.File changes
litellm/router.py: inspect originalmessages/inputinstead of resolving through guardrail translators.litellm/litellm_core_utils/prompt_templates/common_utils.py: tolerate non-message values and malformed nested parts; recognize chat, Responses, Anthropic, and tool-output images.tests/unit/proxy/hooks/test_unit_test_max_model_budget_limiter.py: inject a fixed clock and explicit expired calendar windows, covering October 31 and leap/non-leap February. After main incorporated test(budgets): age the monthly window past any calendar month so the reset test passes on the 31st #49372, this retains its corrected helper and extends the test with deterministic calendar coverage; production budget code is unchanged.Screenshots / Proof of Fix
Baseline:
1595adfb2f678c54c6161d870956c366fbd134b5.Current tip:
49f479e31183bd7f6e77a296c79b917319a0b014.Local candidate HTTP evidence below was refreshed at the current tip using a native extension built from matching Rust source. Both local baseline refresh and independent final-tip verification completed.
Executed the unchanged integration cases against real local proxy, PostgreSQL, Redis, and scripted HTTP upstream processes. Native extension built from pinned repository source. Baseline reused the candidate checkout with both changed production files restored byte-for-byte using
git show BASE:path; all other production files and integration tests are identical. Restored the candidate before the final run; final checkout is clean.strhas noget/v1/messagesomni-moderations-next-listcost casestrhas nogetmodelmodelBaseline: 5 failed in 35.95s. Candidate: 5 passed in 31.89s.
Exact test selection (with the repository's
owned_upstream,owned_proxy, andcost_map_environmentharness):python -m pytest \ tests/integration/providers/test_moderations_wire.py::test_openai_sdk_moderation_inputs_reach_upstream_as_exact_model_and_input \ tests/integration/messages_endpoint/providers/anthropic/test_passthrough_migration_wire.py::test_passthrough_bad_request_returns_400_v1_messages \ 'tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[omni-moderations-next-list]' \ tests/integration/observability/test_azure_content_safety_dispatch.py::test_e1_empty_messages_matches_base_guardrail_response \ -q --tb=shortScreenshot routing controls at
49f479e3118: message-content screenshots, function/custom tool-output screenshots, and computer-outputurlaliases each returned 200, selected the explicitly vision-capable deployment, and preserved the upstreaminput. The group had twoopenai/gpt-4odeployments: text-only (model_info.supports_vision=false,order=0) and vision (supports_vision=true,order=1). Synthetic provider keys identified the selected deployment in recorded HTTP headers.Reproduction request, repeated for each native input shape:
The other inputs are
function_call_outputandcustom_tool_call_outputitems with that screenshot inoutput: [...], andcomputer_call_outputwithoutput: {"type":"computer_screenshot","url":"https://example.invalid/screenshot.png"}. Each recorded upstream authorization wasBearer synthetic-vision; each recorded input exactly matched the request.Local affected tests at current tip: 493 passed, including all 85 budget-limiter tests. The old budget reset test fails on October 31 UTC; the replacement passes all three fixed dates and asserts both spend reset and the exact next reset timestamp. Canonical
make lint-checks BASE_REF=1595adfb2f678c54c6161d870956c366fbd134b5passed, including production/test Ruff, formatting, strict-rule, type-discipline, test-quality, basedpyright budget, E2E typing, and import checks. Existing Pydantic/legacy-alias warnings are unrelated.Local coverage: 17/17 changed executable lines (100%); 14/14 measured touched-function branch edges. These are focused change metrics, not repository-wide coverage. The completed Codecov report confirms 17/17 patch lines covered (100%) after both current-tip uploads merged. Repository-wide coverage is 89.57%; that is separate from the focused line/branch metrics.
Independent Devin final-tip report and artifacts completed for baseline
1595adfb2f678c54c6161d870956c366fbd134b5and final49f479e31183bd7f6e77a296c79b917319a0b014: five baseline failures became five passes. Independent real-HTTP controls preserved chat/Responses/Anthropic image routing, all four screenshot formats, unknown-capability and all-text-only fallback, cooldown behavior, and upstream request bodies. Sync/async SDK controls also passed. Separate source worktrees used a fresh native build from identical baseline/head Rust sources.Devin additionally ran all 85 budget-file tests with both real time and frozen October 31, including all three fixed-date cases. The historical test failed at
e2632a8e; the new main baseline already passes after #49372. No change-caused regressions or blockers were found; temporary services, builds and worktrees were cleaned up.Pre-Submission checklist
49f479e3118.49f479e3118, with zero unresolved actionable findings and zero Bugbot annotations. Veria also passed.49f479e3118.Main already fixes the old budget failure through #49372. This PR now adds deterministic coverage on top of that fix. Historical budget test reproduction: with
TZ=UTC, the previous test computes a 30-day age on October 31, placing the start on October 1. That calendar window ends November 1 and correctly retains spend. The replacement uses a fixed clock and actually expired starts, preserving the original limit/reset assertions. This failure also appears in the baseline unit run.CI results at final tip
All five configured required checks pass:
unit passed,lint passed,smoke passed,cost-map-guard, andspend-logs-guard. The previously failingbudgetsshard passes. Existing human approval remains recorded.All original five integration regressions pass in the current integration run: moderation and malformed Messages in providers, omni-moderations-next-list in cost, and both Azure E1 cases in extensions.
Unrelated integration failures remain outside this PR: Cohere token counts (cost), unpriced response-cost header (accounting), a PyPI network failure while building test infrastructure (management), and existing provider/extension assertions. Provider failures are a subset of the main run, with no PR-only failures; likewise extensions. These failed checks have not been represented as passed or bypassed.
Type
🐛 Bug Fix