From a2c28fc8d733915af24f0d1945cef9c90c6d3e5f Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Wed, 4 Feb 2026 12:01:00 -0600 Subject: [PATCH] fix: ensure that plugin installs use --no-cache when using http proxy to prevent random hangs (see bun issue) (#12161) --- packages/opencode/src/bun/index.ts | 10 ++-------- packages/opencode/src/config/config.ts | 25 +++++++++++++++++++++---- packages/opencode/src/util/proxied.ts | 3 +++ 3 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 packages/opencode/src/util/proxied.ts diff --git a/packages/opencode/src/bun/index.ts b/packages/opencode/src/bun/index.ts index 19edb6eec..bdb7cff78 100644 --- a/packages/opencode/src/bun/index.ts +++ b/packages/opencode/src/bun/index.ts @@ -7,6 +7,7 @@ import { NamedError } from "@opencode-ai/util/error" import { readableStreamToText } from "bun" import { Lock } from "../util/lock" import { PackageRegistry } from "./registry" +import { proxied } from "@/util/proxied" export namespace BunProc { const log = Log.create({ service: "bun" }) @@ -86,20 +87,13 @@ export namespace BunProc { log.info("Cached version is outdated, proceeding with install", { pkg, cachedVersion }) } - const proxied = !!( - process.env.HTTP_PROXY || - process.env.HTTPS_PROXY || - process.env.http_proxy || - process.env.https_proxy - ) - // Build command arguments const args = [ "add", "--force", "--exact", // TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936) - ...(proxied ? ["--no-cache"] : []), + ...(proxied() ? ["--no-cache"] : []), "--cwd", Global.Path.cache, pkg + "@" + version, diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index 91816a00f..5fde2aed8 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -29,6 +29,7 @@ import { Bus } from "@/bus" import { GlobalBus } from "@/bus/global" import { Event } from "../server/event" import { PackageRegistry } from "@/bun/registry" +import { proxied } from "@/util/proxied" export namespace Config { const log = Log.create({ service: "config" }) @@ -247,13 +248,29 @@ export namespace Config { const hasGitIgnore = await Bun.file(gitignore).exists() if (!hasGitIgnore) await Bun.write(gitignore, ["node_modules", "package.json", "bun.lock", ".gitignore"].join("\n")) - await BunProc.run(["add", `@opencode-ai/plugin@${targetVersion}`, "--exact"], { - cwd: dir, - }).catch(() => {}) + await BunProc.run( + [ + "add", + `@opencode-ai/plugin@${targetVersion}`, + "--exact", + // TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936) + ...(proxied() ? ["--no-cache"] : []), + ], + { + cwd: dir, + }, + ).catch(() => {}) // Install any additional dependencies defined in the package.json // This allows local plugins and custom tools to use external packages - await BunProc.run(["install"], { cwd: dir }).catch(() => {}) + await BunProc.run( + [ + "install", + // TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936) + ...(proxied() ? ["--no-cache"] : []), + ], + { cwd: dir }, + ).catch(() => {}) } async function needsInstall(dir: string) { diff --git a/packages/opencode/src/util/proxied.ts b/packages/opencode/src/util/proxied.ts new file mode 100644 index 000000000..440a9ccce --- /dev/null +++ b/packages/opencode/src/util/proxied.ts @@ -0,0 +1,3 @@ +export function proxied() { + return !!(process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.http_proxy || process.env.https_proxy) +}