Repository navigation
Description
Bug description
Switching models with /model <model> (or switching provider+model through the picker) fails with an auth/credential error for any provider whose saved profile name differs from its catalog ID — e.g. you set up OpenAI but named the profile my-openai. The provider was working a moment earlier; the switch itself is what breaks it.
Root cause
normalizeProfileForProvider (internal/tui/picker.go) rewrites the profile identity when normalizeIdentity is true:
normalizeIdentity := profileMatchesProviderBaseURL(profile, provider) || ...
if normalizeIdentity {
profile.Name = provider.ID // <-- clobbers the user's profile name
profile.CatalogID = provider.ID
}profileMatchesProviderBaseURL is true whenever the saved BaseURL equals the catalog default — which is the case for essentially every first-party provider (openai/anthropic/google/…). So on /model switch, a profile named my-openai has its Name overwritten to openai.
The encrypted credential store is keyed by profile.Name (SecureProviderProfile does store.Set(Name, key); ApplyStoredAPIKey does store.Get(Name)). normalizeProfileForProvider runs before profileWithCredential, so the credential is then looked up under the rewritten name openai instead of my-openai → miss → empty APIKey → the rebuilt provider sends no key → 401.
Rewriting CatalogID is harmless (it's not the store key). Rewriting Name is the bug.
Reproduction
Confirmed with a focused unit repro against normalizeProfileForProvider:
- profile
{Name: "my-openai", CatalogID: "openai", BaseURL: <openai catalog default>, APIKeyStored: true} normalizeProfileForProvider(openai)returnsName: "openai"(rewritten frommy-openai).- The credstore key was
my-openai, sostore.Get("openai")misses and the profile comes back with noAPIKey.
End-user steps:
- Configure a provider with a profile name different from the catalog id (e.g. name it
my-openai), authenticate so the key is saved to the credential store. - In the TUI, run
/model <some-model>. - The switch reports a credential/auth error even though the same provider was working before the switch.
Expected behavior
/model switching must preserve the profile's real Name so the credential store resolves the saved key. Switching the model on an already-authenticated provider should never drop its credential.
Fix direction
In normalizeProfileForProvider, only set profile.Name when it is actually empty (or a generic custom-* placeholder) — never overwrite a legitimate user-provided name. CatalogID normalization can stay. A regression test should cover a custom-named first-party profile surviving a /model switch with its stored credential intact.
Notes
- Distinct from no active provider marked forces full re-onboarding instead of using an already-configured provider #409 (
no active provider forces full re-onboarding), which is a startup-resolution bug; fix(config): fall back to a usable saved provider instead of forcing full re-onboarding #410 fixes that and does not touch this path. - No fix PR is currently open for this.
Activity
Vasanthdev2004 commentedon Jul 3, 2026
Claiming this — root cause is confirmed (reproduced against
normalizeProfileForProviderlocally), and no existing PR covers it (#410 is the separate startup no-active-provider case). Fix PR incoming: stop clobbering a real profileNameduring/modelnormalization so the credential store resolves the saved key, with a regression test for a custom-named first-party profile surviving a model switch.fix(tui): keep the profile name on /model switch so the stored key re…