From dd72edf5ea12322a60327420900fab18bb1c8209 Mon Sep 17 00:00:00 2001 From: Lindy Xu Date: Mon, 24 Aug 2026 13:51:03 +0800 Subject: [PATCH] feat: show warning toast when opencode provider fails but fallback is configured When the opencode provider throws and a manual external API fallback is configured, the error was previously only logged. The user had no indication that their primary provider was broken and memory capture was silently using the fallback. This adds a non-blocking warning toast (5s, variant 'warning') informing the user that the opencode provider failed and the fallback is being used. The original provider error is included (truncated to 100 chars) for debugging. The toast only fires when showErrorToasts is enabled and does not block capture. Follow-up from #259 review by NaNomicon. --- src/services/auto-capture.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/services/auto-capture.ts b/src/services/auto-capture.ts index cc090f5..e79b245 100644 --- a/src/services/auto-capture.ts +++ b/src/services/auto-capture.ts @@ -107,7 +107,7 @@ async function capturePrompt( let summaryResult: { summary: string; type: string; tags: string[] } | null; try { - summaryResult = await generateSummary(context, sessionID, prompt.content, prompt); + summaryResult = await generateSummary(ctx, context, sessionID, prompt.content, prompt); } catch (error) { const message = error instanceof Error ? error.message : String(error); throw new Error(`Summary generation failed: ${message}`); @@ -479,6 +479,7 @@ export function buildMarkdownContext( } async function generateSummary( + ctx: PluginInput, context: string, sessionID: string, userPrompt: string, @@ -589,6 +590,26 @@ CAPTURE if: code changed, bug fixed, feature added, decision made`; throw new Error("External API not configured for auto-capture"); } + // Opencode provider failed but a manual fallback is configured — surface a + // non-blocking warning so the user knows their primary provider is broken. + if (opencodeProviderError && CONFIG.showErrorToasts) { + const errMsg = + opencodeProviderError instanceof Error + ? opencodeProviderError.message + : String(opencodeProviderError); + const shortReason = errMsg.length > 100 ? errMsg.substring(0, 100) + "..." : errMsg; + ctx.client?.tui + .showToast({ + body: { + title: "Using fallback provider", + message: `OpenCode provider failed (${shortReason}); using configured fallback.`, + variant: "warning", + duration: 5000, + }, + }) + .catch(() => {}); + } + const { AIProviderFactory } = await import("./ai/ai-provider-factory.js"); const { buildMemoryProviderConfig } = await import("./ai/provider-config.js"); const { detectLanguage, getLanguageName } = await import("./language-detector.js");