Skip to content

fix(core): fall back to an empty catalog when models.dev is unreachable - #48002

Open
Luan-Fuzi wants to merge 2 commits into
anomalyco:devfrom
Luan-Fuzi:fix/models-dev-unreachable-fallback
Open

fix(core): fall back to an empty catalog when models.dev is unreachable#48002
Luan-Fuzi wants to merge 2 commits into
anomalyco:devfrom
Luan-Fuzi:fix/models-dev-unreachable-fallback

Conversation

@Luan-Fuzi

Copy link
Copy Markdown

Issue for this PR

Closes #47328
Related to #35294, #35090, #34730, #47677

Type of change

  • Bug fix

What does this PR do?

On first run with no cached catalog, ModelsDev.populate() ends with
Effect.orDie. If the fetch fails (10s timeout on networks that silently
drop 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 models exits with an
unhandled TimeoutError defect on a cold start against an unreachable
models.dev.

This changes the failure branch to log and serve an empty catalog — the
same behavior as OPENCODE_DISABLE_MODELS_FETCH=1 — so bootstrap
completes 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.scoped still releases it when
the fetch fails.

How did you verify your code works?

  • Unit tests in packages/core/test/models.test.ts: disk empty + fetch
    fails (HTTP 500, and a transport-level error) → get() resolves with
    {} instead of dying; after the fallback, refresh(true) against a
    healthy endpoint recovers the full catalog and writes the cache file.
  • Manual repro of the issue scenario: OPENCODE_MODELS_URL pointed at a
    local server that accepts connections but never responds (equivalent
    to silent packet drop), OPENCODE_MODELS_PATH at a missing file (no
    cache). Before this change: the core script dies with a TimeoutError
    defect, and opencode models exits 1 with Error: Unexpected error / TimeoutError. After: get() returns an empty catalog after the 10s
    timeout with an error logged, and opencode models exits 0 with an
    empty list.
  • bun test in packages/core: 1100 pass, 0 fail. Typecheck (core and
    opencode packages) and prettier clean.

Checklist

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

Luan-Fuzi and others added 2 commits September 9, 2026 01:03
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
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.

[desktop] Startup blocked up to 5 min by models.dev fetch under global Flock when network silently drops packets; UI never loads

1 participant