BigPizzaV3/CodexPlusPlus · error

Grok 模型别名与未管理配置冲突:

Error message

Grok 模型别名与未管理配置冲突:{alias}

What it means

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.

Solutions

  1. Open config.toml and inspect the [models] table for the conflicting alias named in the error.
  2. Rename either the existing alias in config.toml or the alias in your save request.
  3. Remove the stale unmanaged entry if it is no longer needed (back up config.toml first).
  4. Re-read the config to get a fresh revision, then retry the save.
  5. Keep all alias management through the manager to avoid unmanaged duplicates.

Example fix

// before: [models] already has "fast" and request also inserts "fast"
[models]
fast = { model = "grok-2" }
// after: rename the new entry (or remove the old one)
[models]
fast = { model = "grok-2" }
fast-v2 = { model = "grok-3" }
Defensive patterns

Strategy: validation

Validate before calling

let current = read_grok_config()?;
let existing: HashSet<&str> = current.models.keys().map(|k| k.as_str()).collect();
let clash = request.models.iter().find(|m| existing.contains(m.alias.as_str()));
if let Some(m) = clash {
    return Err(format!("alias conflicts with unmanaged config: {}", m.alias));
}

Type guard

fn alias_free(existing: &BTreeMap<String, Value>, alias: &str) -> bool {
    !existing.contains_key(alias)
}

Try / catch

match save_grok_config(req).await {
    Err(e) if e.to_string().contains("别名与未管理配置冲突") => eprintln!("rename alias or remove unmanaged entry, then retry"),
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

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

        update_table_string(table, "model", &input.model);
        update_table_string(table, "name", &input.name);
        update_table_string(table, "base_url", &input.base_url);
        update_table_string(table, "api_backend", &input.api_backend);
        match input.context_window {
            Some(value) => {
                table.insert("context_window", toml_edit::value(value as i64));
            }
            None => {
                table.remove("context_window");
            }
        }
        if input.remove_api_key {
            table.remove("api_key");
        } else if !input.api_key_update.trim().is_empty() {
            table.insert("api_key", toml_edit::value(input.api_key_update.trim()));
        }
        if models.contains_key(alias) {
            bail!("Grok 模型别名与未管理配置冲突:{alias}");
        }
        models.insert(alias, item);
    }
    Ok(())
}

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()) {

View on GitHub (pinned to b1ed92e5e4)