From 1c7eb55f9cfa5e16f51f2984cad6ffbaf9c0e3b1 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 21 Feb 2026 18:32:10 +0900 Subject: [PATCH] fix(hooks): use model cache availability with timeout for first-run cache creation Replace fire-and-forget pattern with await + 10s timeout for initial cache creation. Check model cache availability (not connected providers) to properly coordinate with model-cache-warning hook. Remove non-null assertion and add proper error logging. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- .../hook/connected-providers-status.ts | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/hooks/auto-update-checker/hook/connected-providers-status.ts b/src/hooks/auto-update-checker/hook/connected-providers-status.ts index 4eaf4225..d7e09784 100644 --- a/src/hooks/auto-update-checker/hook/connected-providers-status.ts +++ b/src/hooks/auto-update-checker/hook/connected-providers-status.ts @@ -1,29 +1,48 @@ import type { PluginInput } from "@opencode-ai/plugin" -import { - hasConnectedProvidersCache, - updateConnectedProvidersCache, -} from "../../../shared/connected-providers-cache" +import { updateConnectedProvidersCache } from "../../../shared/connected-providers-cache" +import { isModelCacheAvailable } from "../../../shared/model-availability" import { log } from "../../../shared/logger" -export async function updateAndShowConnectedProvidersCacheStatus(ctx: PluginInput): Promise { - const hadCache = hasConnectedProvidersCache() +const CACHE_UPDATE_TIMEOUT_MS = 10000 - updateConnectedProvidersCache(ctx.client).catch(() => {}) +export async function updateAndShowConnectedProvidersCacheStatus(ctx: PluginInput): Promise { + const hadCache = isModelCacheAvailable() if (!hadCache) { - await ctx.client.tui - .showToast({ - body: { - title: "Connected Providers Cache", - message: "Building provider cache for first time. Restart OpenCode for full model filtering.", - variant: "info" as const, - duration: 8000, - }, - }) - .catch(() => {}) + let timeoutId: ReturnType | undefined + try { + await Promise.race([ + updateConnectedProvidersCache(ctx.client), + new Promise((_, reject) => { + timeoutId = setTimeout(() => reject(new Error("Cache update timed out")), CACHE_UPDATE_TIMEOUT_MS) + }), + ]) + } catch (err) { + log("[auto-update-checker] Connected providers cache creation failed", { error: String(err) }) + } finally { + if (timeoutId) clearTimeout(timeoutId) + } - log("[auto-update-checker] Connected providers cache toast shown (first run)") + if (!isModelCacheAvailable()) { + await ctx.client.tui + .showToast({ + body: { + title: "Connected Providers Cache", + message: "Failed to build provider cache. Restart OpenCode to retry.", + variant: "warning" as const, + duration: 8000, + }, + }) + .catch(() => {}) + + log("[auto-update-checker] Connected providers cache toast shown (creation failed)") + } else { + log("[auto-update-checker] Connected providers cache created on first run") + } } else { + updateConnectedProvidersCache(ctx.client).catch((err) => { + log("[auto-update-checker] Background cache update failed", { error: String(err) }) + }) log("[auto-update-checker] Connected providers cache exists, updating in background") } }