BigPizzaV3/CodexPlusPlus · error

Grok 模型来源别名重复:

Error message

Grok 模型来源别名重复:{source}

What it means

Each model entry may declare a source_alias (upstream model it maps from). validate_request requires non-empty source aliases to be unique across the request. A duplicate causes this error and aborts the save, preventing two local aliases from ambiguously resolving to conflicting upstream definitions.

Solutions

  1. Give each entry a distinct source_alias
  2. If two local aliases should share one upstream source, verify the tooling supports that or split into separate saves
  3. Trim/normalize source_alias strings before comparing

Example fix

// before
[{alias:"a", source_alias:"grok-4"}, {alias:"b", source_alias:"grok-4"}]
// after
[{alias:"a", source_alias:"grok-4"}, {alias:"b", source_alias:"grok-4-preview"}]
Defensive patterns

Strategy: validation

Validate before calling

let srcs: HashSet<&str> = request.models.iter().filter_map(|m| { let s = m.source_alias.trim(); if s.is_empty() { None } else { Some(s) } }).collect(); assert_eq!(srcs.len(), count_nonempty);

Try / catch

if let Err(e) = save_grok_config_at(...) { if e.to_string().contains("来源别名重复") { /* dedupe source aliases */ } }

Prevention

When it happens

Trigger: save_grok_config_at called with two entries whose trimmed source_alias is identical and non-empty (sources.insert returns false).

Common situations: Mapping several local names to the same upstream alias via a copy-paste template; bulk import scripts generating the same source_alias for multiple models when only one mapping was intended.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/c6a2d05f063a1385. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/grok_config.rs:287

}

fn validate_request(request: &SaveGrokConfigRequest) -> anyhow::Result<()> {
    let mut aliases = HashSet::new();
    let mut sources = HashSet::new();
    for input in &request.models {
        let alias = input.alias.trim();
        if alias.is_empty() {
            bail!("Grok 模型别名不能为空");
        }
        if alias.chars().any(char::is_control) {
            bail!("Grok 模型别名不能包含控制字符");
        }
        if !aliases.insert(alias.to_string()) {
            bail!("Grok 模型别名重复:{alias}");
        }
        let source = input.source_alias.trim();
        if !source.is_empty() && !sources.insert(source.to_string()) {
            bail!("Grok 模型来源别名重复:{source}");
        }
        if !matches!(
            input.api_backend.trim(),
            "responses" | "chat_completions" | "messages"
        ) {
            bail!("Grok 模型 {alias} 的 API 协议无效");
        }
        if input.context_window == Some(0) {
            bail!("Grok 模型 {alias} 的上下文窗口必须大于 0");
        }
        if input
            .context_window
            .is_some_and(|value| value > i64::MAX as u64)
        {
            bail!("Grok 模型 {alias} 的上下文窗口过大");
        }
        if input.remove_api_key && !input.api_key_update.is_empty() {
            bail!("Grok 模型 {alias} 不能同时替换并移除 API Key");

View on GitHub (pinned to b1ed92e5e4)