Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

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

thossullivan247dff8629f2
diff --git a/crates/libsy-llm-client/tests/observability.rs b/crates/libsy-llm-client/tests/observability.rs
index b90bb8236..61048d162 100644
--- a/crates/libsy-llm-client/tests/observability.rs
+++ b/crates/libsy-llm-client/tests/observability.rs
@@ -1436,3 +1436,39 @@ async fn classifier_fail_open_records_each_failure_stage() -> switchyard_libsy::
}
Ok(())
}
+
+/// A decision made by the cascade fallback still names its routing tier.
+///
+/// The judge call fails, so `TaskClassifier` fails open and `DefaultTarget`
+/// decides. That decider defines no tier of its own, so without the cascade
+/// lookup the selection logs `tier: None` while a judged decision to the same
+/// target logs its tier. `AffinityRouter` reuse takes the same path.
+#[tokio::test]
+async fn fallback_decision_logs_the_routing_tier() -> switchyard_libsy::Result<()> {
+ let _guard = serialize_test().lock().await;
+ let (store, _, _, _, _) = telemetry();
+
+ let client = Arc::new(JudgeClient {
+ judge_model: "ft-judge".into(),
+ outcome: JudgeOutcome::CallFailure,
+ }) as Arc<dyn RoutedLlmClient>;
+ run(
+ classifier_router("ft-judge", "ft-weak", "ft-strong")?,
+ client,
+ classifier_request(),
+ )
+ .await?;
+
+ let events = store.events();
+ assert!(
+ events.iter().any(|event| {
+ event.fields.get("target").map(String::as_str) == Some("ft-strong")
+ && event
+ .fields
+ .get("tier")
+ .is_some_and(|tier| tier.contains("strong"))
+ }),
+ "fallback selection logged without its routing tier: {events:?}"
+ );
+ Ok(())
+}
diff --git a/crates/libsy/src/algorithms/fall_through.rs b/crates/libsy/src/algorithms/fall_through.rs
index 8bfcd95ca..23e336cf1 100644
--- a/crates/libsy/src/algorithms/fall_through.rs
+++ b/crates/libsy/src/algorithms/fall_through.rs
@@ -264,7 +264,13 @@ where
// 3. Resolve the target and log the choice.
algorithm::ensure_model_is_target(&self.targets, &score.target)?;
let target = score.target.clone();
- let tier = deciding.routing_tier(&target);
+ // A fallback or affinity-reuse decider carries no tier of its own, so
+ // resolve it across the cascade rather than logging it as None.
+ let tier = deciding.routing_tier(&target).or_else(|| {
+ self.classifiers
+ .iter()
+ .find_map(|c| c.routing_tier(&target))
+ });
tracing::info!(algorithm=self.name, target=%score.target, confidence=score.confidence, tier = ?tier, "Model selected");
// 4. Post-decision replay: every processor sees the selection so stateful ones