Skip to content

fix(models): retry a cold catalogue and never cache it empty - #4

Merged
dinhdev666 merged 2 commits into
mainfrom
fix/model-catalog-startup
Dec 2, 2026
Merged

dinhdev666 merged 2 commits into
mainfrom
fix/model-catalog-startup

Conversation

@dinhdev666

Copy link
Copy Markdown
Owner

Root cause

curl ... "model":"opencode/deepseek-v4.1-flash-free" answered
404 model_not_found, but the model exists. A freshly spawned
opencode serve reports readiness before its providers are registered, so the
gateway's first GET /api/model returned data: [] (observed against
opencode 2.4.3, agents already came back). ModelRegistry cached that empty
catalogue for OPENCODE_MODEL_CACHE_TTL_MS, so every request failed for the
next five minutes; GET /v1/models?refresh=true returned all 10 models.

Fix

  • Retry an empty model list the same way an empty agent list was already
    retried (both lists are now retried together, at most ~1 s).
  • Never cache a catalogue that has no models, so the next request picks them up
    as soon as the provider registers them.

Verification

  • New registry tests: "retries the model list when a cold server reports none"
    and "does not cache an empty catalogue" both fail without the fix.
  • pnpm typecheck, pnpm build, pnpm test — 217 passed (15 files).
  • Live cold start (node dist/index.js, opencode 2.4.3): the first
    GET /v1/models without ?refresh returns 10 models, including
    opencode/deepseek-v4.1-flash-free; the reported chat request now reaches the
    upstream and answers the expected 429 provider.free-limit (quota, not a
    gateway defect).

Also documents the behaviour and adds a troubleshooting row, and records that
opencode 2.4.3 was re-verified.

Closes the reported model_not_found failure.

A freshly spawned `opencode serve` answers `/api/model` with an empty
list for a moment after it reports readiness. The gateway cached that
answer for OPENCODE_MODEL_CACHE_TTL_MS, so for the next five minutes
every request failed with `404 model_not_found` for models that do
exist; only `GET /v1/models?refresh=true` recovered (observed against
opencode 2.4.3).

Retry an empty model list the way an empty agent list was already
retried, and leave the catalogue uncached while it holds no models, so
the next request picks them up as soon as the provider registers them.
Record that the catalogue is retried and never cached empty, that
opencode 2.4.3 was re-verified (spawn output, /api/model, /api/provider,
/api/agent and the model ids are unchanged), and add the matching
troubleshooting row for a 404 model_not_found right after startup.
@dinhdev666
dinhdev666 merged commit 7109be9 into main Dec 2, 2026
3 checks passed
@dinhdev666
dinhdev666 deleted the fix/model-catalog-startup branch December 2, 2026 15:57
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.

1 participant