xai-org/grok-build · error

Failed to create agent config: {e}

Error message

Failed to create agent config: {e}

What it means

workspace_control loads the agent configuration strictly from disk (no network/remote refresh) before connecting to the leader. If load_agent_config_disk_only fails — missing config file, invalid TOML, unreadable permissions — the error is wrapped as "Failed to create agent config: {e}". No leader connection is attempted.

Source

Thrown at crates/codegen/xai-grok-pager-bin/src/main.rs:598

        ClientMode::Stdio,
        ClientCapabilities::default(),
    )
    .await
    .map_err(|e| {
        anyhow::anyhow!(
            "no running leader for this environment ({e}). \
             Start a grok session, or run `grok workspace start`."
        )
    })
}
#[tracing::instrument(level = "debug", skip_all)]
async fn workspace_control(
    target: &LeaderTargetArgs,
    json: bool,
    command: ControlCommand,
) -> Result<()> {
    let agent_config = xai_grok_shell::config::load_agent_config_disk_only()
        .map_err(|e| anyhow::anyhow!("Failed to create agent config: {e}"))?;
    let client = connect_workspace_control(&agent_config, target).await?;
    ensure_workspace_caps(client.registration())?;
    let payload = client.send_control(command).await??;
    render_workspace_payload(&payload, json);
    client.cancel();
    Ok(())
}
#[tracing::instrument(level = "debug", skip_all)]
async fn workspace_start(
    args: WorkspaceStartArgs,
    restart: bool,
    remote_settings: Option<xai_grok_shell::util::config::RemoteSettings>,
) -> Result<()> {
    use xai_grok_shell::auth::ensure_authenticated;
    xai_grok_shell::util::config::set_remote_campaigns_from_settings(remote_settings.as_ref());
    let raw_config = xai_grok_shell::config::load_effective_config()
        .map_err(|e| anyhow::anyhow!("Failed to load config: {e}"))?;
    let agent_config = AgentConfig::new_from_toml_cfg(&raw_config)

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Read the wrapped {e} to see whether the file is missing, invalid, or unreadable
  2. Run the normal grok onboarding/auth flow once to generate the on-disk config
  3. Fix TOML syntax errors in the config file (validate with a TOML linter)
  4. Check file permissions and that HOME/XDG_CONFIG env vars point at the directory containing the config

Example fix

// before
$ grok workspace list   # fails: no ~/.config/grok/config.toml on new machine
// after
$ grok auth login        # generates on-disk config
$ grok workspace list
Defensive patterns

Strategy: validation

Validate before calling

let cfg_path = config_dir().join("config.toml");
if !cfg_path.exists() {
    return Err(anyhow!("agent config missing at {} — run `grok auth login` first", cfg_path.display()));
}
// parse-check without side effects
let _raw = std::fs::read_to_string(&cfg_path)?;
let _: toml::Value = toml::from_str(&_raw)?;

Type guard

fn config_readable(path: &std::path::Path) -> bool {
    std::fs::read_to_string(path)
        .ok()
        .and_then(|s| toml::from_str::<toml::Value>(&s).ok())
        .is_some()
}

Try / catch

match workspace_control(&target, json, cmd).await {
    Err(e) if e.to_string().contains("Failed to create agent config") => {
        eprintln!("config problem: {e:#}. Fix or regenerate the on-disk config.");
        std::process::exit(1);
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling workspace_control when load_agent_config_disk_only returns Err: config file absent at the expected path, TOML parse error, or filesystem permission denial.

Common situations: Fresh machine where `grok` was never configured (no on-disk config); hand-edited config.toml with syntax errors; config owned by another user or HOME/XDG env vars pointing elsewhere.

Related errors


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