From d990969a7e4fe47e32168d6e85b7f65e01575627 Mon Sep 17 00:00:00 2001 From: OpenCode Bot Date: Thu, 12 Feb 2026 16:19:50 +0800 Subject: [PATCH] fix(installation): timeout package manager probes on startup --- packages/opencode/src/installation/index.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/opencode/src/installation/index.ts b/packages/opencode/src/installation/index.ts index 47278bd5628..7015c23fb5d 100644 --- a/packages/opencode/src/installation/index.ts +++ b/packages/opencode/src/installation/index.ts @@ -6,6 +6,7 @@ import { NamedError } from "@opencode-ai/util/error" import { Log } from "../util/log" import { iife } from "@/util/iife" import { Flag } from "../flag/flag" +import { withTimeout } from "@/util/timeout" declare global { const OPENCODE_VERSION: string @@ -14,6 +15,7 @@ declare global { export namespace Installation { const log = Log.create({ service: "installation" }) + const TIMEOUT = 5000 export type Method = Awaited> @@ -102,7 +104,13 @@ export namespace Installation { }) for (const check of checks) { - const output = await check.command() + const output = await withTimeout(check.command(), TIMEOUT).catch((error) => { + log.warn("package manager check failed", { + name: check.name, + error: error instanceof Error ? error.message : String(error), + }) + return "" + }) const installedName = check.name === "brew" || check.name === "choco" || check.name === "scoop" ? "opencode" : "opencode-ai" if (output.includes(installedName)) { @@ -215,8 +223,14 @@ export namespace Installation { if (detectedMethod === "npm" || detectedMethod === "bun" || detectedMethod === "pnpm") { const registry = await iife(async () => { - const r = (await $`npm config get registry`.quiet().nothrow().text()).trim() - const reg = r || "https://registry.npmjs.org" + const reg = ( + await withTimeout($`npm config get registry`.quiet().nothrow().text(), TIMEOUT).catch((error) => { + log.warn("npm registry check failed", { + error: error instanceof Error ? error.message : String(error), + }) + return "" + }) + ).trim() || "https://registry.npmjs.org" return reg.endsWith("/") ? reg.slice(0, -1) : reg }) const channel = CHANNEL