feat(routing): add context-window fallback retry to v2 random-routing#106
feat(routing): add context-window fallback retry to v2 random-routing#106elyasmnvidian wants to merge 2 commits into
Conversation
WalkthroughChangesRandom routing fallback
Estimated code review effort: 4 (Complex) | ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/switchyard-components-v2/src/profiles/random_routing.rs`:
- Around line 164-192: Add concise Rust doc comments to the private helpers
`record_success` and `record_error`, describing their shared role in recording
routing statistics and, for `record_success`, wrapping response usage/stream
handling. Match the brief explanatory style used by `backend_for_target`,
`tier_for_target`, `fallback_processed_request`, and `call_selected`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: a9084d28-b522-47cd-beae-d5b912158485
📒 Files selected for processing (2)
crates/switchyard-components-v2/src/profiles/random_routing.rscrates/switchyard-components-v2/tests/random_routing_profile.rs
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com> (cherry picked from commit 0276280) Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
a5ccb16 to
ea2fcc9
Compare
Live before/after — random-routing now recovers from a context overflowConfig: Before (
After (this branch) — with The rationale header now names the overflow-and-retry instead of reprinting the (now-wrong) random-draw text — an audit follow-up in this push, asserted in |
|
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
Random-routing now retries once on a context-window overflow, matching what
stage_routerandllm_routingalready do.Before, if the randomly selected target rejected a request because the prompt was too long, the random-routing profile returned that
ContextWindowExceedederror straight to the client. Now it retries the request once against a fallback target, and only fails if that target also overflows — in which case it returnsContextPoolExhaustedinstead of the raw overflow.New optional config key on the
random-routingprofile (serve --config):fallback_target_on_evict: the target id to retry after an overflow. Defaults to the strong target.build()rejects any value that is not the profile'sstrongorweaktarget id.Tests in the diff:
run_retries_fallback_target_after_context_overflowdrivesrun()through a weak-target overflow and checks the second backend call lands on the strong target and its response is returned.build_rejects_fallback_target_not_matching_strong_or_weakchecks the config rejects an unknown fallback id.How to try it: add
fallback_target_on_evict: strongunder atype: random-routingprofile whose weak target has a small context window, then send a prompt that overflows the weak target — the response comes back from the strong target instead of erroring.Audit follow-up in this branch: after a fallback switches tiers, the
x-model-router-rationaleheader now names the overflow-and-retry instead of reprinting the original random-draw explanation (which described the wrong tier). The retry test asserts the corrected rationale. Theserve --configdocs fortype: random-routingnow show the optionalfallback_target_on_evictkey.