fix(cron): preserve model fallbacks when agent overrides primary

When an agent config specifies `model: { primary: "..." }` without
an explicit `fallbacks` array, the existing code replaced the entire
model object from `agents.defaults`—discarding the default fallbacks.

This caused cron jobs (and agent sessions) to have only one model
candidate (the pinned model) plus the global primary as a final
fallback, skipping all intermediate fallback models.

The fix merges the agent model override into the existing defaults
model object using spread, so that keys like `fallbacks` survive
when the agent only overrides `primary`. Agents can still explicitly
override or clear fallbacks by providing their own `fallbacks` array.

Reproduction scenario:
- `agents.defaults.model = { primary: "codex", fallbacks: ["opus", "flash", "deepseek"] }`
- Agent config: `model: { primary: "codex" }`
- Cron job pins: `model: "flash"`
- Before fix: fallback candidates = [flash, codex] (3 models lost)
- After fix: fallback candidates = [flash, opus, deepseek, ..., codex]
This commit is contained in:
Mahsum Aktas
2026-02-16 19:20:26 +03:00
committed by Peter Steinberger
parent 5a3a448bc4
commit 0ee3480690
2 changed files with 112 additions and 2 deletions

View File

@@ -149,10 +149,14 @@ export async function runCronIsolatedAgentTurn(params: {
params.cfg.agents?.defaults,
agentOverrideRest as Partial<AgentDefaultsConfig>,
);
// Merge agent model override with defaults instead of replacing, so that
// `fallbacks` from `agents.defaults.model` are preserved when the agent
// (or its per-cron model pin) only specifies `primary`.
const existingModel = agentCfg.model && typeof agentCfg.model === "object" ? agentCfg.model : {};
if (typeof overrideModel === "string") {
agentCfg.model = { primary: overrideModel };
agentCfg.model = { ...existingModel, primary: overrideModel };
} else if (overrideModel) {
agentCfg.model = overrideModel;
agentCfg.model = { ...existingModel, ...overrideModel };
}
const cfgWithAgentDefaults: OpenClawConfig = {
...params.cfg,