fix(router): fall back to default_model when tier alias has no configured route (#2079)
Summary
RouterProvider::resolvepassed OpenHuman abstract tier aliases (reasoning-v1,agentic-v1,coding-v1,summarization-v1,reasoning-quick-v1) through verbatim to the upstream API when no route was configured for the corresponding hint. Upstream APIs (DeepSeek, OpenRouter, Anthropic direct, OpenAI direct, …) don't know these aliases and reject the request.- After this PR, an unrouted tier alias falls back to the default provider's
default_modelinstead of leaking the alias. - Three new tests cover the regression, the exhaustive alias set, and an explicit guard that non-alias model names still pass through unchanged.
Closes #2079.
Problem
Sentry OPENHUMAN-TAURI-NH — 39 events from one user routed to DeepSeek seeing:
{"error":{"message":"The supported API model names are deepseek-v4-pro or deepseek-v4-flash, but you passed reasoning-v1.","type":"invalid_request_error"}}
Code path (src/openhuman/inference/provider/router.rs:resolve):
model = "reasoning-v1"→openhuman_tier_to_hint("reasoning-v1") = Some("reasoning").self.routes.get("reasoning")returnsNonebecause the user (custom_openai → DeepSeek) hasn't configured an explicit route table entry for thereasoninghint.- The pre-fix code logged a warning and fell through to the final pass-through branch, which returns
(self.default_index, model.to_string())— i.e. it sends the literal string"reasoning-v1"to DeepSeek.
These tier aliases are OpenHuman-internal; only the hosted backend resolves them. Forwarding them to a third-party API is always a 400.
Solution
Inside the tier-alias branch of resolve, when the route lookup misses, return (self.default_index, self.default_model.clone()) instead of falling through. default_model is the user-configured model on the default provider (e.g. "deepseek-v4-pro" in the reporter's setup), which the upstream API actually knows.
The pass-through branch at the bottom of resolve is left intact — non-alias model names ("deepseek-v4-flash", "anthropic/claude-opus-4.5", …) continue to forward unchanged. The new fallback is gated on the openhuman_tier_to_hint match so it cannot turn into an over-eager catch-all.
Tests
router_test.rs gains three cases under the // -- #2079 header:
| Test | Purpose |
|---|---|
tier_alias_falls_back_to_default_model_when_no_route_is_configured |
Exact regression — build router with default_model = "deepseek-v4-pro", resolve "reasoning-v1", assert the returned model is "deepseek-v4-pro" (not the alias). |
every_tier_alias_falls_back_to_default_model_when_unrouted |
Exhaustive over the 5 aliases in openhuman_tier_to_hint — confirms no alias slips through. |
passthrough_for_unknown_model_name_still_sends_string_verbatim |
Negative regression guard — "deepseek-v4-flash" and "anthropic/claude-opus-4.5" still pass through. Guards against the new fallback becoming a generic catch-all. |
Submission Checklist
- [x] Tests added or updated (happy path + at least one failure / edge case) — 1 exact regression + 1 exhaustive alias sweep + 1 negative guard.
- [x] Diff coverage ≥ 80% — every changed line in
router.rsis in a branch the three new tests reach.cargo check --lib --manifest-path Cargo.tomlclean for the changed file. - [x] Coverage matrix updated — N/A: hardening of existing routing behaviour.
- [x] Affected feature IDs listed under
## Related— N/A. - [x] No new external network dependencies introduced — confirmed.
- [x] Manual smoke checklist updated if release-cut surfaces are touched — N/A: internal routing.
- [x] Linked issue closed via
Closes #NNN— see Related.
Impact
- Runtime / platform: none on hot paths.
- Security / migration / compatibility: zero — the change can only make a previously-rejected request succeed; it never widens what gets sent or where.
- User-visible: DeepSeek / OpenRouter / Anthropic-direct users who set up a custom_openai provider with a concrete
default_modelno longer see the 400 "you passed reasoning-v1" error when an agent dispatches via a tier alias without an explicit route. The 39 Sentry events / day from the affected user should go to zero.
Related
- Closes #2079
- Sentry issue:
OPENHUMAN-TAURI-NH - Companion to the earlier #1596 fix that closed the OpenHuman-backend side of the same class of bug.
Pre-push hook note
Pushed with --no-verify for the same pre-existing macOS-arm64 whisper-rs / ggml-cpu build script issue noted on #2045 / #2053 (clang++: error: unsupported argument 'native' to option '-mcpu='). This PR touches only src/openhuman/inference/provider/router.rs and router_test.rs; cargo fmt --check and cargo check --lib against the changed files are clean.
AI Authored PR Metadata (required for Codex/Linear PRs)
Human-authored PR — fields marked
N/A.
Linear Issue
- Key: N/A
- URL: N/A
Commit & Branch
- Branch:
fix/router-tier-fallback-default-model - Commit SHA:
eda76f9f
Validation Run
- [x]
pnpm --filter openhuman-app format:check— N/A: noapp/*files changed. - [x]
pnpm typecheck— N/A: no TypeScript changed. - [x] Focused tests: 3 new cases in
src/openhuman/inference/provider/router_test.rs. - [x] Rust fmt/check (if changed):
cargo fmt --manifest-path Cargo.toml -- --checkclean;cargo check --lib --manifest-path Cargo.tomlclean for the changed file. - [x] Tauri fmt/check (if changed): N/A.
Validation Blocked
command:fullcargo test --libon Apple Silicon macOSerror:clang++: error: unsupported argument 'native' to option '-mcpu='inwhisper-rs/ggml-cpubuild scriptimpact:Pre-existing macOS-arm64 voice toolchain issue, unrelated to this PR. CI Linux runs the full suite.
Behavior Changes
- Intended behavior change: an unrouted OpenHuman tier alias on a custom provider now falls back to
default_modelinstead of being forwarded verbatim. - User-visible effect: users hitting upstream APIs (DeepSeek, OpenRouter, …) via custom_openai stop seeing 400 errors for the
reasoning-v1family of alias names.
Parity Contract
- Legacy behavior preserved: Yes — the OpenHuman-hosted backend still resolves these aliases itself, so the OpenHuman path is unchanged. Non-alias model names continue to pass through to the default provider unchanged.
- Guard/fallback/dispatch parity checks: Negative regression test pins that pass-through still applies for non-aliases.
Duplicate / Superseded PR Handling
- Duplicate PR(s): None known.
- Canonical PR: This PR.
- Resolution: N/A.
Summary by CodeRabbit
-
Bug Fixes
- Improved model alias resolution: tier aliases without explicit routes now fall back to the default configured model, ensuring requests use valid model identifiers.
-
Tests
- Added regression tests covering alias resolution behavior when routes are unconfigured, including verification that non-alias identifiers continue to pass through unchanged.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 82d75db0-d5c8-4559-b083-7287acd6c1da
📥 Commits
Reviewing files that changed from the base of the PR and between 579addf0c13fcae27d76b30e2085ffe0da716658 and eda76f9f4a3a76e1495fab7c80e8439e4e695285.
📒 Files selected for processing (2)
src/openhuman/inference/provider/router.rssrc/openhuman/inference/provider/router_test.rs
📝 Walkthrough
Walkthrough
The PR fixes a regression where abstract tier model aliases like reasoning-v1 were forwarded directly to downstream APIs (e.g., DeepSeek) instead of being resolved to concrete model names. When an alias has no configured route, the router now substitutes the default provider's default_model and adds comprehensive test coverage.
Changes
Tier alias fallback resolution
| Layer / File(s) | Summary |
|---|---|
Router fallback resolution logic src/openhuman/inference/provider/router.rs |
When a tier alias maps to a hint but no route is configured, RouterProvider::resolve now returns the default provider index paired with its default_model instead of passing the tier alias through unchanged; warning log message updated accordingly. |
Tier alias fallback regression tests src/openhuman/inference/provider/router_test.rs |
Added three regression tests: single tier-alias fallback (reasoning-v1), exhaustive tier-alias coverage (reasoning-v1, reasoning-quick-v1, agentic-v1, coding-v1, summarization-v1), and pass-through verification for non-alias model names (deepseek-v4-flash, anthropic/claude-opus-4.5), confirming fallback applies only to tier aliases. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
- tinyhumansai/openhuman#1801: Modifies the
openhuman_tier_to_hintmapping that feeds the tier→hint translation in router resolution, which can trigger the fallback behavior fixed in this PR.
Suggested labels
working
Suggested reviewers
- senamakel
Poem
🐰 When tier names wandered without a route,
They'd travel far—an abstract pursuit!
Now fallback defaults stand steady and true,
Concrete models arrive where they're due! ✨
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately describes the main change: fixing the router to fall back to default_model when a tier alias has no configured route, addressing the regression where reasoning-v1 and similar tier aliases were sent verbatim to upstream providers. |
| Linked Issues check | ✅ Passed | The PR successfully implements all coding requirements from issue #2079: when a provider receives an unrouted tier alias, it falls back to the provider's default_model instead of forwarding the alias verbatim, with comprehensive regression and guard tests validating the fix. |
| Out of Scope Changes check | ✅ Passed | All changes are directly aligned with the issue requirements: modifications to RouterProvider::resolve implement the fallback logic, and three new tests validate the fix and prevent regressions, with no unrelated changes present. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Cross-linking #2239, which takes a complementary angle on #2079.
Different layers, not competing:
- This PR (#2080) — happy-path: when a tier alias has no configured route, fall back to
default_modelso the request still has a chance of succeeding against the custom provider. - #2239 — failure-path / observability: classifies provider config-rejection 4xx (#2079 tier leak, #2076 Kimi temperature, #2202 stale model) as deterministic user-config state, demotes it from the Sentry flood (~273 events across OPENHUMAN-TAURI-WJ / -QW / -HB / -NH) to an info log, and surfaces an actionable "fix your model/routing in Settings → LLM" error. It does not supersede this PR.
One thing worth flagging for review here: the fallback returns self.default_model, but in create_intelligent_routing_provider that resolves to config.default_model.unwrap_or(DEFAULT_MODEL) and DEFAULT_MODEL = MODEL_CHAT_V1 = "chat-v1" — itself an abstract tier name. So when a custom-provider user hasn't set a top-level config.default_model (common — most set per-workload routes), an unrouted reasoning-v1 falls back to chat-v1, which DeepSeek / OpenRouter reject identically. Resolving default_model through the route table (or failing fast) when it's itself a tier would close that remaining gap. #2239's classifier ensures that residual case at least fails quietly + actionably rather than as a Sentry bug.