{"record":{"id":"751e3af1e0906627","repo":"zed-industries/zed","slug":"model-not-found","errorCode":null,"errorMessage":"Model not found","messagePattern":"Model not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/agent.rs","lineNumber":2489,"sourceCode":"            },\n        );\n\n        Task::ready(Ok(()))\n    }\n\n    fn selected_model(&self, cx: &mut App) -> Task<Result<acp_thread::AgentModelInfo>> {\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        let Some(model) = thread.read(cx).model() else {\n            return Task::ready(Err(anyhow!(\"Model not found\")));\n        };\n        let Some(provider) = LanguageModelRegistry::read_global(cx).provider(&model.provider_id())\n        else {\n            return Task::ready(Err(anyhow!(\"Provider not found\")));\n        };\n        Task::ready(Ok(LanguageModels::map_language_model_to_info(\n            model, &provider,\n        )))\n    }\n\n    fn favorite_model_ids(&self, cx: &mut App) -> HashSet<AgentModelId> {\n        agent_settings::AgentSettings::get_global(cx)\n            .favorite_model_ids()\n            .into_iter()\n            .map(AgentModelId::from)\n            .collect()\n    }\n","sourceCodeStart":2471,"sourceCodeEnd":2507,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent/src/agent.rs#L2471-L2507","documentation":"The session exists, but `thread.read(cx).model()` returns None: the Thread has no language model assigned. selected_model reports this instead of guessing, because mapping to AgentModelInfo requires a concrete model instance.","triggerScenarios":"Querying the model immediately after session creation before a default model has been assigned; the user has no default model configured in AgentSettings and none was passed at thread creation; the model was cleared when its provider went away.","commonSituations":"Fresh installs with no default_model in agent settings; upgrades that reset model configuration; tests that create threads without setting a model.","solutions":["Set a default model in AgentSettings (or pass the model explicitly when creating the thread) so every Thread starts with one.","Re-query after settings and the model registry settle — the model is assigned at construction or when explicitly set.","Surface a 'pick a model' prompt instead of showing the raw error to the user."],"exampleFix":"// before\nlet info = connection.selected_model(cx).await?; // fails with \"Model not found\"\n\n// after\nif thread.read(cx).model().is_none() {\n    agent_settings::AgentSettings::get_global(cx)\n        .set_default_model(Some(default_model_id), cx);\n}\nlet info = connection.selected_model(cx).await?;","handlingStrategy":"validation","validationCode":"// before requesting model info, ensure the thread has a model\nlet has_model = thread.read(cx).model().is_some();\nif !has_model {\n    // set default model or prompt the user to pick one\n}","typeGuard":"fn thread_has_model(thread: &Entity<Thread>, cx: &App) -> bool {\n    thread.read(cx).model().is_some()\n}","tryCatchPattern":null,"preventionTips":["Configure a default model in AgentSettings so new threads always start with one.","After creating a session programmatically, set its model before issuing model-dependent requests."],"tags":["rust","zed","agent","model","configuration"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}