Skip to content

fix(provider): keep configured provider connected when directory is unavailable - #513

Open
rookie136 wants to merge 1 commit into
tickernelz:mainfrom
rookie136:fix/provider-directory-fallback
Open

rookie136 wants to merge 1 commit into
tickernelz:mainfrom
rookie136:fix/provider-directory-fallback

Conversation

@rookie136

Copy link
Copy Markdown
Contributor

Problem

On OpenCode V2 (0.0.0-beta-19271), the plugin context does not expose the provider domain (the runtime exposes catalog instead). refreshConnectedProviders() calls ctx.client.provider.list(), which throws:

TypeError: undefined is not an object (evaluating 'ctx.provider.list')

Because the error path leaves _connectedProviders empty, ensureProviderConnected() denies providers that are actually configured and authenticated. Every internal structured-output call (auto-capture, profile learning, dedup, description evolution, AI cleanup) then throws provider '<id>' is not connected and falls back to the external API (memoryApiUrl).

In our setup that fallback path is non-streaming and sends large prompts, so the gateway holds the request until its 600s limit and returns HTTP 504 (observed: status_code=504, duration 9m59s, request type 非流).

Fix

When the provider directory refresh fails, seed the connectivity snapshot with the explicitly configured opencodeProvider:

} catch (error) {
  log("Failed to refresh opencode provider state", { error: String(error) });
  if (CONFIG.opencodeProvider) {
    const { setConnectedProviders } = await loadOpencodeProvider();
    setConnectedProviders([CONFIG.opencodeProvider]);
  }
}

If the configured id is wrong, the structured-output call still fails loudly and the existing external fallback applies, so this does not hide misconfiguration. No behavior change when the host provider directory is available.

Verification

  • bunx tsc --noEmit passes; pre-commit hooks (prettier/eslint) pass.
  • With opencodeProvider: "bs-aigw" + opencodeModel: "DeepSeek-V4-Flash" on V2 beta-19271:
    • auto-capture and profile learning complete through the host ctx.generate.text() path
    • plugin log: 0 external fallbacks, 0 API request timeout (60000ms), 0 provider is not connected after restart
  • Gateway request log changed from non-stream 504 (599s) to streaming (first token 2.8s, total 7.0s).

Note

A longer-term fix could read provider connectivity from ctx.catalog once its API is stable; this change only makes the connectivity snapshot resilient when the provider directory is unavailable.

…navailable

Some plugin contexts (notably the V2 host) do not expose the provider directory, so refreshing the connectivity snapshot throws and ensureProviderConnected() denies providers that are actually configured. Fall back to the explicitly configured opencodeProvider so internal structured-output calls are still attempted; an invalid provider id still fails on the call and falls back to the external API.
@rookie136
rookie136 force-pushed the fix/provider-directory-fallback branch from a654604 to a756c60 Compare November 19, 2026 13:45

This branch has not been deployed

No deployments
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