Skip to content

fix(v2): avoid empty catalog during discovery refresh (refs #159) - #160

Merged
yuhp merged 1 commit into
devfrom
fix/issue-159-cache-refresh-availability
Oct 18, 2026
Merged

yuhp merged 1 commit into
devfrom
fix/issue-159-cache-refresh-availability

Conversation

@yuhp

@yuhp yuhp commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses #159 where model discovery refresh or cache expiration caused first requests to transiently return 404 (Model not found).

Root Cause

refreshFromCurrentConfig() previously invoked await ctx.provider.reload() unconditionally at the beginning of every refresh. In OpenCode V2, provider.reload() immediately causes the host to recalculate provider/model transforms. During normal discovery and cache expiration refreshes, invoking this before the upstream /v1/models HTTP request completes placed the model registry in a transient empty/transition state while the network request was in-flight, leading to a temporary 404 window.

Changes

  • Introduced reloadProviderConfig (defaults to false) in refreshFromCurrentConfig():
    • Normal discovery / cache refresh: skips the upfront ctx.provider.reload(). Existing models remain fully available while background network discovery runs, and replaceInventory() atomically materializes newly discovered models once ready.
    • Configuration / Credential events (config.updated, credential.*): explicitly passes reloadProviderConfig = true to ensure the host provider registry is synchronized before discovering models.
  • Added unit test in test/v2/plugin.test.ts verifying that provider catalog reloads are deferred until model discovery completes.

Related to #159 (closes #159).

@yuhp
yuhp merged commit 624a3bf into dev Oct 18, 2026
1 check passed
@yuhp
yuhp deleted the fix/issue-159-cache-refresh-availability branch October 18, 2026 13:46
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.

Cache refresh makes 404 of models in first request

1 participant