diff --git a/packages/core/src/plugin/provider/opencode.ts b/packages/core/src/plugin/provider/opencode.ts index 020c4ed7db9..c3beee70820 100644 --- a/packages/core/src/plugin/provider/opencode.ts +++ b/packages/core/src/plugin/provider/opencode.ts @@ -6,6 +6,7 @@ import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } fr import { Bus } from "../../bus.js" import { Credential } from "../../credential.js" import { Integration } from "../../integration.js" +import { IntegrationConnection } from "../../integration/connection.js" import { Provider } from "../../provider.js" import { WebSearch } from "../../websearch.js" import { ConfigProvider } from "@opencode/schema/config/provider" @@ -131,7 +132,13 @@ export const OpencodePlugin = define - Effect.logWarning("failed to load OpenCode provider config", { cause }).pipe(Effect.as(undefined)), + Effect.logWarning("failed to load OpenCode provider config", { cause }).pipe( + Effect.as( + IntegrationConnection.key(snapshot.connection) === IntegrationConnection.key(connection) + ? snapshot.config + : undefined, + ), + ), ), ) : undefined diff --git a/packages/core/test/plugin/provider-opencode.test.ts b/packages/core/test/plugin/provider-opencode.test.ts index 4a65361a2dd..2b8888e7cbf 100644 --- a/packages/core/test/plugin/provider-opencode.test.ts +++ b/packages/core/test/plugin/provider-opencode.test.ts @@ -550,14 +550,15 @@ describe("OpencodePlugin", () => { ), ) - it.effect("refreshes hosted search with Console config and skips unchanged snapshots", () => + it.effect("refreshes hosted search with Console config, retains it on failure, and skips unchanged snapshots", () => Effect.acquireUseRelease( Effect.sync(() => { - const state = { advertised: false, requests: 0 } + const state = { advertised: false, failing: false, requests: 0 } const server = Bun.serve({ port: 0, fetch: () => { state.requests++ + if (state.failing) return new Response("Unavailable", { status: 502 }) return Response.json({ providers: {}, ...(state.advertised ? { websearch: { providerID: "opencode" } } : {}), @@ -607,10 +608,18 @@ describe("OpencodePlugin", () => { expect(rebuilds).toEqual({ provider: initial.provider + 1, websearch: initial.websearch + 1 }) expect(yield* websearch.default()).toEqual({ id: WebSearch.ID.make("opencode"), name: "OpenCode Web Search" }) - state.advertised = false + state.failing = true yield* TestClock.adjust("1 minute") yield* drain expect(state.requests).toBe(4) + expect(rebuilds).toEqual({ provider: initial.provider + 1, websearch: initial.websearch + 1 }) + expect(yield* websearch.default()).toEqual({ id: WebSearch.ID.make("opencode"), name: "OpenCode Web Search" }) + + state.failing = false + state.advertised = false + yield* TestClock.adjust("1 minute") + yield* drain + expect(state.requests).toBe(5) expect(rebuilds).toEqual({ provider: initial.provider + 2, websearch: initial.websearch + 2 }) expect(yield* websearch.providers()).toEqual([]) expect(yield* websearch.default()).toBeUndefined()