{"record":{"id":"0e8f9816095a58ec","repo":"zed-industries/zed","slug":"invalid-model-id","errorCode":null,"errorMessage":"Invalid model ID {}","messagePattern":"Invalid model ID (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/agent.rs","lineNumber":2425,"sourceCode":"    fn select_model(&self, model_id: AgentModelId, cx: &mut App) -> Task<Result<()>> {\n        log::debug!(\n            \"Setting model for session {}: {}\",\n            self.session_id,\n            model_id\n        );\n        let Some(thread) = self\n            .connection\n            .0\n            .read(cx)\n            .sessions\n            .get(&self.session_id)\n            .map(|session| session.thread.clone())\n        else {\n            return Task::ready(Err(anyhow!(\"Session not found\")));\n        };\n\n        let Some(model) = self.connection.0.read(cx).models.model_from_id(&model_id) else {\n            return Task::ready(Err(anyhow!(\"Invalid model ID {}\", model_id)));\n        };\n\n        let favorite = agent_settings::AgentSettings::get_global(cx)\n            .favorite_models\n            .iter()\n            .find(|favorite| {\n                favorite.provider.0 == model.provider_id().0.as_ref()\n                    && favorite.model == model.id().0.as_ref()\n            })\n            .cloned();\n\n        let LanguageModelSelection {\n            enable_thinking,\n            effort,\n            speed,\n            ..\n        } = agent_settings::language_model_to_selection(&model, favorite.as_ref());\n","sourceCodeStart":2407,"sourceCodeEnd":2443,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent/src/agent.rs#L2407-L2443","documentation":"After the session resolves, select_model calls model_from_id(&model_id) against the agent's current model registry; a miss means the requested AgentModelId is not in the live model list. Favorites in agent settings are matched by provider+model string after this, so a stale id fails before favorite handling.","triggerScenarios":"Applying a model id that no longer exists: favorite_models persisted from an older catalog, model renamed/deprecated upstream, provider extension downgraded, or provider switched while an old selection persisted.","commonSituations":"Settings carry favorites referencing removed models; model deprecated by the provider; ids from a different provider namespace.","solutions":["Pick a model from the currently available list (call list_models and use one of those ids)","Update favorite_models in agent settings to ids that exist now","Re-enumerate models (fix provider auth if enumeration failed) and retry"],"exampleFix":"// before\nlet Some(model) = self.connection.0.read(cx).models.model_from_id(&model_id) else {\n    return Task::ready(Err(anyhow::anyhow!(\"Invalid model ID {}\", model_id)));\n};\n\n// after: fall back to the default model with a visible warning\nlet Some(model) = self.connection.0.read(cx).models.model_from_id(&model_id) else {\n    log::warn!(\"model {} no longer available; using default\", model_id);\n    let Some(model) = self.connection.0.read(cx).models.default_model() else {\n        return Task::ready(Err(anyhow::anyhow!(\"No models available\")));\n    };\n    model\n};","handlingStrategy":"type-guard","validationCode":"// Resolve the id against the live list before selecting\nlet valid_ids: HashSet<_> = connection.0.read(cx).models\n    .model_list.iter().map(|m| m.id.clone()).collect();\nif !valid_ids.contains(&model_id) {\n    model_id = pick_from(valid_ids); // or prompt the user to re-choose\n}","typeGuard":"fn model_id_is_available(agent: &AgentConnection, model_id: &AgentModelId, cx: &App) -> bool {\n    agent.0.read(cx).models.model_from_id(model_id).is_some()\n}","tryCatchPattern":"match selector.select_model(model_id, cx).await {\n    Err(error) if error.to_string().starts_with(\"Invalid model ID\") => {\n        // Stale favorite: fall back to the default model and notify.\n        notify(format!(\"{error}; using default\"));\n        selector.select_model(default_model_id(), cx).await\n    }\n    other => other,\n}","preventionTips":["Validate persisted favorite_models against the current list at startup and prune stale entries","Re-verify model ids after provider/extension updates before applying them","Prefer provider+model keys over raw ids when persisting selections"],"tags":["rust","zed","agent","models","validation","settings"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}