Skip to content

Fix stale BYOK model selection after vendor resolves with zero models#318424

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-byok-ui-last-model-selection
Draft

Fix stale BYOK model selection after vendor resolves with zero models#318424
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-byok-ui-last-model-selection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

After removing BYOK models and reloading, the chat picker button kept displaying the previously selected BYOK model (e.g. "Claude Haiku 4.5") while the dropdown only listed "Auto".

Root cause

The chat input bridges the startup race by retaining cached models for vendors that haven't resolved yet (mergeModelsWithCache), keying eviction on hasResolvedVendor. When a BYOK vendor later resolves with zero model groups (key/config removed), _modelsGroups.set(vendor, []) flips hasResolvedVendor from falsetrue, but _resolveAllLanguageModels did not fire onDidChangeLanguageModels because both the old and new model/group lists were empty. Consumers silently evicted the cached BYOK model from their merged view, yet resetCurrentLanguageModelIfUnavailable never ran, so _currentLanguageModel kept pointing at the now-unavailable model.

Changes

  • src/vs/workbench/contrib/chat/common/languageModels.ts: treat the first resolution of a vendor as a change, so the event always fires on the unresolved → resolved transition. The existing reset handler then falls back to the default model in the list (per the agent instruction on the issue).

    const wasUnresolved = !this._modelsGroups.has(vendorId);
    const oldGroups = this._modelsGroups.get(vendorId) ?? [];
    this._modelsGroups.set(vendorId, languageModelsGroups);
    const oldModels = this._clearModelCache(vendorId);
    let hasChanges = wasUnresolved;
  • src/vs/workbench/contrib/chat/test/common/languageModels.test.ts: regression test "fires onChange event when a vendor first resolves with zero models".

Copilot AI requested review from Copilot and removed request for Copilot May 26, 2026 19:56
Co-authored-by: vritant24 <13074644+vritant24@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 26, 2026 20:21
Copilot AI changed the title [WIP] Fix BYOK UI not resetting last model selection Fix stale BYOK model selection after vendor resolves with zero models May 26, 2026
Copilot AI requested a review from vritant24 May 26, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BYOK UI: Last model should not be selected after removing BYOK models

2 participants