{"record":{"id":"a79e537cab9b9a11","repo":"xai-org/grok-build","slug":"cancelled-after-parallel-copy","errorCode":null,"errorMessage":"cancelled after parallel copy","messagePattern":"cancelled after parallel copy","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/codegen/xai-fast-worktree/src/worktree/execute.rs","lineNumber":992,"sourceCode":"        channel_buffer,\n        skip_files: modified_files_for_skip,\n        respect_gitignore: true,\n        skip_patterns: vec![],\n    };\n\n    let copy_result =\n        copy::copy_parallel(&source_root, &dest, copy_config, cancellation_token.clone())?;\n\n    tracing::debug!(\n        elapsed = ?copy_start.elapsed(),\n        files = copy_result.stats.files_copied,\n        dirs = copy_result.stats.dirs_created,\n        \"parallel copy complete\"\n    );\n\n    // Check cancellation after the heavy copy phase.\n    if cancellation_token.is_cancelled() {\n        anyhow::bail!(\"cancelled after parallel copy\");\n    }\n\n    // Phase 3: Finalize (index copy / reset / clean).\n    let finalize_start = std::time::Instant::now();\n\n    finalize_worktree(\n        &source_root,\n        &dest,\n        working_tree,\n        &modified_files_in_source,\n        copy_result.file_metadata,\n    )?;\n    tracing::debug!(elapsed = ?finalize_start.elapsed(), \"finalize complete\");\n\n    // Phase 4: Copy ignored files (optional).\n    let ignored_stats = match ignored_files {\n        IgnoredFilesMode::Skip | IgnoredFilesMode::CopyOnly { .. } => None,\n        IgnoredFilesMode::Copy { skip_patterns } => {","sourceCodeStart":974,"sourceCodeEnd":1010,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-fast-worktree/src/worktree/execute.rs#L974-L1010","documentation":"In execute_copy_worktree, after the parallel copy of the working tree completes, the cancellation token is checked again before the finalize phase (index copy / reset / clean). If cancelled during the copy, it bails with 'cancelled after parallel copy'; the PartialWorktreeGuard drops and removes the partially copied destination.","triggerScenarios":"Cancellation requested while the multi-threaded file copy of source files into dest was in progress — e.g. token.cancel() from a timeout, shutdown handler, or user abort during a large repo copy.","commonSituations":"Copying a very large monorepo takes minutes and a supervisor's deadline fires mid-copy; user aborts a UI-triggered create; node shutdown drains tasks mid-operation.","solutions":["Retry the create after cancellation if the worktree is still wanted — the partial dest was reclaimed automatically.","Raise timeouts/allocation so large copies are not cut off mid-flight.","Keep the cancellation token un-triggered for the duration of the operation (don't tie it to short-lived request deadlines).","If cleanup of the partial tree did not happen (crash), remove the destination directory manually before retrying."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in 0..2 {\n    match create_worktree(&plan).await {\n        Err(e) if e.to_string().contains(\"cancelled after parallel copy\")\n            && !user_requested_cancel => continue,\n        other => break other,\n    }\n}","preventionTips":["Size deadlines to repo copy time (large monorepos copy slowly)","Keep the cancellation token dedicated to this operation","Verify the partial destination was reclaimed before re-running","Log copy stats to correlate cancellations with copy duration"],"tags":["cancellation","worktree","copy","async"],"backgroundTag":"operation-cancelled","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}