{"record":{"id":"3b581129af2795bf","repo":"BigPizzaV3/CodexPlusPlus","slug":"grok-alias-config","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":283,"sourceCode":"        }\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()) {\n            bail!(\"Grok 模型别名重复：{alias}\");\n        }\n        let source = input.source_alias.trim();\n        if !source.is_empty() && !sources.insert(source.to_string()) {\n            bail!(\"Grok 模型来源别名重复：{source}\");\n        }\n        if !matches!(\n            input.api_backend.trim(),\n            \"responses\" | \"chat_completions\" | \"messages\"\n        ) {\n            bail!(\"Grok 模型 {alias} 的 API 协议无效\");\n        }\n        if input.context_window == Some(0) {\n            bail!(\"Grok 模型 {alias} 的上下文窗口必须大于 0\");\n        }\n        if input\n            .context_window\n            .is_some_and(|value| value > i64::MAX as u64)\n        {","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/grok_config.rs#L265-L301","documentation":"validate_request enforces that every model alias in a Grok save request is unique using a HashSet insert. If two entries in request.models share the same trimmed alias, this error aborts the whole save before any config is written, since duplicates would silently overwrite each other in the generated TOML.","triggerScenarios":"save_grok_config_at called where two or more entries in request.models have identical trimmed alias values (HashSet::insert returns false on the second insert).","commonSituations":"Duplicating a row in the manager UI's model list and forgetting to rename it; merging two config sources that both define grok-4; scripted batch imports appending an entry that already exists.","solutions":["De-duplicate request.models before saving (keep one entry per alias)","Rename one of the conflicting models so each alias is unique","If both entries are intended, confirm which one to keep and delete the other"],"exampleFix":"// before\nmodels: [ {alias: \"grok-4\", ...}, {alias: \"grok-4\", ...} ]\n// after\nmodels: [ {alias: \"grok-4\", ...}, {alias: \"grok-4-fast\", ...} ]","handlingStrategy":"validation","validationCode":"let names: Vec<_> = request.models.iter().map(|m| m.alias.trim()).collect(); let uniq: HashSet<_> = names.iter().collect(); assert_eq!(names.len(), uniq.len());","typeGuard":null,"tryCatchPattern":"match save_grok_config_at(...) { Err(e) if e.to_string().contains(\"别名重复\") => { /* prompt user to rename */ } ... }","preventionTips":["De-duplicate model lists before constructing the request","In UIs, warn immediately when a new row reuses an existing alias","Use stable unique IDs in the UI keyed by row, not by alias"],"tags":["validation","duplicate","config"],"backgroundTag":"schema-validation-failed","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"}