{"record":{"id":"6305dbb48ba6d85e","repo":"xai-org/grok-build","slug":"refusing-to-delete-pre-existing-snapshot-outsi","errorCode":null,"errorMessage":"refusing to delete pre-existing snapshot {}: outside grok-managed btrfs storage","messagePattern":"refusing to delete pre-existing snapshot (.+?): outside grok-managed btrfs storage","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-fast-worktree/src/btrfs/snapshot.rs","lineNumber":143,"sourceCode":"        })?;\n    }\n\n    // A pre-existing entry here would be deleted with btrfs privileges, so guard it:\n    // unlink a planted symlink, and only `btrfs delete` a real contained subvolume\n    // whose sibling metadata proves it belongs to THIS `dest` (never another session's).\n    if snapshot_path.exists() {\n        if snapshot_path\n            .symlink_metadata()\n            .is_ok_and(|m| m.file_type().is_symlink())\n        {\n            std::fs::remove_file(&snapshot_path).with_context(|| {\n                format!(\n                    \"failed to remove planted symlink at {}\",\n                    snapshot_path.display()\n                )\n            })?;\n        } else if !is_safe_snapshot_delete_target(&snapshot_path) {\n            bail!(\n                \"refusing to delete pre-existing snapshot {}: outside grok-managed \\\n                 btrfs storage\",\n                snapshot_path.display()\n            );\n        } else {\n            match snapshot_meta_state(&snapshot_path, dest) {\n                // Recreate a stale snapshot for this worktree, or reclaim a\n                // crashed-creation orphan whose metadata was never written; the\n                // is_safe check above keeps the delete inside managed storage.\n                SnapshotMetaState::Matches | SnapshotMetaState::Absent => {\n                    tracing::warn!(\n                        snapshot_path = %snapshot_path.display(),\n                        \"snapshot path already exists for this worktree, recreating\"\n                    );\n                    delete_snapshot(&snapshot_path)?;\n                }\n                // Metadata proves a different session owns it — never delete.\n                SnapshotMetaState::Mismatch => bail!(","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-fast-worktree/src/btrfs/snapshot.rs#L125-L161","documentation":"`create_snapshot_with_symlink` refuses to remove a pre-existing snapshot path because `is_safe_snapshot_delete_target` determined it lies outside the grok-managed btrfs storage area. This is a safety guard: the library will not delete anything it does not own, so snapshot creation aborts rather than clobbering an unknown path.","triggerScenarios":"Calling `create_snapshot_with_symlink` when the computed `snapshot_path` already exists on disk as a real file/directory/symlink that is not within the managed btrfs storage root (fails the safety check), and it is not a symlink that could be safely removed.","commonSituations":"A stale snapshot left by a different tool or an older library layout; user-created directory at the snapshot path; misconfigured snapshot root so the managed path resolves elsewhere; reusing a dest name across unrelated sessions.","solutions":["Inspect the existing path from the error message; if it's not yours, choose a different dest/snapshot name and delete it manually.","If it's a stale artifact you own, delete it yourself (e.g. `rm -rf` / `btrfs subvolume delete` as appropriate) and re-run creation.","Verify your configured btrfs storage root matches the one used previously — a mismatch makes valid snapshots look 'outside managed storage'.","Align snapshot naming so concurrent/legacy sessions don't collide at the same path.","If it's a planted symlink scenario, note the library already removes symlinks safely; this error means the target is a real entry, so manual intervention is required."],"exampleFix":"// before\n// /mnt/btrfs/snapshots/wt-42 exists but was created outside the managed root\ncreate_snapshot_with_symlink(&src, &dest)?; // refuses\n// after\n// manually reclaim the path first (verify ownership!)\n// $ btrfs subvolume show /mnt/btrfs/snapshots/wt-42 || rm -rf /mnt/btrfs/snapshots/wt-42\ncreate_snapshot_with_symlink(&src, &dest)?;\n","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn snapshot_path_is_reclaimable(snapshot_path: &Path) -> bool {\n    !snapshot_path.exists()\n        || is_safe_snapshot_delete_target(snapshot_path) // library helper\n        || snapshot_path.is_symlink() // symlinks are removed automatically\n}","typeGuard":"fn is_managed_snapshot(path: &Path, managed_root: &Path) -> bool {\n    path.canonicalize()\n        .map(|p| p.starts_with(managed_root.canonicalize().unwrap()))\n        .unwrap_or(false)\n}","tryCatchPattern":"match create_snapshot_with_symlink(&src, &dest) {\n    Err(e) if e.to_string().contains(\"outside grok-managed\") => {\n        eprintln!(\"stale/unmanaged path at snapshot location: {e}\");\n        // require human verification before removing the path manually\n    }\n    r => r?,\n}","preventionTips":["Use unique snapshot paths per worktree/session to avoid collisions","Keep the configured btrfs storage root consistent across versions and machines","Never create files manually inside the managed snapshot directory","Before reusing a dest, check whether the snapshot path already exists and clean it deliberately"],"tags":["btrfs","safety-guard","filesystem","path-conflict"],"backgroundTag":"refusing-to-delete-unmanaged-path","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}