Hmbown/CodeWhale · error

The destination config has a different provider identity

Error message

The destination config has a different provider identity

What it means

This error is thrown by set_provider_model_document when the TOML config document being written resolves the given provider_identity to a provider pin whose provider does not match the provider argument. It is a safety guard so the writer never writes a model value under the wrong provider's route identity.

Solutions

  1. Re-read the config and resolve the identity first (Config::resolve_provider_pin_identity), then pass the matching provider value.
  2. Check whether the provider_identity string is stale — refresh it from the current config before persisting.
  3. If the config was hand-edited, fix the provider pin so it matches the intended provider, or remove the pin so identity resolution falls back to the default provider.

Example fix

// before
set_provider_model_document(doc, "my-old-provider", ApiProvider::Anthropic, model)
// after
let config: Config = toml::from_str(&doc.to_string())?;
let identity = config.resolve_provider_pin_identity("my-old-provider")?;
set_provider_model_document(doc, "my-old-provider", identity.provider, model)
Defensive patterns

Strategy: validation

Validate before calling

let config: Config = toml::from_str(&doc.to_string())?;
let identity = config.resolve_provider_pin_identity(provider_identity)?;
if identity.provider != provider {
    eprintln!("identity {} pins {:?}, not {:?}", provider_identity, identity.provider, provider);
}

Type guard

fn identity_matches(config: &Config, provider_identity: &str, provider: ApiProvider) -> bool {
    config.resolve_provider_pin_identity(provider_identity)
        .map(|i| i.provider == provider)
        .unwrap_or(false)
}

Try / catch

match persist_provider_model_key(&path, provider, identity, model) {
    Err(e) if e.to_string().contains("different provider identity") => re_resolved_identity_retry(),
    other => other?,
}

Prevention

When it happens

Trigger: Calling set_provider_model_document (directly or via migrate_legacy_route_preferences, persist_provider_selection, reconcile_root_model_aliases, or persist_provider_model_key) with a provider and a provider_identity string whose pin in the destination config resolves to a different ApiProvider.

Common situations: A stale provider identity string (e.g. a persisted custom-provider name or pin id) still refers to an old provider after the config was edited or another switch happened; the caller passes the default provider while the config pins that identity to a different one.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/99770b81600aae42. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/config_persistence.rs:173

}

pub(crate) fn set_provider_model_document(
    doc: &mut toml_edit::DocumentMut,
    provider: ApiProvider,
    provider_identity: &str,
    model: &str,
) -> anyhow::Result<()> {
    anyhow::ensure!(
        !model.trim().is_empty() && !model.chars().any(char::is_control),
        "model must be nonempty and contain no control characters"
    );
    let config: crate::config::Config = toml::from_str(&doc.to_string()).map_err(|_| {
        anyhow::anyhow!("Could not parse destination route identity; contents omitted")
    })?;
    let identity = config
        .resolve_provider_pin_identity(provider_identity)
        .map_err(anyhow::Error::msg)?;
    anyhow::ensure!(
        identity.provider == provider,
        "The destination config has a different provider identity"
    );
    let provider_key = if provider == ApiProvider::Custom {
        if identity.persisted_id().is_none() {
            return set_document_value(doc, &["default_text_model"], model);
        }
        identity.key
    } else if identity.migrated_legacy_ollama_cloud_route {
        "ollama".to_string()
    } else if provider == ApiProvider::DeepseekCN {
        "deepseek_cn".to_string()
    } else {
        provider
            .metadata()
            .context("provider config metadata")?
            .provider_config_key()
            .to_string()

View on GitHub (pinned to 73e0f67d83)