router: skip tiers whose window cannot hold the history

This commit is contained in:
hermes committed 2026-11-14 11:56:17 +00:00
1 parent 0184627f27
commit e119dc2f0d
1 file changed
+28 -2
+28 -2
View File
@@ -371,7 +371,20 @@ impl Router {
}
};
let prefer = self.cur.map_or(start, |(k, _)| k);
let (kind, model) = pick_for(tier, prefer, avoid, models, &self.cfg)?;
let (mut kind, mut model) = pick_for(tier, prefer, avoid, models, &self.cfg)?;
// the history must fit the window (a 1M session cannot go down to a 200k Haiku)
let mut tier = tier;
while (hx_ai::models::window(models, &model) as usize) * 9 / 10 < sig.ctx {
let up = match tier {
Tier::Fast => Tier::Balanced,
Tier::Balanced => Tier::Deep,
_ => break,
};
let Some((k, m)) = pick_for(up, kind, avoid, models, &self.cfg) else {
break;
};
(tier, kind, model) = (up, k, m);
}
// no Fable in the catalog: it ran as Deep
let tier = if tier == Tier::Max && Tier::of(&model) != Some(Tier::Max) {
Tier::Deep
@@ -485,7 +498,7 @@ mod tests {
ModelInfo {
id: id.into(),
kind,
context_window: 1,
context_window: 1_000_000,
}
}
@@ -635,6 +648,19 @@ mod tests {
);
}
#[test]
fn history_too_big_for_the_window_skips_the_small_tier() {
let mut r = Router::new(Cfg::default());
let mut light = signals("commit", &[]);
assert_eq!(light.tier, Tier::Fast);
light.ctx = 250_000;
let mut c = cat();
c[2].context_window = 200_000;
c[1].context_window = 1_000_000;
let p = r.route(&light, Kind::Claude, None, &c).unwrap();
assert_eq!(p.model, "claude-sonnet-5-5");
}
#[test]
fn effort_follows_score_and_provider() {
assert_eq!(effort_for(-2, Kind::Claude), Effort::Off);