xai-org/grok-build · error

Failed to load config: {e}

Error message

Failed to load config: {e}

What it means

workspace_start loads the full effective configuration (load_effective_config) and wraps any failure as "Failed to load config: {e}". Unlike the disk-only loader, this may merge remote/derived settings, so failures include on-disk problems plus errors from computing the effective view. Startup aborts before resolving leader mode.

Source

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

    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)
        .map_err(|e| anyhow::anyhow!("Failed to create agent config: {e}"))?;
    let (use_leader, _) = resolve_use_leader(
        args.leader,
        args.no_leader,
        &raw_config,
        remote_settings.as_ref(),
        true,
        xai_grok_sandbox::requested_confinement_profile(),
    );
    if !use_leader {
        anyhow::bail!(
            "`grok workspace` requires leader mode (the workspace is shared via the leader).\n\
             Enable it with `[cli] use_leader = true` in ~/.grok/config.toml, or pass --leader."
        );
    }
    ensure_authenticated(
        &agent_config.grok_com_config,

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Inspect the wrapped {e} for the concrete load failure (file vs parse vs merge)
  2. Fix TOML syntax or invalid values in the config, or restore a known-good backup
  3. Re-run grok onboarding/auth to regenerate a valid base config
  4. Verify HOME/XDG environment variables point to the intended config directory

Example fix

// before
# ~/.config/grok/config.toml
model = 
// after
# ~/.config/grok/config.toml
model = "grok-4"   # valid TOML value
Defensive patterns

Strategy: validation

Validate before calling

let cfg_path = config_dir().join("config.toml");
if !cfg_path.exists() {
    return Err(anyhow!("config not found at {} — run onboarding first", cfg_path.display()));
}
let raw = std::fs::read_to_string(&cfg_path)?;
let _: toml::Value = toml::from_str(&raw)?; // catch parse errors before workspace_start

Type guard

fn effective_config_loadable() -> bool {
    xai_grok_shell::config::load_effective_config().is_ok()
}

Try / catch

match workspace_start(&args, restart, remote_settings).await {
    Err(e) if e.to_string().contains("Failed to load config") => {
        eprintln!("config load failed: {e:#}. Restore or fix config.toml.");
        std::process::exit(1);
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling workspace_start when load_effective_config returns Err: missing base config, unparsable TOML, or errors while applying overrides/remote settings to build the effective config.

Common situations: Corrupt or hand-edited config after an upgrade introduced new required keys; conflicting overrides producing an invalid effective config; unreadable config file or wrong HOME/XDG paths.

Related errors


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