zed-industries/zed · error

worktree repair was canceled

Error message

worktree repair was canceled

What it means

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.

Solutions

  1. Retry restoration after the main repository entity is confirmed alive and its git state is quiescent
  2. Delete the stale non-git directory at the worktree path so the else-branch recreates a fresh worktree instead of repairing
  3. Check that the temporary project hosting the main repo was not torn down mid-restore
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/agent_ui/src/thread_worktree_archive.rs:666 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/c52c403363089de1. Report an issue: GitHub.

Appendix: source

Thrown at crates/agent_ui/src/thread_worktree_archive.rs:666

    cx: &mut AsyncApp,
) -> Result<PathBuf> {
    let (main_repo, _temp_project) =
        find_or_create_repository(&row.main_repo_path, remote_connection, cx).await?;

    let worktree_path = &row.worktree_path;
    let app_state = current_app_state(cx).context("no app state available")?;
    let already_exists = app_state.fs.metadata(worktree_path).await?.is_some();

    let created_new_worktree = if already_exists {
        let is_git_worktree =
            resolve_git_worktree_to_main_repo(app_state.fs.as_ref(), worktree_path)
                .await
                .is_some();

        if !is_git_worktree {
            let rx = main_repo.update(cx, |repo, _cx| repo.repair_worktrees());
            rx.await
                .map_err(|_| anyhow!("worktree repair was canceled"))?
                .context("failed to repair worktrees")?;
        }
        false
    } else {
        // Create worktree at the original commit — the branch still points
        // here because archival used detached commits.
        let rx = main_repo.update(cx, |repo, _cx| {
            repo.create_worktree_detached(worktree_path.clone(), row.original_commit_hash.clone())
        });
        rx.await
            .map_err(|_| anyhow!("worktree creation was canceled"))?
            .context("failed to create worktree")?;
        true
    };

    let (wt_repo, _temp_wt_project) =
        match find_or_create_repository(worktree_path, remote_connection, cx).await {
            Ok(result) => result,

View on GitHub (pinned to f4178619ac)