{"record":{"id":"93c391b940b01c52","repo":"charmbracelet/crush","slug":"failed-to-update-agent-models-w","errorCode":null,"errorMessage":"failed to update agent models: %w","messagePattern":"failed to update agent models: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/app/app.go","lineNumber":487,"sourceCode":"\t}\n\n\tif !cfg.IsModelAvailable(lastMsg.Provider, lastMsg.Model) {\n\t\tslog.Debug(\"Skipping model restoration: provider/model not available\",\n\t\t\t\"provider\", lastMsg.Provider,\n\t\t\t\"model\", lastMsg.Model)\n\t\treturn nil\n\t}\n\n\tapp.config.OverridePreferredModel(config.SelectedModelTypeLarge, config.SelectedModel{\n\t\tProvider: lastMsg.Provider,\n\t\tModel:    lastMsg.Model,\n\t})\n\tif _, ok := cfg.Models[config.SelectedModelTypeSmall]; !ok {\n\t\tsmallModel := app.GetDefaultSmallModel(lastMsg.Provider)\n\t\tapp.config.OverridePreferredModel(config.SelectedModelTypeSmall, smallModel)\n\t}\n\tif err := app.AgentCoordinator.UpdateModels(ctx); err != nil {\n\t\treturn fmt.Errorf(\"failed to update agent models: %w\", err)\n\t}\n\tslog.Info(\"Restored model from session\",\n\t\t\"provider\", lastMsg.Provider,\n\t\t\"model\", lastMsg.Model)\n\treturn nil\n}\n\n// overrideModelsForNonInteractive parses the model strings and temporarily\n// overrides the model configurations, then rebuilds the agent.\n// Format: \"model-name\" (searches all providers) or \"provider/model-name\".\n// Model matching is case-insensitive.\n// If largeModel is provided but smallModel is not, the small model defaults to\n// the provider's default small model.\nfunc (app *App) overrideModelsForNonInteractive(ctx context.Context, largeModel, smallModel string) error {\n\tproviders := app.config.Config().Providers.Copy()\n\n\tlargeMatches, smallMatches, err := findModels(providers, largeModel, smallModel)\n\tif err != nil {","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/app/app.go#L469-L505","documentation":"After restoring provider/model overrides from the session's last assistant message, restoreModelFromSession calls AgentCoordinator.UpdateModels to apply them to live agents; failure is wrapped with this message. It means the restored provider/model combination could not be applied — usually because that model no longer resolves against the provider catalog or credentials are missing.","triggerScenarios":"Continuing a session whose last assistant message used a provider/model that is no longer available (removed from catalog, provider not configured, API key absent) when UpdateModels tries to wire agents.","commonSituations":"--continue on an old session created with a deprecated model id; API key rotated/removed since the original run; provider catalog changed between versions.","solutions":["Pass an explicit valid --model override to force a currently available model","Reconfigure credentials for the original provider (or accept the new default)","Start a new session instead of --continue if the old model is gone","Update crush so the provider catalog includes the stored model"],"exampleFix":"// before\ncrush run --continue <id> \"next step\" // old session used removed model\n// after\ncrush run --continue <id> --model anthropic/claude-sonnet-4-5 \"next step\"","handlingStrategy":"fallback","validationCode":"last := getLastAssistantMessage(sessionID) // via crush session data\nif last != nil && !modelAvailable(last.Provider, last.Model) {\n\t// force a known-good model instead of relying on restore\n\tlargeModel = fallbackModel\n}","typeGuard":null,"tryCatchPattern":"if err := app.RunNonInteractive(ctx, w, prompt, \"\", \"\", true, contID, false); err != nil {\n\tif strings.Contains(err.Error(), \"failed to update agent models\") {\n\t\t// fall back to a current default model\n\t\treturn app.RunNonInteractive(ctx, w, prompt, fallbackModel, \"\", true, contID, false)\n\t}\n\treturn err\n}","preventionTips":["Pass an explicit --model when continuing old sessions with stale models","Keep provider API keys configured for all providers your sessions used","Re-pin stored model ids after provider catalog deprecations"],"tags":["go","model-restore","session","configuration"],"backgroundTag":"unknown-model-id","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}