{"record":{"id":"2178ee30ac32da04","repo":"zed-industries/zed","slug":"could-not-resolve-path","errorCode":null,"errorMessage":"Could not resolve path {}","messagePattern":"Could not resolve path (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/tools/tool_permissions.rs","lineNumber":404,"sourceCode":"/// - `Ok(ResolvedProjectPath::SymlinkEscape { .. })` — the path resolves\n///   through a symlink to a location outside the project. Agent tools should\n///   prompt the user before proceeding.\n/// - `Err(..)` — the path could not be found in the project or could not be\n///   verified. The error message is suitable for returning to the model.\npub fn resolve_project_path(\n    project: &Project,\n    path: impl AsRef<Path>,\n    canonical_worktree_roots: &[PathBuf],\n    cx: &App,\n) -> Result<ResolvedProjectPath> {\n    let path = path.as_ref();\n    let project_path = project\n        .find_project_path(path, cx)\n        .ok_or_else(|| anyhow!(\"Path {} is not in the project\", path.display()))?;\n\n    let worktree = project\n        .worktree_for_id(project_path.worktree_id, cx)\n        .ok_or_else(|| anyhow!(\"Could not resolve path {}\", path.display()))?;\n    let snapshot = worktree.read(cx);\n\n    // Fast path: if the entry exists in the snapshot and is not marked\n    // external, we know it's safe (the background scanner already verified).\n    if let Some(entry) = snapshot.entry_for_path(&project_path.path) {\n        if !entry.is_external {\n            return Ok(ResolvedProjectPath::Safe(project_path));\n        }\n\n        // Entry is external (set by the worktree scanner when a symlink's\n        // canonical target is outside the worktree root). Return the\n        // canonical path if the entry has one, otherwise fall through to\n        // filesystem-level canonicalization.\n        if let Some(canonical) = &entry.canonical_path {\n            if is_within_any_worktree(canonical.as_ref(), canonical_worktree_roots) {\n                return Ok(ResolvedProjectPath::Safe(project_path));\n            }\n","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent/src/tools/tool_permissions.rs#L386-L422","documentation":"The second step of resolve_project_path: find_project_path returned a worktree id, but worktree_for_id can no longer resolve it. Both lookups consult live project state, so this only happens when the worktree is removed between the two calls — a close-vs-tool-call race, not a bad path.","triggerScenarios":"A worktree is closed or removed from the project concurrently with an agent tool call being resolved; the id from the first lookup is stale by the time of the second.","commonSituations":"The user closes a folder tab in a multi-root workspace while the agent is mid-request.","solutions":["Retry the tool call — resolution then runs against the updated worktree set","Confirm the folder is still open in the project panel","Re-issue the agent request after the project layout change settles"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"let resolved = match resolve_project_path(&project, &path, &canonical_roots, cx) {\n    Err(e) if e.to_string().contains(\"Could not resolve path\") => {\n        // worktree set changed mid-resolution; re-resolve once against fresh state\n        resolve_project_path(&project, &path, &canonical_roots, cx)?\n    }\n    result => result?,\n};","preventionTips":["Treat this error as transient: re-resolve immediately rather than reporting failure","Avoid closing worktrees while agent requests that reference them are in flight"],"tags":["agent","tool-permissions","race-condition","worktree"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}