{"record":{"id":"99770b81600aae42","repo":"Hmbown/CodeWhale","slug":"the-destination-config-has-a-different-provider-identity","errorCode":null,"errorMessage":"The destination config has a different provider identity","messagePattern":"The destination config has a different provider identity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/config_persistence.rs","lineNumber":173,"sourceCode":"}\n\npub(crate) fn set_provider_model_document(\n    doc: &mut toml_edit::DocumentMut,\n    provider: ApiProvider,\n    provider_identity: &str,\n    model: &str,\n) -> anyhow::Result<()> {\n    anyhow::ensure!(\n        !model.trim().is_empty() && !model.chars().any(char::is_control),\n        \"model must be nonempty and contain no control characters\"\n    );\n    let config: crate::config::Config = toml::from_str(&doc.to_string()).map_err(|_| {\n        anyhow::anyhow!(\"Could not parse destination route identity; contents omitted\")\n    })?;\n    let identity = config\n        .resolve_provider_pin_identity(provider_identity)\n        .map_err(anyhow::Error::msg)?;\n    anyhow::ensure!(\n        identity.provider == provider,\n        \"The destination config has a different provider identity\"\n    );\n    let provider_key = if provider == ApiProvider::Custom {\n        if identity.persisted_id().is_none() {\n            return set_document_value(doc, &[\"default_text_model\"], model);\n        }\n        identity.key\n    } else if identity.migrated_legacy_ollama_cloud_route {\n        \"ollama\".to_string()\n    } else if provider == ApiProvider::DeepseekCN {\n        \"deepseek_cn\".to_string()\n    } else {\n        provider\n            .metadata()\n            .context(\"provider config metadata\")?\n            .provider_config_key()\n            .to_string()","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/config_persistence.rs#L155-L191","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-read the config and resolve the identity first (Config::resolve_provider_pin_identity), then pass the matching provider value.","Check whether the provider_identity string is stale — refresh it from the current config before persisting.","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."],"exampleFix":"// before\nset_provider_model_document(doc, \"my-old-provider\", ApiProvider::Anthropic, model)\n// after\nlet config: Config = toml::from_str(&doc.to_string())?;\nlet identity = config.resolve_provider_pin_identity(\"my-old-provider\")?;\nset_provider_model_document(doc, \"my-old-provider\", identity.provider, model)","handlingStrategy":"validation","validationCode":"let config: Config = toml::from_str(&doc.to_string())?;\nlet identity = config.resolve_provider_pin_identity(provider_identity)?;\nif identity.provider != provider {\n    eprintln!(\"identity {} pins {:?}, not {:?}\", provider_identity, identity.provider, provider);\n}","typeGuard":"fn identity_matches(config: &Config, provider_identity: &str, provider: ApiProvider) -> bool {\n    config.resolve_provider_pin_identity(provider_identity)\n        .map(|i| i.provider == provider)\n        .unwrap_or(false)\n}","tryCatchPattern":"match persist_provider_model_key(&path, provider, identity, model) {\n    Err(e) if e.to_string().contains(\"different provider identity\") => re_resolved_identity_retry(),\n    other => other?,\n}","preventionTips":["Always resolve provider identity from the freshly loaded config, never from cached UI state.","Re-read config.toml immediately before writing to avoid concurrent-edit drift.","Avoid hand-editing provider pins while a switch flow is in progress."],"tags":["config","rust","provider-identity","toml"],"backgroundTag":"type-mismatch","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}