Skip to content

fix: resolve routing tier for fallback and affinity-reuse decisions - #273

Open
thossullivan wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
thossullivan:fix/fallback-tier-resolution
Open

fix: resolve routing tier for fallback and affinity-reuse decisions#273
thossullivan wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
thossullivan:fix/fallback-tier-resolution

Conversation

@thossullivan

@thossullivan thossullivan commented Aug 4, 2026

Copy link
Copy Markdown

What

Resolve the routing tier for fallback and affinity-reuse decisions in llm_classifier cascades, so switchyard.requests (and the routing log) carry a tier attribute on every decision path. This matches what the context-overflow fallback already does.

Closes #276

Why

When the judge abstains or is unavailable, the cascade's DefaultTarget decides; on sticky turns, AffinityRouter decides. Neither implements Classifier::routing_tier, so the trait default returns None (crates/libsy/src/core/classifier.rs:75-77) and the metric is emitted with no tier attribute (crates/libsy/src/algorithms/fall_through.rs:294, crates/libsy/src/observability.rs:548-551). The same strong model then lands in two time series, one labeled and one not, and consumers cannot unify them. We hit this monitoring a governed dispatch system: one agentic session showed 1 request labeled tier="weak" and 45 on the strong model with no tier at all (mechanism: #272).

The overflow fallback already resolves the tier across the cascade via find_map (fall_through.rs:221-233). This PR applies the same pattern to the primary decision path. Because TaskClassifier::routing_tier maps model name to tier, both halves get the tier of the model actually selected: a judge-abstain fallback gets tier="strong" and an affinity reuse gets the pinned model's tier. No new tier values, no trait changes.

Related: #205 (in flight) answers how often the classifier failed open and why, with a dedicated counter; this PR answers which tier actually served. They compose, and we are glad to rebase over #205 whenever it lands (same test file). Prior art considered: #31, #135, #168.

How tested

  • uv run ruff check . clean (no Python changes)
  • uv run mypy switchyard clean (no Python changes)
  • uv run pytest tests/ green: 1330 passed, 31 skipped (no Python changes)
  • Manual smoke: patched release switchyard-server, classifier route with a weak and strong pair over OpenRouter. A trivial request classified weak (switchyard_requests_total{model="deepseek/deepseek-v4-flash-0731",tier="weak"} 1). A tool-continuation request, whose newest message is a tool result the judge cannot classify, fell back (switchyard_requests_total{model="openai/gpt-5.6-sol",tier="strong"} 1). Before this change the second series had no tier attribute.
  • Rust on the pinned toolchain (1.96.1): cargo fmt --check and clippy clean; cargo test -p switchyard-libsy green (231 tests). The two new tests, judge_unavailable_fallback_keeps_the_tier_label and affinity_reuse_keeps_the_tier_label, fail without the fall_through.rs change.

Checklist

  • One class per file; filename = snake_case of the primary class. (n/a, Rust only)
  • New public symbols exported from switchyard/__init__.py.__all__ if intended for downstream use. (n/a)
  • Unit tests added for new components / bug fixes.
  • README / --help updated if customer-facing surface changed. (n/a, this completes an existing metric attribute; glad to add a line to the metrics reference doc if wanted)
  • Commits signed off (Signed-off-by:) per the DCO.

Notes for reviewers

Summary by CodeRabbit

  • Bug Fixes

    • Improved request routing when the primary classifier does not provide a routing tier.
    • The system now checks fallback options and selects the appropriate tier for the resolved target while preserving the primary decision when available.
  • Observability

    • Added coverage to ensure fallback routing and session affinity report accurate tier labels and maintain consistent metrics across repeated requests.

A judge-abstain or judge-unavailable fallback is decided by DefaultTarget,
and an affinity-reuse turn by AffinityRouter; neither implements
Classifier::routing_tier, so switchyard.requests was emitted without a
tier attribute and the same strong model landed in two time series.
Resolve the tier across the cascade with the same find_map pattern
fallback_decision already uses for context-overflow fallbacks.

Tests: judge-unavailable and affinity-reuse cases in
tests/observability.rs assert the labeled series; both fail without the
fall_through.rs change.

Signed-off-by: thossullivan <tomhsullivan@outlook.com>
@thossullivan
thossullivan requested a review from a team as a code owner August 4, 2026 02:14
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

FallThrough::route now finds a tier from the classifier cascade when the deciding classifier lacks one. Observability tests cover unavailable-judge fallback and session-affinity tier labels.

Changes

Tier Routing and Observability

Layer / File(s) Summary
Cascade tier resolution
crates/libsy/src/algorithms/fall_through.rs
FallThrough::route checks the classifier cascade for a tier associated with the resolved target when the deciding classifier provides none.
Fallback and affinity observability
crates/libsy/tests/observability.rs
Added a client stub and tests for classifier timeouts, strong-tier fallback, and weak-tier session-affinity metrics.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit watched the tiers align,
Through cascading paths they shine.
When judges pause, the route goes on,
Strong and weak labels both stay drawn.
Two requests share one metric trail,
Hop, hop—fallbacks never fail!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: resolving routing tiers for fallback and affinity-reuse decisions.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/libsy/tests/observability.rs`:
- Around line 1233-1245: Extend the observability test around the two-request
loop to track non-routed judge calls in ClassifierClient, then assert that the
second request does not increase that count. Keep the existing routing_tier
assertions, and use the recorded call count to verify the second request reuses
the session-affinity decision path rather than invoking the judge again.
🪄 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: d2d5e19e-2405-44c7-8282-6f94390ca9cb

📥 Commits

Reviewing files that changed from the base of the PR and between a9c04b3 and 50c8be2.

📒 Files selected for processing (2)
  • crates/libsy/src/algorithms/fall_through.rs
  • crates/libsy/tests/observability.rs

Comment thread crates/libsy/tests/observability.rs
Review feedback: the affinity test could pass even if the second request
were re-classified rather than reusing the pin, since a fresh judge run
would also yield tier weak. Count non-routed judge calls in
ClassifierClient and assert the second request adds none.

Signed-off-by: thossullivan <tomhsullivan@outlook.com>
@ayushag-nv

Copy link
Copy Markdown
Contributor

@thossullivan Thanks for putting up the PR. Can you put up a Issue and link a PR to that.

@thossullivan

Copy link
Copy Markdown
Author

Filed #276 for this and linked it in the description. Thanks for the look!

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.

[bug] llm_classifier: fallback and affinity-reuse decisions emit switchyard.requests without a tier attribute

2 participants