fix: allow correcting API key after entering an invalid one for xAI/Gemini#11854
Conversation
… re-adding When a user enters an invalid API key for a provider (e.g. xAI or Gemini) and later tries to add the same model again with a correct key, the addModel function previously either skipped (exact match) or created a duplicate with a numbered suffix. Now it detects models with the same provider and model name and updates the existing entry in-place, allowing users to correct their API key by re-adding the model. Closes #9995
|
Docs Review: No documentation updates needed. This PR is an internal bug fix to the |
…f appending duplicates When re-entering an API key through the onboarding flow, setupProviderConfig previously appended new model entries without removing the old ones with the invalid key. Now it filters out existing models with the same hub slug before adding the new ones, ensuring the user ends up with a single set of correctly-configured models.
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="core/config/onboarding.ts">
<violation number="1" location="core/config/onboarding.ts:107">
P2: Filtering out existing `uses` entries and re-adding `newModels` will discard any extra configuration fields on those models (e.g., roles or options). To update an API key without losing settings, merge into the existing model entry instead of replacing it.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Avoid overwriting user-customized fields (apiBase, completionOptions, title, etc.) when updating an existing model. Only the apiKey is changed.
…cating Address review feedback: update only the API key on existing model entries to preserve user-customized fields (roles, options, etc.). - setupProviderConfig: merge `with` into existing hub-slug models, only append entries for slugs not yet in config - addModel: narrow update to only set apiKey on matching provider+model
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="core/config/onboarding.ts">
<violation number="1" location="core/config/onboarding.ts:107">
P2: This update path preserves pre-existing duplicate `uses` entries instead of collapsing them, so users with legacy duplicated models will still keep duplicates after re-entering a key.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
The YAML config model type is a union that includes uses-based models without an apiKey property. Use 'provider' in m guard and cast to any for the assignment.
…keys in onboarding When a user tries to add a model that already exists (e.g. after entering an invalid API key), show a warning toast and open the config file so they can update the key directly. Also fix setupProviderConfig to merge API keys into existing models instead of creating duplicates. Closes #9995
Use 'uses' in m type guards to narrow the union type instead of casting to any.
Summary
When a user enters an invalid API key for a provider like xAI or Gemini, they get stuck — re-adding the same model silently creates a duplicate, and the onboarding flow appends new entries instead of updating existing ones.
Changes:
core.ts: When adding a model that already exists (same provider + model), show a warning toast and open the config file so the user can update their API key directlyonboarding.ts:setupProviderConfignow merges the new API key into existing hub-slug models instead of appending duplicates, preserving user-customized fields (roles, options, etc.)Closes #9995
Test plan