xai-org/grok-build · error · io::Error

trust store path has no parent

Error message

trust store path has no parent

What it means

record_decision persists a trust decision to a store file and uses a lock file placed in the store path's parent directory. Before creating the directory it calls path.parent(); a Path has no parent only when it is a bare root (e.g. '/' with no file name or an empty/relative single-component path in effect). If there is no parent, it fails with io::ErrorKind::InvalidInput, 'trust store path has no parent'.

Source

Thrown at crates/codegen/xai-grok-workspace/src/trust.rs:265

                "folder trust: refusing to record an over-broad root (home, filesystem root, or non-absolute path); nothing recorded"
            );
            return Ok(());
        }

        // No backing file (no-home env) → record nothing, return `Ok` so
        // callers treat "no home" like "nothing to persist" (see fn doc).
        let Some(path) = self.path.as_deref() else {
            tracing::warn!(
                path = %canonical.display(),
                trusted,
                "folder trust: no user grok home resolved; trust decision not recorded"
            );
            return Ok(());
        };

        // The lock file lives beside the store, so ensure the dir exists first.
        let parent = path.parent().ok_or_else(|| {
            io::Error::new(
                io::ErrorKind::InvalidInput,
                "trust store path has no parent",
            )
        })?;
        std::fs::create_dir_all(parent)?;

        // Serialize cross-process writers for the whole read-modify-write so a
        // concurrent peer's records are preserved, not clobbered.
        let _lock = ExclusiveLock::acquire(&path.with_extension("toml.lock"))?;

        // Re-read the latest on-disk state (merges a peer's concurrent writes).
        let mut doc = Self::read_doc(path);
        doc.folders.insert(
            canonical.to_string_lossy().to_string(),
            FolderTrust {
                trusted,
                decided_at: now_unix(),
            },

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Configure a full file path for the trust store (e.g. ~/.config/xai-grok/trust.toml), not an empty or root-only path.
  2. Validate the store path before calling: ensure path.parent() is Some and the file name is present.
  3. Fix the environment/config source that supplies an empty trust-store path.
  4. If the path is relative by design, make it absolute first so parent() is meaningful.

Example fix

// before
let store: PathBuf = config.trust_store.unwrap_or_default().into(); // empty -> no parent
set_trusted(&host, &store).await?;
// after
let store = PathBuf::from(config.trust_store.unwrap_or_else(|| "~/.config/xai-grok/trust.toml".into()));
assert!(store.parent().is_some(), "trust store path needs a parent dir");
set_trusted(&host, &store).await?;
Defensive patterns

Strategy: validation

Validate before calling

fn trust_store_ok(path: &std::path::Path) -> bool {
    path.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false)
        && path.file_name().is_some()
}
// reject empty/root-only store paths at config load time

Try / catch

match set_trusted(&host, &store).await {
    Ok(()) => {}
    Err(e) if e.to_string().contains("trust store path has no parent") => {
        let fixed = default_trust_store_path();
        set_trusted(&host, &fixed).await?;
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Calling record_decision (directly or via set_trusted/set_untrusted) with a trust store path that has no parent component — e.g. an empty path, a bare root, or a path constructed as just a file name where parent() yields None (typically empty strings converted to a Path).

Common situations: Config value for the trust store left empty or unset and later coerced into a Path; misassembled path strings from environment variables; passing a root-only path instead of a full file path to the store.

Related errors


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