xai-org/grok-build · error
Failed to load config: {e}
Error message
Failed to load config: {e} What it means
run_single_turn wraps any failure from xai_grok_shell::config::load_effective_config() in an anyhow context 'Failed to load config: {e}'. It means the effective configuration (TOML config file plus environment overrides) could not be read, found, or parsed, so no agent session can start.
Source
Thrown at crates/codegen/xai-grok-pager/src/headless.rs:783
let cwd = match options.cwd {
None => std::env::current_dir()?,
Some(ref p) => dunce::canonicalize(p)?,
};
let mut emitter = HeadlessEmitter::new(options.output_format, options.json_schema.is_some());
if options.include_partial_messages
&& options.output_format != OutputFormat::StreamingMessagesJson
{
eprintln!(
"warning: --include-partial-messages only affects --output-format streaming-messages-json; ignoring it"
);
}
let t_spawn = Instant::now();
let raw_config = xai_grok_shell::config::load_effective_config()
.map_err(|e| anyhow::anyhow!("Failed to load config: {e}"))?;
let mut agent_config = AgentConfig::new_from_toml_cfg(&raw_config)
.map_err(|e| anyhow::anyhow!("Failed to create agent config: {e}"))?;
// Only canonical tokens are stamped early; remapped menu ids need the post-session catalog resolve below
if let Some(ref token) = options.reasoning_effort
&& let Some(effort) = parse_canonical_effort_token(token)
{
agent_config.reasoning_effort_override = Some(effort);
}
// Stamp `-m` early so the initial system prompt uses it, not a later SetSessionModel.
if let Some(ref model) = options.model {
agent_config.default_model_override = Some(model.clone());
}
agent_config.resolve_runtime_fields(&xai_grok_shell::agent::config::RuntimeResolutionContext {
raw_config: &raw_config,
remote_settings: None,
is_headless: true,View on GitHub (pinned to bc7f02eddd)
Solutions
- Read the inner {e} message; it states the exact file path and parse error
- Run with an explicitly valid config path / restore a known-good config.toml
- Validate the TOML with a linter (e.g. taplo) before restarting
- Reinstall or regenerate default config via the shell's init command if the file is corrupted
Example fix
// before: blindly loading config
let raw_config = xai_grok_shell::config::load_effective_config()?;
// after: check existence and fail with an actionable message
let path = xai_grok_shell::config::default_config_path();
anyhow::ensure!(path.exists(), "config not found at {}; run the init command", path.display());
let raw_config = xai_grok_shell::config::load_effective_config()?; Defensive patterns
Strategy: validation
Validate before calling
let path = xai_grok_shell::config::default_config_path();
if !path.exists() {
eprintln!("config missing at {} — run init or set the config path", path.display());
std::process::exit(2);
}
if let Err(e) = std::fs::read_to_string(&path).and_then(|s| toml::from_str::<toml::Value>(&s).map_err(std::io::Error::other).map(|_| ())) {
eprintln!("config invalid: {e}");
std::process::exit(2);
} Type guard
fn config_readable(path: &std::path::Path) -> bool {
path.is_file() && std::fs::read_to_string(path)
.map(|s| toml::from_str::<toml::Value>(&s).is_ok())
.unwrap_or(false)
} Try / catch
match xai_grok_shell::config::load_effective_config() {
Ok(cfg) => cfg,
Err(e) => { eprintln!("Failed to load config: {e:#}"); std::process::exit(2); }
} Prevention
- Validate config.toml with a TOML linter in CI before deploys
- Regenerate defaults after upgrading the binary
- Never hand-edit config without re-validating
- Pin config path via env var explicitly in scripts
When it happens
Trigger: Calling run_single_turn (headless single-turn run) when load_effective_config() fails: the config file path is set but missing/unreadable, the TOML is syntactically invalid, or an env-var override has an invalid value.
Common situations: First run with no config file at the expected location; hand-edited config.toml with a typo; XDG_CONFIG_HOME or a config-path env var pointing to the wrong directory; config written by a newer version with unknown keys/types.
Related errors
- Failed to create agent config: {e}
- config root is not a table
- disabled_mcp_tools is not a table
- refusing to overwrite unparseable {}: {}; fix the syntax bef
- Failed to load config: {e}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/24afe9627f1ee1ac.
Report an issue: GitHub.