fix(agent-registration): always attempt fallback when model resolution fails

Removes both the isFirstRunNoCache and override?.model guards from
the fallback logic in collectPendingBuiltinAgents(). Previously, when
a user configured a model like minimax/MiniMax-M2.5 that wasn't in
availableModels, the agent was silently excluded and --agent Librarian
would crash with 'undefined is not an object'.

Now: if applyModelResolution() fails for ANY reason (cache state,
unavailable model, config merge issue), getFirstFallbackModel() is
always attempted. A log warning is emitted when a user-configured
model couldn't be resolved, making the previously silent failure
visible.

Supersedes #2517
Fixes #2427
This commit is contained in:
MoerAI
2026-03-16 10:58:51 +09:00
committed by sspark-kisane
parent f31f50abec
commit abdd39da00

View File

@@ -8,6 +8,7 @@ import { buildAgent, isFactory } from "../agent-builder"
import { applyOverrides } from "./agent-overrides" import { applyOverrides } from "./agent-overrides"
import { applyEnvironmentContext } from "./environment-context" import { applyEnvironmentContext } from "./environment-context"
import { applyModelResolution, getFirstFallbackModel } from "./model-resolution" import { applyModelResolution, getFirstFallbackModel } from "./model-resolution"
import { log } from "../../shared/logger"
export function collectPendingBuiltinAgents(input: { export function collectPendingBuiltinAgents(input: {
agentSources: Record<BuiltinAgentName, import("../agent-builder").AgentSource> agentSources: Record<BuiltinAgentName, import("../agent-builder").AgentSource>
@@ -75,7 +76,13 @@ export function collectPendingBuiltinAgents(input: {
availableModels, availableModels,
systemDefaultModel, systemDefaultModel,
}) })
if (!resolution && isFirstRunNoCache && !override?.model) { if (!resolution) {
if (override?.model) {
log("[agent-registration] User-configured model could not be resolved, falling back", {
agent: agentName,
configuredModel: override.model,
})
}
resolution = getFirstFallbackModel(requirement) resolution = getFirstFallbackModel(requirement)
} }
if (!resolution) continue if (!resolution) continue