Fix BYOK models startup race#319190
Draft
dmitrivMS wants to merge 1 commit into
Draft
Conversation
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
Contributor
There was a problem hiding this comment.
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
whenReadytoILanguageModelsConfigurationServiceto signal completion of the first config-file load. - Updated
HasByokModelsContributionto defer persistingfalseuntil 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(); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #319121
HasByokModelsContributioncould persistchat.hasByokModels.lastKnown = falseduring cold start becauseLanguageModelsConfigurationServiceloads the BYOK JSON asynchronously: when extensions registered before the file read finished,getLanguageModelsProviderGroups()returned[]and we wrotefalse, flickering BYOK-gated UI (e.g. the Copilot signed-out placeholder) until the next config-change event.Fix: add
whenReadytoILanguageModelsConfigurationService(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; thechatNonCopilotModelsAreUserSelectablesignal 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.