zed-industries/zed · warning

worktree repair was canceled

Error message

worktree repair was canceled

What it means

During restore, when the archived worktree's directory still exists on disk but is not recognized as a git worktree, the code calls repo.repair_worktrees() and awaits its channel. This error means the receiver was dropped — the repository entity or project went away — so the repair was cancelled rather than failing.

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 bc538def45)

Solutions

  1. Retry the restore after reopening the project.
  2. If repair keeps being needed, run 'git worktree repair' in the main repository once, then restore.
  3. In code, distinguish this cancellation from the 'failed to repair worktrees' git error and handle it as an abort.
Defensive patterns

Strategy: try-catch

Try / catch

match repo.update(cx, |repo, _| repo.repair_worktrees()).await {
    Ok(result) => result.context("failed to repair worktrees")?,
    Err(_canceled) => {
        // repair was cancelled by teardown: abort the restore, no git rollback needed
    }
}

Prevention

When it happens

Trigger: Worktree directory exists but its .git link is damaged or the worktree was pruned from the main repo, and the project/repository entity is torn down while repair_worktrees() is still running.

Common situations: Closing the window during restore of a machine-pruned worktree; git worktree state damaged by external tooling plus an app teardown race.

Related errors


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