{"record":{"id":"c52c403363089de1","repo":"zed-industries/zed","slug":"worktree-repair-was-canceled","errorCode":null,"errorMessage":"worktree repair was canceled","messagePattern":"worktree repair was canceled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent_ui/src/thread_worktree_archive.rs","lineNumber":666,"sourceCode":"    cx: &mut AsyncApp,\n) -> Result<PathBuf> {\n    let (main_repo, _temp_project) =\n        find_or_create_repository(&row.main_repo_path, remote_connection, cx).await?;\n\n    let worktree_path = &row.worktree_path;\n    let app_state = current_app_state(cx).context(\"no app state available\")?;\n    let already_exists = app_state.fs.metadata(worktree_path).await?.is_some();\n\n    let created_new_worktree = if already_exists {\n        let is_git_worktree =\n            resolve_git_worktree_to_main_repo(app_state.fs.as_ref(), worktree_path)\n                .await\n                .is_some();\n\n        if !is_git_worktree {\n            let rx = main_repo.update(cx, |repo, _cx| repo.repair_worktrees());\n            rx.await\n                .map_err(|_| anyhow!(\"worktree repair was canceled\"))?\n                .context(\"failed to repair worktrees\")?;\n        }\n        false\n    } else {\n        // Create worktree at the original commit — the branch still points\n        // here because archival used detached commits.\n        let rx = main_repo.update(cx, |repo, _cx| {\n            repo.create_worktree_detached(worktree_path.clone(), row.original_commit_hash.clone())\n        });\n        rx.await\n            .map_err(|_| anyhow!(\"worktree creation was canceled\"))?\n            .context(\"failed to create worktree\")?;\n        true\n    };\n\n    let (wt_repo, _temp_wt_project) =\n        match find_or_create_repository(worktree_path, remote_connection, cx).await {\n            Ok(result) => result,","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/agent_ui/src/thread_worktree_archive.rs#L648-L684","documentation":"In restore_worktree_via_git, when the target path already exists but is not a valid git worktree, the code calls repo.repair_worktrees() and awaits its receiver; the channel closed without a value (the Repository was dropped or the repair task was cancelled), which is mapped to this sentinel error before the underlying repair result is inspected.","triggerScenarios":"Thrown at crates/agent_ui/src/thread_worktree_archive.rs:666 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry restoration after the main repository entity is confirmed alive and its git state is quiescent","Delete the stale non-git directory at the worktree path so the else-branch recreates a fresh worktree instead of repairing","Check that the temporary project hosting the main repo was not torn down mid-restore"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}