Transient Kilo model-catalog fetch failure silently removes the provider and breaks every model in a worktree
Description
Description
When the Kilo model-catalog fetch fails or returns empty, the kilo provider is silently removed from a worktree's provider list, and every Kilo model in that worktree then fails with a misleading Model not found: kilo/<model-id>. error. New sessions and forks inside that worktree stay broken regardless of which model is selected, while other worktrees keep working normally.
This affects Kilo organization accounts, because the models.dev fallback and the fetch retry are both skipped when an organization ID is present.
The error is not caused by an invalid model ID: the same model streams successfully in another worktree in the same backend process moments later, and the model is present in the gateway catalog.
Steps to reproduce
Deterministic (unit-level):
- Sign in with a Kilo account that has an organization (
auth.jsonentry forkilohas anaccountId). - Make the org-scoped Kilo catalog fetch return an empty result / error (e.g. take the process offline, or make
fetchKiloModelsreturn{ models: {}, error }). - In a directory whose provider state is built while the fetch is failing, request any Kilo model.
- Observe the failure below. A second directory whose provider state was built earlier still works; forking inside the affected directory also fails.
Observed (real-world):
- Long-running session in a worktree works normally on
kilo/deepseek/deepseek-v4.1-flash. - Machine goes idle for ~2.5h (overnight sleep) and a transient network failure occurs.
- Sending "continue" fails with
Model not found: kilo/deepseek/deepseek-v4.1-flash. - Switching the picker to a different model (
kilo/deepseek/deepseek-v4-pro-0813, thenkilo/moonshotai/kimi-k3) still fails, once per attempt. - Creating forks of the session also fails with the same class of error for whatever model is selected.
- Meanwhile the same model (
kilo/deepseek/deepseek-v4-pro-0813) streams successfully in a different worktree handled by the same backend process, and the model is present in the live gateway catalog.
Expected behavior
A transient catalog fetch failure should not remove the provider or permanently break a directory. At minimum, the error should say that the provider catalog failed to load, and the state should recover once the fetch succeeds.
Actual behavior
kilodisappears from the provider list for that directory.- Every Kilo model returns
Model not found: kilo/<model-id>. - Forks inherit the broken per-directory provider state, so they fail too.
- The state does not self-heal until the directory's provider state is invalidated (e.g. successful hourly models.dev refresh or a backend restart).
Error surfaced in the UI/logs:
Model not found: kilo/deepseek/deepseek-v4-pro-0813.
{
"name": "UnknownError",
"data": { "message": "Model not found: kilo/deepseek/deepseek-v4-pro-0813." }
}Backend log (redacted):
level=ERROR message="prompt_async failed" cause="Cause([Die(ProviderModelNotFoundError: Model not found: kilo/deepseek/deepseek-v4.1-flash.)])"
level=ERROR message="prompt_async failed" cause="Cause([Die(ProviderModelNotFoundError: Model not found: kilo/deepseek/deepseek-v4-pro-0813.)])"
level=ERROR message="prompt_async failed" cause="Cause([Die(ProviderModelNotFoundError: Model not found: kilo/moonshotai/kimi-k3.)])"Note the missing No models are currently available. hint — see root cause.
Environment
- Kilo Code VS Code extension
7.7.9(CLI backend bundled at the same version, tagv7.7.9) - Reported from the Agent Manager (VS Code), but the failure is in the CLI backend provider state
- OS: macOS
<version> - Kilo account type: organization
Root cause
The chain (line numbers from v7.7.9):
packages/opencode/src/kilocode/provider/catalog.ts—organization()returns the account's org from OAuthaccountId, soorgis set.packages/opencode/src/provider/model-cache.ts— the Kilo catalog is fetched org-scoped (fetch, ~L283). A failed fetch still gets committed and cached for the 5-minute TTL (~L211-225, L251-253); the empty result is only logged at debug/warn level.packages/opencode/src/provider/models.ts:88-99— becauseorgis set, the models.dev fallback is skipped, and the retry refresh is gated on!org:const models = !valid || org || Object.keys(fetched).length > 0 ? fetched : (fallback?.models ?? {}) ... if (valid && !org && Object.keys(fetched).length === 0) yield* cache.refresh("kilo", fetch)…So an empty fetch result becomes the provider's model list, with no fallback and no retry.
packages/opencode/src/provider/provider.ts:1780-1783— any provider with zero models is deleted:if (Object.keys(provider.models).length === 0) { delete providers[providerID] continue }packages/opencode/src/provider/provider.ts:1957-1969—getModeltakes the missing-provider branch and hardcodesmodelsEmpty = false(~L1967, akilocode_change), so the diagnostic hint is suppressed and the message is justModel not found: kilo/<id>.Provider state is per-directory
InstanceState(provider.ts:1428), so only the affected worktree is poisoned. It is rebuilt only whenModelsRefresh.notify()fires (provider.ts:1796,packages/opencode/src/kilocode/provider/models-refresh.ts) on a successful models.dev refresh, not when the 5-minute Kilo cache recovers — so it looks permanent.A fork runs in the same directory, so it inherits the poisoned state and
getModelfails for any selected model.
The trigger is a transient org-scoped catalog fetch failure; the bug is how the code handles that empty result (delete the provider + misleading error + no recovery).
Possible fix?
models.ts: whenorgis set andfetchedis empty, fall back tofallback.models(or otherwise avoid emitting an emptykiloprovider), and schedule a retry when the result is empty regardless oforg.provider.ts: don't silently delete providers with an empty model map, or at minimum make the error accurate — distinguish "unknown provider" from "provider catalog failed to load", and stop hardcodingmodelsEmpty = falseon the missing-provider branch.- Invalidate/rebuild provider state when
ModelCacherecovers, instead of waiting up to an hour for a models.dev refresh.
Workaround
Reload the VS Code window or restart the kilo serve backend. This disposes the per-directory Instances and rebuilds the provider state, which clears the poisoned entry. No files or sessions need to be deleted.
Related
- #14531 / commit
89f0cbad72("recover Agent Manager session recovery and model providers when the CLI backend reconnects during startup", shipped in 7.7.10) is adjacent but client-side (re-fetches providers for the picker); it does not fix the server-side "org + empty fetch → provider deleted → misleading ModelNotFound" path. - Behavior of skipping public-model fallbacks for org accounts was introduced in 7.5.10 (#13692).
Plugins
No response
Kilo version
Kilo v 7.7.3, VS Code Kilo Ext v 7.8.1
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
MacOS 26.3.1
Terminal
No response
Source: Kilo-Org/kilocode