fix: models loader no longer fails every request when models.dev is unreachable
RA
2d ago+331+331+012345678901234567890123456789-19-19-01234567890123456789
Issue for this PR
Closes #1862
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
With no models cache and models.dev unreachable (a fresh install on a restricted network), serve failed every chat request. Core's models loader died on the failed fetch, and plugin boot, agent state and every prompt wait on it.
- Release builds: core's loader now gets the catalogue the build already ships for the fork's loader. Both server entry points (
index.tsand the TUI worker) pass it in throughprovideSnapshot. Offline with no cache, the user gets the full model list from the build and chat works. The background refresh replaces it once models.dev answers. - No bundled catalogue (dev runs): a failed fetch gives an empty catalogue instead of dying. So does a body that isn't a catalogue, such as a proxy's HTML or
{"error": ...}. The server works, with no models.dev providers listed until a refresh succeeds. - Only catalogues are cached. A body is checked before it's written, a cache file that isn't a catalogue is dropped, and a fetched catalogue is still served if the cache can't be written.
Limits
- No size cost. Both binaries are 312.9MB. A build-time define (
OPENCODE_MODELS_DEV) would add 17.7MB per binary (2.3MB gzipped), because the two bundles can't share a copy. - The bundled catalogue is as of the build, as for the fork's loader.
- Without one, the empty catalogue lasts until a refresh succeeds, which runs hourly after the startup attempt.
How did you verify your code works?
--singlelinux-x64 binaries, run with models.dev on a closed port and empty home and cache folders. Main and the released 0.12.12:GET /agentreturns 500. This branch: 200, and only the background refresh tried models.dev.- The new core tests cover failed fetches, non-catalogue bodies and cache files, malformed entries, an unwritable cache, and host loaders that reject or throw. They fail on main and pass here, 19 of 19. An opencode test shows the entry module hands core the catalogue: 0 providers without the module.
- Typecheck in core and opencode, and the marker guard. The TUI itself wasn't run.
location-layer.test.ts"isolates location state…" times out on main too.
Cost side effects
None: no model calls, queries or cloud resources, and no change to binary size (see Limits).
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
Codex review log: https://github.com/AltimateAI/altimate-code/pull/1864#issuecomment-7271036224
🤖 Generated with Claude Code
https://claude.ai/code/session_01BXxzvsr1G2qqFbMCyPZg3G
Summary by CodeRabbit
- New Features
- Model listings can use a bundled catalogue when live fetching is unavailable.
- Bug Fixes
- Failed catalogue requests and invalid responses no longer interrupt model loading.
- Invalid fetched data is not cached, and a failed cache write does not prevent valid fetched data from being used.
- Invalid default-cache data is discarded, while valid cached data is preserved when a refresh fails.