zed-industries/zed · warning
worktree creation was canceled
Error message
worktree creation was canceled
What it means
When the archived worktree's directory no longer exists, the restore recreates it via repo.create_worktree_detached at the original archived commit. This error means that operation's channel receiver was dropped before completion (repository entity or project torn down, task cancelled), so creation was cancelled mid-flight.
Source
Thrown at crates/agent_ui/src/thread_worktree_archive.rs:677
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,
Err(error) => {
remove_new_worktree_on_error(created_new_worktree, &main_repo, worktree_path, cx)
.await;
return Err(error);
}
};
if let Some(branch_name) = &row.branch_name {
// Attempt to check out the branch the worktree was previously on.
let checkout_result = wt_repo
.update(cx, |repo, _cx| repo.change_branch(branch_name.clone()))View on GitHub (pinned to bc538def45)
Solutions
- Retry the restore; a partially cancelled creation is cleaned up or superseded on the next run.
- Check 'git worktree list' in the main repo and prune leftovers ('git worktree prune') before retrying.
- In code, handle cancellation separately from the 'failed to create worktree' git error.
Defensive patterns
Strategy: try-catch
Try / catch
match repo
.update(cx, |repo, _| {
repo.create_worktree_detached(worktree_path.clone(), commit.clone())
})
.await
{
Ok(result) => result.context("failed to create worktree")?,
Err(_canceled) => {
// creation was cancelled by teardown: abort; a retry re-creates cleanly
}
} Prevention
- Prune leftover worktrees ('git worktree prune') before retrying a cancelled creation.
- Keep the spawning entity alive for the duration of worktree creation.
- Log cancellations at debug level; reserve errors for real git failures.
When it happens
Trigger: The worktree directory is missing and the project/repository entity is dropped while 'git worktree add' (detached) is still running underneath create_worktree_detached.
Common situations: Quitting Zed or closing the window right as the restore starts creating the worktree; tests dropping contexts around the spawned restore.
Related errors
- temporary repository barrier canceled
- worktree repair was canceled
- restore_archive_checkpoint canceled
- User canceled
- The agent is nearing the end of its context window and has b
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/1fec01ccb5d64a27.
Report an issue: GitHub.