xai-org/grok-build · warning

cancelled after parallel copy

Error message

cancelled after parallel copy

What it means

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.

Source

Thrown at crates/codegen/xai-fast-worktree/src/worktree/execute.rs:992

        channel_buffer,
        skip_files: modified_files_for_skip,
        respect_gitignore: true,
        skip_patterns: vec![],
    };

    let copy_result =
        copy::copy_parallel(&source_root, &dest, copy_config, cancellation_token.clone())?;

    tracing::debug!(
        elapsed = ?copy_start.elapsed(),
        files = copy_result.stats.files_copied,
        dirs = copy_result.stats.dirs_created,
        "parallel copy complete"
    );

    // Check cancellation after the heavy copy phase.
    if cancellation_token.is_cancelled() {
        anyhow::bail!("cancelled after parallel copy");
    }

    // Phase 3: Finalize (index copy / reset / clean).
    let finalize_start = std::time::Instant::now();

    finalize_worktree(
        &source_root,
        &dest,
        working_tree,
        &modified_files_in_source,
        copy_result.file_metadata,
    )?;
    tracing::debug!(elapsed = ?finalize_start.elapsed(), "finalize complete");

    // Phase 4: Copy ignored files (optional).
    let ignored_stats = match ignored_files {
        IgnoredFilesMode::Skip | IgnoredFilesMode::CopyOnly { .. } => None,
        IgnoredFilesMode::Copy { skip_patterns } => {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Retry the create after cancellation if the worktree is still wanted — the partial dest was reclaimed automatically.
  2. Raise timeouts/allocation so large copies are not cut off mid-flight.
  3. Keep the cancellation token un-triggered for the duration of the operation (don't tie it to short-lived request deadlines).
  4. If cleanup of the partial tree did not happen (crash), remove the destination directory manually before retrying.
Defensive patterns

Strategy: retry

Try / catch

for attempt in 0..2 {
    match create_worktree(&plan).await {
        Err(e) if e.to_string().contains("cancelled after parallel copy")
            && !user_requested_cancel => continue,
        other => break other,
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/a79e537cab9b9a11. Report an issue: GitHub.