xai-org/grok-build · error
Failed to create agent config: {e}
Error message
Failed to create agent config: {e} What it means
This error wraps a failure from AgentConfig::new_from_toml_cfg while building the ACP agent configuration from the raw TOML config during connect_via_leader. The library throws it because the leader process cannot proceed without a valid AgentConfig; the underlying parse/validation error is embedded in the message.
Source
Thrown at crates/codegen/xai-grok-pager/src/acp/mod.rs:290
cancel: &CancellationToken,
flags: ConnectFlags,
raw_config: &toml::Value,
) -> Result<AcpConnection> {
use xai_grok_shell::leader::{
ClientCapabilities, ClientMode, LeaderReconnector, ReconnectPolicy, connect_or_spawn,
};
// These flags are baked into the agent at startup
// In leader mode the agent is already running, so per-client overrides cannot be applied
warn_unsupported_leader_flags(&flags);
apply_config_writes(&flags);
startup::enter(StartupPhase::ConfigLoad);
// The leader path never runs the managed-policy sync in this process.
startup::set_auth_mode(xai_grok_shell::managed_config::classify_auth_mode());
let mut agent_config = AgentConfig::new_from_toml_cfg(raw_config)
.map_err(|e| anyhow::anyhow!("Failed to create agent config: {e}"))?;
// resolve_telemetry_mode reads remote_settings.
agent_config.remote_settings = flags.remote_settings.clone();
let client_type = flags
.client_identifier
.as_deref()
.unwrap_or(HEADLESS_CLIENT_TYPE);
let env_urls = xai_grok_shell::leader::LeaderEnvUrls::from(&agent_config.grok_com_config);
let capabilities = ClientCapabilities {
// Leader agent is pre-running; capabilities carry the mode seeds into session meta
yolo_mode: flags.default_yolo_mode,
auto_mode: flags.default_auto_mode && !flags.default_yolo_mode,
default_model: agent_config.models.default.clone(),
client_version: Some(PAGER_CLIENT_VERSION.to_string()),
code_nav_enabled: false,
terminal: flags.terminal,
fs_read: flags.fs_read,
fs_write: flags.fs_write,View on GitHub (pinned to bc7f02eddd)
Solutions
- Read the embedded {e} message to identify the exact TOML key or value that failed validation
- Fix or regenerate the TOML config so it matches the AgentConfig schema
- Validate the config with new_from_toml_cfg in a preflight check before connect_via_leader
- If caused by an upgrade, migrate the config to the current schema
Example fix
// before
let agent_config = AgentConfig::new_from_toml_cfg(raw_config)
.map_err(|e| anyhow::anyhow!("Failed to create agent config: {e}"))?;
// after
// preflight: parse and inspect errors with context
let agent_config = AgentConfig::new_from_toml_cfg(&raw_config)
.with_context(|| format!("invalid agent config: {}", raw_config.path()))?; Defensive patterns
Strategy: validation
Validate before calling
fn validate_agent_config(raw: &str) -> Result<(), String> {
raw.parse::<toml::Value>().map_err(|e| format!("invalid TOML: {e}"))?;
Ok(())
}
// call validate_agent_config(&raw_config) before connect_via_leader Try / catch
match connect_via_leader(cfg).await {
Err(e) if e.to_string().starts_with("Failed to create agent config") => {
eprintln!("config error: {e:#}"); // inspect chained source for the TOML detail
}
r => r?,
} Prevention
- Validate TOML config against the AgentConfig schema at startup before connecting
- Version-control the config and lint it in CI
- After upgrades, diff config keys against the new schema
- Keep per-environment overrides small and reviewed
When it happens
Trigger: Calling connect_via_leader when raw_config contains invalid TOML, missing required keys, or values that fail AgentConfig validation.
Common situations: Hand-edited or stale config files, schema drift after upgrading (renamed/removed config keys), environment-specific overrides producing invalid TOML, typos in config fields.
Understand the failure class
Background: Config validation failed: what "invalid value for {key}" and settings-rejection errors mean across 19 open-source libraries — this error's family across 19 libraries.
Related errors
- Failed to load config: {e}
- Failed to load config: {e}
- Failed to load config: {e}
- Failed to load config: {}
- Failed to parse config.toml: {e}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/420976fc549658fd.
Report an issue: GitHub.