Skip to content

fix(provider): await models.dev refresh before computing provider state#15609

Open
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Br1an67:fix/issue-8587-model-id-format
Open

fix(provider): await models.dev refresh before computing provider state#15609
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Br1an67:fix/issue-8587-model-id-format

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Issue for this PR

Closes #8587

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

ModelsDev.refresh() fires at module load (fire-and-forget) but Provider.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() throws ProviderModelNotFoundError.

This fix tracks the initial refresh promise via startRefresh() and awaits it in Provider.state() initialization through ensureFresh(). 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?

  • Traced the race: Data() resolves from snapshot → state() computes → refresh() completes and resets Data too late
  • Confirmed remeda.mergeDeep preserves shared references (nested objects not in the merge source keep the same ref), so Data.reset() after state() has resolved doesn't help
  • Ran provider and tool tests — no regressions (pre-existing bash permission failures unrelated)

Screenshots / recordings

N/A — backend fix

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
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.

OpenCode Zen GPT-5.2 Codex install model fails (ProviderModelNotFoundError)

1 participant