xai-org/grok-build · error

invalid worktree id {:?}

Error message

invalid worktree id {:?}

What it means

try_grove_worktree validates the planned worktree id with confined::is_safe_worktree_id before contacting the daemon. A malformed or unsafe id (wrong charset/format) is rejected up front with 'invalid worktree id' so it never reaches the daemon.

Source

Thrown at crates/codegen/xai-fast-worktree/src/nfs/mod.rs:111

    #[cfg(target_os = "linux")]
    {
        if !grove_fuse_ready() {
            tracing::info!("grove-fuse skipped: /dev/fuse or fusermount missing");
            return Ok(None);
        }
        let has_delegate = plan.btrfs_delegate.is_some();
        if !has_delegate
            && matches!(
                crate::mount_info::current_mount_ns_status(),
                crate::mount_info::MountNsStatus::Private
            )
        {
            tracing::info!("grove-fuse skipped: private mount namespace");
            return Ok(None);
        }
    }
    if !confined::is_safe_worktree_id(&plan.worktree_id) {
        anyhow::bail!("invalid worktree id {:?}", plan.worktree_id);
    }
    let linked = source_is_linked_local_view(opts, &plan.source);
    if dest_is_projected_mount(&plan.source) {
        if !linked {
            tracing::info!(
                source = %plan.source.display(),
                "nfs worktree skipped: source is itself an NFS mount"
            );
            return Ok(None);
        }
        if matches!(plan.working_tree, WorkingTreeMode::PreserveWorkingTree) {
            tracing::info!(
                source = %plan.source.display(),
                "nfs worktree skipped: preserve on a linked local-codebase view"
            );
            return Ok(None);
        }
    } else if !dest_is_known_unmounted(&plan.source) && !dest_is_mountpoint(&plan.source) {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Sanitize the id before planning: replace '/', '\\', '..' and unsafe chars (e.g. use a slug/hash of the source path)
  2. Use a library-provided id generator / the confined module helpers to mint valid ids
  3. Check the plan construction to ensure worktree_id is the canonical id, not a path

Example fix

// before
let id = format!("{}", branch_name); // "feature/foo"
// after
let id: String = branch_name.chars().map(|c| if c.is_ascii_alphanumeric() || c=='-' || c=='_' { c } else { '_' }).collect();
if !confined::is_safe_worktree_id(&id) { bail!("cannot derive safe worktree id from {:?}", branch_name); }
Defensive patterns

Strategy: validation

Validate before calling

fn safe_id(id: &str) -> bool {
    !id.is_empty()
        && id.len() <= 64
        && id.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
}
if !safe_id(&plan.worktree_id) { /* fix id before calling */ }

Prevention

When it happens

Trigger: Calling try_grove_worktree with a plan whose worktree_id contains path separators, '..', non-ASCII/unsafe characters, or is otherwise not passing is_safe_worktree_id; callers include the storage-full mapping path and the invalid_worktree_id_never_contacts_daemon test.

Common situations: Deriving worktree ids from user/branch names without sanitizing (slashes in branch names); ids built by concatenating paths; older versions of the tool writing ids that the stricter validator now rejects.

Related errors


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