{"record":{"id":"9e9352b310de30ef","repo":"BigPizzaV3/CodexPlusPlus","slug":"grok-alias","errorCode":null,"errorMessage":"Grok 模型别名与未管理配置冲突：{alias}","messagePattern":"Grok 模型别名与未管理配置冲突：(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/grok_config.rs","lineNumber":264,"sourceCode":"        update_table_string(table, \"model\", &input.model);\n        update_table_string(table, \"name\", &input.name);\n        update_table_string(table, \"base_url\", &input.base_url);\n        update_table_string(table, \"api_backend\", &input.api_backend);\n        match input.context_window {\n            Some(value) => {\n                table.insert(\"context_window\", toml_edit::value(value as i64));\n            }\n            None => {\n                table.remove(\"context_window\");\n            }\n        }\n        if input.remove_api_key {\n            table.remove(\"api_key\");\n        } else if !input.api_key_update.trim().is_empty() {\n            table.insert(\"api_key\", toml_edit::value(input.api_key_update.trim()));\n        }\n        if models.contains_key(alias) {\n            bail!(\"Grok 模型别名与未管理配置冲突：{alias}\");\n        }\n        models.insert(alias, item);\n    }\n    Ok(())\n}\n\nfn validate_request(request: &SaveGrokConfigRequest) -> anyhow::Result<()> {\n    let mut aliases = HashSet::new();\n    let mut sources = HashSet::new();\n    for input in &request.models {\n        let alias = input.alias.trim();\n        if alias.is_empty() {\n            bail!(\"Grok 模型别名不能为空\");\n        }\n        if alias.chars().any(char::is_control) {\n            bail!(\"Grok 模型别名不能包含控制字符\");\n        }\n        if !aliases.insert(alias.to_string()) {","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/grok_config.rs#L246-L282","documentation":"update_models merges the requested model entries into the [models] table of the Grok config.toml. When an alias requested for insertion already exists as a key in the existing (unmanaged portion of the) models table, the library bails instead of silently overwriting a user-defined entry it does not manage. This protects externally authored model aliases from being clobbered by a save.","triggerScenarios":"Calling save_grok_config with request.models containing an alias whose key already exists in the parsed config's models table (an entry not originating from the managed set), causing the models.contains_key(alias) check to fire.","commonSituations":"User hand-edited config.toml and added a model with the same alias the manager uses; a previous version of the config created the alias outside the managed flow; importing a saved profile whose aliases collide with existing config entries.","solutions":["Open config.toml and inspect the [models] table for the conflicting alias named in the error.","Rename either the existing alias in config.toml or the alias in your save request.","Remove the stale unmanaged entry if it is no longer needed (back up config.toml first).","Re-read the config to get a fresh revision, then retry the save.","Keep all alias management through the manager to avoid unmanaged duplicates."],"exampleFix":"// before: [models] already has \"fast\" and request also inserts \"fast\"\n[models]\nfast = { model = \"grok-2\" }\n// after: rename the new entry (or remove the old one)\n[models]\nfast = { model = \"grok-2\" }\nfast-v2 = { model = \"grok-3\" }","handlingStrategy":"validation","validationCode":"let current = read_grok_config()?;\nlet existing: HashSet<&str> = current.models.keys().map(|k| k.as_str()).collect();\nlet clash = request.models.iter().find(|m| existing.contains(m.alias.as_str()));\nif let Some(m) = clash {\n    return Err(format!(\"alias conflicts with unmanaged config: {}\", m.alias));\n}","typeGuard":"fn alias_free(existing: &BTreeMap<String, Value>, alias: &str) -> bool {\n    !existing.contains_key(alias)\n}","tryCatchPattern":"match save_grok_config(req).await {\n    Err(e) if e.to_string().contains(\"别名与未管理配置冲突\") => eprintln!(\"rename alias or remove unmanaged entry, then retry\"),\n    other => other?,\n}","preventionTips":["Read existing [models] keys before choosing new aliases.","Use a naming convention/prefix for manager-managed aliases.","Migrate hand-edited config entries into the managed flow.","Back up config.toml before removing conflicting entries."],"tags":["grok-config","alias-conflict","models"],"backgroundTag":"file-already-exists","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}