Skip to content

Fix BYOK models startup race#319190

Draft
dmitrivMS wants to merge 1 commit into
mainfrom
dev/dmitriv/fix-byok-models-startup-race
Draft

Fix BYOK models startup race#319190
dmitrivMS wants to merge 1 commit into
mainfrom
dev/dmitriv/fix-byok-models-startup-race

Conversation

@dmitrivMS
Copy link
Copy Markdown
Contributor

Fixes #319121

HasByokModelsContribution could persist chat.hasByokModels.lastKnown = false during cold start because LanguageModelsConfigurationService loads the BYOK JSON asynchronously: when extensions registered before the file read finished, getLanguageModelsProviderGroups() returned [] and we wrote false, flickering BYOK-gated UI (e.g. the Copilot signed-out placeholder) until the next config-change event.

Fix: add whenReady to ILanguageModelsConfigurationService (resolved after the first config-file load) and only persist a negative result once both extension scan and the first config load have completed. Configured non-Copilot groups remain authoritative-positive; the chatNonCopilotModelsAreUserSelectable signal stays trusted only pre-registration (preserves the #318187 invariant that the signal can be stale after group removal).

Tests: added a regression test for #319121 (persisted true survives while config load is pending) and one for the cleared-on-load-complete case. All 14 tests in the suite pass.

Persisted hasByokModels=true could be clobbered with false during cold start because LanguageModelsConfigurationService loads its JSON asynchronously. Gate the negative result on a new whenReady signal so a previously-true value survives until the config has actually loaded.

Fixes #319121
Copilot AI review requested due to automatic review settings May 31, 2026 06:56
@dmitrivMS dmitrivMS self-assigned this May 31, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a cold-start race where BYOK state could be persisted as false before the BYOK configuration file finished loading, causing BYOK-gated UI to flicker until the next config update. This adds an explicit “configuration loaded at least once” readiness signal and updates the BYOK state contribution to avoid persisting a negative result until startup signals have settled.

Changes:

  • Added whenReady to ILanguageModelsConfigurationService to signal completion of the first config-file load.
  • Updated HasByokModelsContribution to defer persisting false until both extension registration and initial config load complete, while treating configured non-Copilot groups as an always-positive signal.
  • Added regression tests covering “persisted true survives while config load is pending” and “cleared once config load completes with no BYOK groups”.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/test/browser/hasByokModelsContribution.test.ts Adds regression tests modeling deferred config readiness and verifying persistence behavior.
src/vs/workbench/contrib/chat/common/languageModelsConfiguration.ts Extends the configuration service contract with whenReady to distinguish “empty” from “not yet loaded”.
src/vs/workbench/contrib/chat/browser/languageModelsConfigurationService.ts Implements whenReady by capturing the initial async config load.
src/vs/workbench/contrib/chat/browser/hasByokModelsContribution.ts Uses whenReady + extension registration to avoid persisting a premature negative BYOK result on startup.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 3

Comment on lines +27 to +31
* 1. Restore the last persisted answer for correct warm-reload UI.
* 2. Configured non-Copilot vendor groups are a positive signal at any time.
* 3. Pre-registration only, also trust the `chatNonCopilotModelsAreUserSelectable` signal
* (post-registration it can be stale — model cache lags behind group removal).
* 4. Only persist `false` after both extension scan and first config load complete, so startup
Comment on lines 60 to 64
this.modelsConfigurationFile = userDataProfileService.currentProfile.languageModelsResource;
this.updateLanguageModelsConfiguration();
this._whenReady = this.updateLanguageModelsConfiguration();
// Watch the parent folder for reliable change detection across platforms (especially Windows
// where `fs.watch` on individual files can miss in-place writes).
this._register(fileService.watch(uriIdentityService.extUri.dirname(this.modelsConfigurationFile)));
Comment on lines +72 to +77
this._languageModelsConfigurationService.whenReady.then(() => {
if (!this._store.isDisposed) {
this._configurationLoaded = true;
this._update();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Endpoint (BYOK) models disappear from model picker on VS Code restart - hasByokModels.lastKnown race condition

2 participants