fix(provider): await models.dev refresh before computing provider state#15609
Open
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Open
fix(provider): await models.dev refresh before computing provider state#15609Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Conversation
The provider state initialization could use a stale bundled snapshot when the background models.dev refresh hadn't completed yet. This caused ProviderModelNotFoundError for models that exist in models.dev but not in the snapshot. Track the initial refresh promise via startRefresh() and await it in ensureFresh() before computing provider state. If the refresh fails or was never started, ensureFresh() is a no-op.
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.
Issue for this PR
Closes #8587
Type of change
What does this PR do?
ModelsDev.refresh()fires at module load (fire-and-forget) butProvider.state()can resolve from the bundled snapshot before the refresh completes. When a model exists in live models.dev but not in the snapshot,getModel()throwsProviderModelNotFoundError.This fix tracks the initial refresh promise via
startRefresh()and awaits it inProvider.state()initialization throughensureFresh(). If the refresh fails or was never started (e.g.OPENCODE_DISABLE_MODELS_FETCH), the await is a no-op and falls through to the snapshot as before.How did you verify your code works?
Data()resolves from snapshot →state()computes →refresh()completes and resetsDatatoo lateremeda.mergeDeeppreserves shared references (nested objects not in the merge source keep the same ref), soData.reset()afterstate()has resolved doesn't helpScreenshots / recordings
N/A — backend fix
Checklist