{"record":{"id":"9c3aee6b3d226054","repo":"xai-org/grok-build","slug":"failed-to-create-agent-config-e-9c3aee","errorCode":null,"errorMessage":"Failed to create agent config: {e}","messagePattern":"Failed to create agent config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/headless.rs","lineNumber":785,"sourceCode":"        None => std::env::current_dir()?,\n        Some(ref p) => dunce::canonicalize(p)?,\n    };\n\n    let mut emitter = HeadlessEmitter::new(options.output_format, options.json_schema.is_some());\n\n    if options.include_partial_messages\n        && options.output_format != OutputFormat::StreamingMessagesJson\n    {\n        eprintln!(\n            \"warning: --include-partial-messages only affects --output-format streaming-messages-json; ignoring it\"\n        );\n    }\n\n    let t_spawn = Instant::now();\n    let raw_config = xai_grok_shell::config::load_effective_config()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load config: {e}\"))?;\n    let mut agent_config = AgentConfig::new_from_toml_cfg(&raw_config)\n        .map_err(|e| anyhow::anyhow!(\"Failed to create agent config: {e}\"))?;\n\n    // Only canonical tokens are stamped early; remapped menu ids need the post-session catalog resolve below\n    if let Some(ref token) = options.reasoning_effort\n        && let Some(effort) = parse_canonical_effort_token(token)\n    {\n        agent_config.reasoning_effort_override = Some(effort);\n    }\n    // Stamp `-m` early so the initial system prompt uses it, not a later SetSessionModel.\n    if let Some(ref model) = options.model {\n        agent_config.default_model_override = Some(model.clone());\n    }\n\n    agent_config.resolve_runtime_fields(&xai_grok_shell::agent::config::RuntimeResolutionContext {\n        raw_config: &raw_config,\n        remote_settings: None,\n        is_headless: true,\n        cli_subagents: None,\n        cli_web_search_model: None,","sourceCodeStart":767,"sourceCodeEnd":803,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/headless.rs#L767-L803","documentation":"run_single_turn wraps failures from AgentConfig::new_from_toml_cfg(&raw_config) with 'Failed to create agent config: {e}'. The raw TOML loaded fine, but one or more fields could not be converted into the typed AgentConfig (missing required key, wrong type, or semantically invalid value).","triggerScenarios":"Calling run_single_turn with a config whose parsed TOML does not match AgentConfig's expected schema: e.g. model id empty, api_key not a string, numeric fields given as strings, unknown enum value for a setting.","commonSituations":"Upgrading the binary after AgentConfig gained/renamed fields while the old config.toml persists; copying a config from another tool with a different schema; hand-editing values to the wrong type.","solutions":["Read the inner {e}; it names the offending field and expected type","Align config.toml keys/types with the current AgentConfig schema","Delete or rename the stale config so defaults are regenerated","Pin the config schema version / run the tool's config-migration step"],"exampleFix":"// before (config.toml)\nmax_turns = \"25\"\n// after\nmax_turns = 25","handlingStrategy":"validation","validationCode":"let raw = xai_grok_shell::config::load_effective_config()?;\n// dry-convert to catch schema drift before starting a session\nif let Err(e) = xai_grok_shell::agent::config::AgentConfig::new_from_toml_cfg(&raw) {\n    eprintln!(\"agent config schema mismatch: {e:#}\");\n    std::process::exit(2);\n}","typeGuard":"fn toml_field_is<'a, T: serde::Deserialize<'a>>(cfg: &'a toml::Value, key: &str) -> bool {\n    cfg.get(key).map(|v| T::deserialize(v).is_ok()).unwrap_or(false)\n}","tryCatchPattern":"match AgentConfig::new_from_toml_cfg(&raw_config) {\n    Ok(cfg) => cfg,\n    Err(e) => { eprintln!(\"Failed to create agent config: {e:#}\"); std::process::exit(2); }\n}","preventionTips":["Keep config.toml in sync with the AgentConfig schema version","Run a config check command after upgrades","Type-check numeric fields are not quoted strings","Migrate configs with the tool's migration step, not by hand"],"tags":["config","schema","rust","deserialization"],"backgroundTag":"schema-validation-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}