{"record":{"id":"04f24dc6f61d5f5b","repo":"zed-industries/zed","slug":"worktree-not-found","errorCode":null,"errorMessage":"worktree not found","messagePattern":"worktree not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/agent_ui/src/mention_set.rs","lineNumber":1260,"sourceCode":"\n        files\n    }\n\n    let Some(project_path) = project\n        .read(cx)\n        .project_path_for_absolute_path(&abs_path, cx)\n    else {\n        return Task::ready(Err(anyhow!(\n            \"project path not found for directory mention {abs_path:?}\"\n        )));\n    };\n    let Some(entry) = project.read(cx).entry_for_path(&project_path, cx) else {\n        return Task::ready(Err(anyhow!(\"project entry not found\")));\n    };\n    let directory_path = entry.path.clone();\n    let worktree_id = project_path.worktree_id;\n    let Some(worktree) = project.read(cx).worktree_for_id(worktree_id, cx) else {\n        return Task::ready(Err(anyhow!(\"worktree not found\")));\n    };\n    let project = project.clone();\n    cx.spawn(async move |cx| {\n        let file_paths = worktree.read_with(cx, |worktree, _cx| {\n            collect_files_in_path(worktree, &directory_path)\n        });\n        let descendants_future = cx.update(|cx| {\n            futures::future::join_all(file_paths.into_iter().map(\n                |(worktree_path, full_path): (Arc<RelPath>, String)| {\n                    let rel_path = worktree_path\n                        .strip_prefix(&directory_path)\n                        .map_or_else(|_| worktree_path.clone(), |rel_path| rel_path.into());\n\n                    let open_task = project.update(cx, |project, cx| {\n                        project.buffer_store().update(cx, |buffer_store, cx| {\n                            let project_path = ProjectPath {\n                                worktree_id,\n                                path: worktree_path,","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent_ui/src/mention_set.rs#L1242-L1278","documentation":"The directory-mention flow resolved a ProjectPath (which embeds worktree_id) and immediately calls project.worktree_for_id; None means the worktree was removed from the project in between. Because the id came from a worktree that existed a moment earlier, this is a teardown/removal race rather than a bad path.","triggerScenarios":"Removing or closing a worktree from the project while a directory mention confirmation is running; project teardown racing the spawned mention task.","commonSituations":"Closing a multi-root project's root just as a mention is confirmed; rapid workspace restructuring; tests exercising removal races.","solutions":["Retry the mention after the project settles; the path re-resolves against the remaining worktrees.","Treat as cancellation if the window is closing.","In code, re-validate that the worktree still exists right before use and surface a 'directory no longer available' message."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// re-resolve the worktree immediately before spawning the async work\nlet Some(worktree) = project.read(cx).worktree_for_id(project_path.worktree_id, cx) else {\n    return Task::ready(Err(anyhow!(\"directory no longer available\")));\n};","typeGuard":null,"tryCatchPattern":"match confirm_task.await {\n    Ok(mention) => { /* attach */ }\n    Err(err) if err.to_string() == \"worktree not found\" => {\n        show_user(\"That worktree was removed from the project\")\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Capture a strong Entity<Worktree> handle once resolved, and check it is alive before use.","Recompute project paths when worktrees are removed instead of caching ids.","Treat this as a transient race: offer the user a retry after the project settles."],"tags":["zed","worktree","race","lifecycle","mentions"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}