fix(core): fall back to an empty catalog when models.dev is unreachable - #48002
Open
Luan-Fuzi wants to merge 2 commits into
Open
fix(core): fall back to an empty catalog when models.dev is unreachable#48002Luan-Fuzi wants to merge 2 commits into
Luan-Fuzi wants to merge 2 commits into
Conversation
Bootstrap must not die when the catalog fetch fails on first run (no cache on disk, models.dev times out or is dropped on restricted networks): serve an empty catalog like OPENCODE_DISABLE_MODELS_FETCH and let the background refresh recover it. Dying here (Effect.orDie on ModelsDev.populate) takes the whole server down and cascades into the desktop UI failing to load sessions, models, and projects. Fixes anomalyco#47328
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 #47328
Related to #35294, #35090, #34730, #47677
Type of change
What does this PR do?
On first run with no cached catalog,
ModelsDev.populate()ends withEffect.orDie. If the fetch fails (10s timeout on networks that silentlydrop packets — corporate VPNs, restricted networks), the service dies
during bootstrap and takes the whole server down: the desktop UI then
fails to load sessions, models, and projects (the cascade in #47328).
The same defect kills the CLI —
opencode modelsexits with anunhandled
TimeoutErrordefect on a cold start against an unreachablemodels.dev.
This changes the failure branch to log and serve an empty catalog — the
same behavior as
OPENCODE_DISABLE_MODELS_FETCH=1— so bootstrapcompletes and the existing background refresh recovers the catalog once
the network is reachable. The Flock is untouched; it still guards the
cross-process cache write, and
Effect.scopedstill releases it whenthe fetch fails.
How did you verify your code works?
packages/core/test/models.test.ts: disk empty + fetchfails (HTTP 500, and a transport-level error) →
get()resolves with{}instead of dying; after the fallback,refresh(true)against ahealthy endpoint recovers the full catalog and writes the cache file.
OPENCODE_MODELS_URLpointed at alocal server that accepts connections but never responds (equivalent
to silent packet drop),
OPENCODE_MODELS_PATHat a missing file (nocache). Before this change: the core script dies with a
TimeoutErrordefect, and
opencode modelsexits 1 withError: Unexpected error / TimeoutError. After:get()returns an empty catalog after the 10stimeout with an error logged, and
opencode modelsexits 0 with anempty list.
bun testin packages/core: 1100 pass, 0 fail. Typecheck (core andopencode packages) and prettier clean.
Checklist