{"record":{"id":"9d4c78a41d378fb4","repo":"xai-org/grok-build","slug":"remove-subagent-worktree-task-failed-e","errorCode":null,"errorMessage":"remove_subagent_worktree task failed: {e}","messagePattern":"remove_subagent_worktree task failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/worktree/mod.rs","lineNumber":1533,"sourceCode":"    })\n    .await\n    .map_err(|e| anyhow::anyhow!(\"snapshot_subagent_worktree task failed: {e}\"))?\n}\n\n/// Remove a subagent worktree directory. Call only AFTER\n/// [`snapshot_subagent_worktree`] succeeded and its ref was persisted, so a\n/// removal failure is safe to treat as best-effort (the durable ref already\n/// backs resume). The blocking fast-worktree work runs on a blocking thread.\npub async fn remove_subagent_worktree(worktree_path: &Path) -> Result<()> {\n    let worktree_path = worktree_path.to_path_buf();\n    // On rootless hosts the snapshot delete needs the privileged helper; without\n    // the delegate the btrfs delete hits EPERM and the snapshot leaks.\n    let delegate = btrfs_delegate_from_env();\n    tokio::task::spawn_blocking(move || {\n        xai_fast_worktree::remove_worktree_with_delegate(&worktree_path, delegate)\n    })\n    .await\n    .map_err(|e| anyhow::anyhow!(\"remove_subagent_worktree task failed: {e}\"))??;\n    Ok(())\n}\n\n/// Test-only thin wrapper: snapshot then remove (capture-first). NOT for\n/// production use: the completion path drives [`snapshot_subagent_worktree`] and\n/// [`remove_subagent_worktree`] separately so it can persist the ref between the\n/// two steps (removing without persisting first is a crash-safety footgun).\n#[cfg(test)]\nasync fn snapshot_and_remove_subagent_worktree(\n    worktree_path: &Path,\n    source_repo: &Path,\n    ref_name: &str,\n) -> Result<String> {\n    let snapshot_ref = snapshot_subagent_worktree(worktree_path, source_repo, ref_name).await?;\n    remove_subagent_worktree(worktree_path).await?;\n    Ok(snapshot_ref)\n}\n","sourceCodeStart":1515,"sourceCodeEnd":1551,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/worktree/mod.rs#L1515-L1551","documentation":"Error \"remove_subagent_worktree task failed: {e}\" thrown in xai-org/grok-build.","triggerScenarios":"Thrown at crates/codegen/xai-grok-workspace/src/worktree/mod.rs:1533 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}