{"record":{"id":"0e2be38cdb64a250","repo":"xai-org/grok-build","slug":"failed-to-create-btrfs-snapshot-from-to","errorCode":null,"errorMessage":"failed to create BTRFS snapshot from {} to {}: {}","messagePattern":"failed to create BTRFS snapshot from (.+?) to (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-fast-worktree/src/btrfs/snapshot.rs","lineNumber":40,"sourceCode":"        dest = %dest.display(),\n        \"creating BTRFS snapshot\"\n    );\n\n    let mut cmd = Command::new(\"btrfs\");\n    xai_tty_utils::detach_std_command(&mut cmd);\n    cmd.stdin(Stdio::null());\n    // OsStr args: a non-UTF-8 path must not silently collapse to \".\".\n    let output = cmd\n        .arg(\"subvolume\")\n        .arg(\"snapshot\")\n        .arg(source)\n        .arg(dest)\n        .output()\n        .with_context(|| \"failed to execute btrfs subvolume snapshot command\")?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        bail!(\n            \"failed to create BTRFS snapshot from {} to {}: {}\",\n            source.display(),\n            dest.display(),\n            stderr.trim()\n        );\n    }\n\n    tracing::debug!(\n        dest = %dest.display(),\n        \"BTRFS snapshot created successfully\"\n    );\n\n    Ok(())\n}\n\n/// Result of creating a snapshot for a worktree.\n#[derive(Debug)]\npub struct SnapshotResult {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-fast-worktree/src/btrfs/snapshot.rs#L22-L58","documentation":"`create_snapshot` shells out to `btrfs subvolume snapshot <source> <dest>`; when the command exits non-zero it bails with this message including the source, dest, and btrfs stderr. It means the btrfs tool itself refused or failed the snapshot, not a Rust-side error.","triggerScenarios":"Calling `create_snapshot` (directly or via `create_snapshot_with_symlink` / `create_overlay_worktree`) where source doesn't exist or isn't a btrfs subvolume, dest already exists, or the filesystem at source/dest isn't btrfs.","commonSituations":"Trying to snapshot on ext4/xfs/tmpfs volumes; snapshotting a plain directory instead of a subvolume; dest path already existing; running inside a container without btrfs kernel support or without `btrfs` binary; insufficient privileges (non-root, missing CAP_SYS_ADMIN).","solutions":["Read the stderr appended to the error — it contains btrfs's actual reason (e.g. 'not a btrfs subvolume', 'already exists').","Verify the source is a btrfs subvolume: `btrfs subvolume show <source>` must succeed.","Ensure both source and dest live on btrfs filesystems and dest does not already exist.","Run with sufficient privileges (root or CAP_SYS_ADMIN) and confirm the `btrfs` binary is installed in the environment/container.","If the environment isn't btrfs, use a non-btrfs worktree backend instead of forcing snapshots."],"exampleFix":"// before\n// running on ext4:\ncreate_snapshot(Path::new(\"/home/user/repo\"), Path::new(\"/home/user/repo-snap\"))?;\n// after\n// pick a btrfs-backed location and verify first\nif btrfs::is_btrfs(Path::new(\"/mnt/btrfs/repo\")) {\n    create_snapshot(Path::new(\"/mnt/btrfs/repo\"), Path::new(\"/mnt/btrfs/repo-snap\"))?;\n} else {\n    // fall back to plain copy-based worktree creation\n}\n","handlingStrategy":"validation","validationCode":"use std::process::Command;\nfn is_btrfs_subvolume(p: &std::path::Path) -> bool {\n    Command::new(\"btrfs\").args([\"subvolume\", \"show\"])\n        .arg(p).output().map(|o| o.status.success()).unwrap_or(false)\n}\nassert!(is_btrfs_subvolume(&source), \"source must be a btrfs subvolume\");\nassert!(!dest.exists(), \"snapshot dest must not already exist\");","typeGuard":null,"tryCatchPattern":"match create_snapshot(&src, &dst) {\n    Err(e) if e.to_string().contains(\"failed to create BTRFS snapshot\") => {\n        eprintln!(\"btrfs refused: {e}\"); // stderr is embedded — log it\n        fallback_to_copy_worktree(&src, &dst)?;\n    }\n    r => r?,\n}","preventionTips":["Verify source/dest are on btrfs (btrfs subvolume show) before snapshotting","Run with root or CAP_SYS_ADMIN privileges","Ensure the btrfs binary exists in containers/images","Ensure the dest path is free before creating a snapshot"],"tags":["btrfs","filesystem","snapshot","external-command"],"backgroundTag":"btrfs-snapshot-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}