fix: preserve agent model fallbacks when switching models#1160
Merged
hazeone merged 1 commit intoJul 15, 2026
Merged
Conversation
updateAgentModel() replaced the agent's model block wholesale with
{ primary }, silently discarding any configured fallbacks array. The
resulting block also suppressed agents.defaults.model.fallbacks, because
the OpenClaw runtime treats a per-agent model block without a fallbacks
key as an explicit empty fallback override. Net effect: any in-chat
model switch silently disabled all model failover for that agent.
Merge the new primary into the existing block instead, and inherit the
defaults fallback chain whenever the resulting block would lack one, so
switching models never turns off failover.
Fixes ValueCell-ai#1159
Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1159.
Problem
updateAgentModel()inelectron/utils/agent-config.tsreplaced the agent'smodelblock wholesale with{ primary: modelRef }on every model switch (in-chat picker or Agents dialog). This has two destructive effects:fallbacksarray in that block is silently discarded.{ primary }-only block disables the agent's entire fallback chain: the OpenClaw runtime'sresolveSelectedModelFallbacksOverride()treats a per-agent model block that hasprimarybut nofallbackskey as an explicit empty fallback override, which suppressesagents.defaults.model.fallbackstoo. The gateway then reportsfallbackConfigured: false, and a 429/rate-limit on the primary fails the turn with no fallback attempted.Nothing in the UI indicates failover was turned off. Full analysis, logs, and reproduction in #1159.
Fix
primary, preservingfallbacks(and any other fields).fallbackskey (fresh block, or a pre-existing bare-primary block), copyagents.defaults.model.fallbacksinto it, so a per-agent primary never silently disables failover.The
modelRef: nullpath (reset to default) is unchanged — deleting the block correctly falls back to the defaults chain.Testing
tsc --noEmit -p tsconfig.node.jsonclean for this file (one pre-existing unrelated error about the generated_ext-bridge.generatedmodule in a fresh checkout).updateAgentModel()against a real config, all three paths:{ primary, fallbacks: [defaults chain] }inherited;null→ block deleted (unchanged behavior).{ "primary": "openrouter/qwen/qwen3.6-flash", "fallbacks": [ ...full defaults chain... ] }and gateway failover kept working.An alternative design would be to keep per-agent blocks primary-only and change the empty-override semantics in the openclaw runtime instead — happy to rework if maintainers prefer that direction.
🤖 Generated with Claude Code