{"record":{"id":"1fec01ccb5d64a27","repo":"zed-industries/zed","slug":"worktree-creation-was-canceled","errorCode":null,"errorMessage":"worktree creation was canceled","messagePattern":"worktree creation was canceled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/agent_ui/src/thread_worktree_archive.rs","lineNumber":677,"sourceCode":"            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,\n            Err(error) => {\n                remove_new_worktree_on_error(created_new_worktree, &main_repo, worktree_path, cx)\n                    .await;\n                return Err(error);\n            }\n        };\n\n    if let Some(branch_name) = &row.branch_name {\n        // Attempt to check out the branch the worktree was previously on.\n        let checkout_result = wt_repo\n            .update(cx, |repo, _cx| repo.change_branch(branch_name.clone()))","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent_ui/src/thread_worktree_archive.rs#L659-L695","documentation":"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.","triggerScenarios":"The worktree directory is missing and the project/repository entity is dropped while 'git worktree add' (detached) is still running underneath create_worktree_detached.","commonSituations":"Quitting Zed or closing the window right as the restore starts creating the worktree; tests dropping contexts around the spawned restore.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match repo\n    .update(cx, |repo, _| {\n        repo.create_worktree_detached(worktree_path.clone(), commit.clone())\n    })\n    .await\n{\n    Ok(result) => result.context(\"failed to create worktree\")?,\n    Err(_canceled) => {\n        // creation was cancelled by teardown: abort; a retry re-creates cleanly\n    }\n}","preventionTips":["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."],"tags":["zed","git","cancellation","worktree-create","thread-restore"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}