opencode icon indicating copy to clipboard operation
opencode copied to clipboard

opencode get stuck when `bun add` get stuck

Open WAY29 opened this issue 1 month ago • 21 comments

Description

What happen: When I executed opencode, the program froze, akin to a terminal being frozen. I was unable to close it using any method, such as pressing Ctrl+C. When I terminated it from another terminal, I ran it again with the --print-log option and noticed it was stuck at the bun add command. I think we should improve this situation.

I've done some digging and found out why the bun got stuck. It's because my bun encountered a 304 response, and then it just went nowhere. Maybe we should add --no-cache option when run bun.

By the way, I've encountered this error multiple times already; I often have to manually run "bun add."

bun add --cwd /Users/lang/.cache/opencode --force --exact [email protected] --verbose

bun add v1.3.3 (274e01c7)
   - "opencode-anthropic-auth": "0.0.2" - [email protected]
Enqueue package manifest for download: @openauthjs/openauth
  🔍 Resolving [1/1] [fetch] > HTTP/1.1 GET https://registry.npmmirror.com/@openauthjs%2fopenauth
[fetch] > If-None-Match: W/"e9e873cea576887a9d66bdd1048dbf983cadbe45"
[fetch] > Accept: application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*
[fetch] > Connection: keep-alive
[fetch] > User-Agent: Bun/1.3.3
[fetch] > Host: registry.npmmirror.com
[fetch] > Accept-Encoding: gzip, deflate, br, zstd

[fetch] < 200 Connection established

[fetch] < 304 Not Modified
[fetch] < Server: Tengine
[fetch] < Connection: keep-alive
[fetch] < Strict-Transport-Security: max-age=5184000
[fetch] < Date: Mon, 24 Nov 2025 08:21:49 GMT
[fetch] < request-id: cb00ed85-d034-4a21-b240-036edd52697a
[fetch] < cache-control: public, max-age=300
[fetch] < x-frame-options: SAMEORIGIN
[fetch] < x-xss-protection: 1; mode=block
[fetch] < x-content-type-options: nosniff
[fetch] < x-download-options: noopen
[fetch] < x-readtime: 1.462
[fetch] < Via: cn8360.l1, kunlun1.cn8360, l2cn8047.l2, cache23.l2cn8047, npmmirror-x86-20220823001, cache23.l2cn8047[0,0,304-0,H], cache34.l2cn8047[1,0], kunlun10.cn7632[32,31,304-0,H], kunlun1.cn7632[34,0]
[fetch] < Vary: Origin, Accept, Accept-Encoding
[fetch] < etag: W/"e9e873cea576887a9d66bdd1048dbf983cadbe45"
[fetch] < Age: 45
[fetch] < Ali-Swift-Global-Savetime: 1763972509
[fetch] < X-Cache: HIT TCP_REFRESH_HIT dirn:-2:-2
[fetch] < X-Swift-SaveTime: Mon, 24 Nov 2025 08:22:34 GMT
[fetch] < X-Swift-CacheTime: 255
[fetch] < Timing-Allow-Origin: *
[fetch] < EagleId: 2493171517639725549608795e

OpenCode version

No response

Steps to reproduce

  1. run opencode
  2. get stuck

Screenshot and/or share link

No response

Operating System

macos

Terminal

vscode terminal

WAY29 avatar Nov 24 '25 08:11 WAY29

This issue might be a duplicate of existing issues. Please check:

  • #4672: OpenCode Github Agent Stuck! - Reports OpenCode getting stuck during execution

The root cause you've identified (bun hanging on 304 cache responses) appears to be specific to this issue, but the symptom (OpenCode freezing/getting stuck) is also seen in #4672. Feel free to ignore if your specific case differs from those issues.

github-actions[bot] avatar Nov 24 '25 08:11 github-actions[bot]

Is there a way to prevent opencode from updating bun depends anymore?

WAY29 avatar Nov 24 '25 08:11 WAY29

hmm ill look into it, for this the only work around would be to disable the default plugins that we load (or only work around we currently provide)

rekram1-node avatar Nov 24 '25 15:11 rekram1-node

Regarding this issue, I'd like to add another common case: for users in mainland China, updating bun may require configuring a mirror.

Image

https://bun.com/docs/runtime/bunfig

[install]
registry = "https://registry.npmmirror.com"

Although I'm not sure whether this information is appropriate, or where it should be mentioned @rekram1-node

jensenojs avatar Nov 26 '25 06:11 jensenojs

Regarding this issue, I'd like to add another common case: for users in mainland China, updating bun may require configuring a mirror.

Image https://bun.com/docs/runtime/bunfig

[install] registry = "https://registry.npmmirror.com" Although I'm not sure whether this information is appropriate, or where it should be mentioned @rekram1-node

Yes, I am Chinese, I had already add bun mirror, but bun still got stuck when http response 304 status code

WAY29 avatar Nov 26 '25 06:11 WAY29

that's good to know thx

rekram1-node avatar Nov 26 '25 06:11 rekram1-node

I'm facing exactly the same issue and therefore cannot use Opencode right now. Is there any temp. workaround to get it working again?

For context, I'm not located in China, but within a corporate network and behind a corporate proxy. I have proxies configured via environment variables (HTTP_PROXY, HTTPS_PROXY) and by setting them in npm config using npm config set proxy ... and npm config set https-proxy ....

jslorrma avatar Dec 02 '25 10:12 jslorrma

Hey everyone, just wanted to +1 this since I'm having the same issue when opencode goes through the bootstrapping routine.

INFO  2025-12-02T14:47:40 +166ms service=server method=GET path=/ request
INFO  2025-12-02T14:47:40 +0ms service=server status=started method=GET path=/ request
INFO  2025-12-02T14:47:40 +1ms service=default directory=/Users/user/.config/opencode creating instance
INFO  2025-12-02T14:47:40 +0ms service=project directory=/Users/user/.config/opencode fromDirectory
INFO  2025-12-02T14:47:40 +2ms service=default directory=/Users/user/.config/opencode bootstrapping
INFO  2025-12-02T14:47:40 +2ms service=config path=/Users/user/.config/opencode/config.json loading
INFO  2025-12-02T14:47:40 +0ms service=config path=/Users/user/.config/opencode/opencode.json loading
INFO  2025-12-02T14:47:40 +2ms service=config path=/Users/user/.config/opencode/opencode.jsonc loading
INFO  2025-12-02T14:47:40 +1ms service=config path=/Users/user/.config/opencode/opencode.json loading
INFO  2025-12-02T14:47:40 +2ms service=bun cmd=["/opt/homebrew/Cellar/opencode/1.0.126/libexec/lib/node_modules/opencode-ai/node_modules/opencode-darwin-arm64/bin/opencode","add","@opencode-ai/[email protected]","--exact"] cwd=/Users/user/.config/opencode running

edit: It seems that after many attempts of launching & having to kill opencode it finally managed to install the dependency and it started working again.

driden avatar Dec 02 '25 14:12 driden

There is a known issue w/ proxy stuff Ill get it fixed soon

rekram1-node avatar Dec 02 '25 17:12 rekram1-node

Once again, I encountered this problem, and for some reason, the dependencies of opencode I installed disappeared. I then used bun to install opencode again, and I got stuck in bun once more.

WAY29 avatar Dec 04 '25 03:12 WAY29

Once again, I encountered this problem, and for some reason, the dependencies of opencode I installed disappeared. I then used bun to install opencode again, and I got stuck in bun once more.

https://github.com/oven-sh/bun/issues/11526 This issue may be somewhat helpful; currently, it seems that the only way to help is for users to disable ipv6 or add —no-cache when adding bun (this appears to be the simplest solution).

WAY29 avatar Dec 04 '25 03:12 WAY29

repo because of opencode-dcp

Image
INFO  2025-12-05T09:06:31 +2ms service=server status=started method=GET path=/event request
INFO  2025-12-05T09:08:27 +115632ms service=bun code=0 stdout=bun add v1.3.3 (274e01c7)

installed @tarquinen/[email protected]

115 packages installed [721.63s]
 stderr=Resolving dependencies
Resolved, downloaded and extracted [71]
Saved lockfile
 done
INFO  2025-12-05T09:08:27 +96ms service=plugin path=file:///Users/oujinsai/.config/opencode/plugin/notification.js loading plugin
INFO  2025-12-05T09:08:27 +1ms service=plugin path=file:///Users/oujinsai/.config/opencode/plugin/env-protection.js loading plugin
INFO  2025-12-05T09:08:27 +0ms service=plugin [email protected] loading plugin
INFO  2025-12-05T09:08:27 +2ms service=bun pkg=opencode-copilot-auth version=0.0.8 installing package using Bun's default registry resolution
INFO  2025-12-05T09:08:27 +0ms service=bun pkg=opencode-copilot-auth version=0.0.8 attempt=1 total=3 bun install attempt
INFO  2025-12-05T09:08:27 +0ms service=bun cmd=["/opt/homebrew/Cellar/opencode/1.0.133/bin/opencode","add","--force","--exact","--cwd","/Users/oujinsai/.cache/opencode","[email protected]"] cwd=/Users/oujinsai/.cache/opencode running
INFO  2025-12-05T09:10:28 +120663ms service=bun code=0 stdout=bun add v1.3.3 (274e01c7)

+ @tarquinen/[email protected]

installed [email protected]

116 packages installed [120.65s]
 stderr=Resolving dependencies
Resolved, downloaded and extracted [5]
Saved lockfile
 done
INFO  2025-12-05T09:10:28 +38ms service=plugin [email protected] loading plugin
INFO  2025-12-05T09:10:28 +5ms service=bun pkg=opencode-anthropic-auth version=0.0.4 installing package using Bun's default registry resolution
INFO  2025-12-05T09:10:28 +0ms service=bun pkg=opencode-anthropic-auth version=0.0.4 attempt=1 total=3 bun install attempt
INFO  2025-12-05T09:10:28 +0ms service=bun cmd=["/opt/homebrew/Cellar/opencode/1.0.133/bin/opencode","add","--force","--exact","--cwd","/Users/oujinsai/.cache/opencode","[email protected]"] cwd=/Users/oujinsai/.cache/opencode running
...

jensenojs avatar Dec 05 '25 09:12 jensenojs

Once again, I've encountered this issue. It seems that after every auto-update of opencode, the bun dependency gets deleted, leading to this problem cropping up after each auto-update: [email protected].

WAY29 avatar Dec 05 '25 09:12 WAY29

I found a problem, every time I run opencode, bun seems to be trying to install new dependencies, which is too crazy, so I always encounter this issues every time I run opencode. I also encountered another problem, when I pin a dependency version in the configuration file, the latest version was still downloaded. https://github.com/numman-ali/opencode-openai-codex-auth/issues/60 @rekram1-node can you help me?

WAY29 avatar Dec 09 '25 03:12 WAY29

Clearing bun cache helped me to unstuck opencode

bun pm cache rm

klimkin avatar Dec 15 '25 23:12 klimkin

once again, but at lease we know why hhh

Image

jensenojs avatar Dec 18 '25 08:12 jensenojs

@WAY29

  • https://github.com/oven-sh/bun/issues/17793
Image
rm -rf ~/.cache/opencode && /usr/bin/time -lp opencode --print-logs

jensenojs avatar Dec 18 '25 12:12 jensenojs

I finally upgraded again today ~ 1hr startup time

INFO  2025-12-18T13:59:17 +0ms service=server method=GET path=/event request
INFO  2025-12-18T13:59:17 +0ms service=server status=started method=GET path=/event request
INFO  2025-12-18T13:59:17 +12ms service=default directory=/Users/ilou/code/Atlas_Acceptance_Tests bootstrapping
INFO  2025-12-18T13:59:17 +1ms service=config path=/Users/ilou/.config/opencode/config.json loading
INFO  2025-12-18T13:59:17 +1ms service=config path=/Users/ilou/.config/opencode/opencode.json loading
INFO  2025-12-18T13:59:17 +1ms service=config path=/Users/ilou/.config/opencode/opencode.jsonc loading
INFO  2025-12-18T13:59:17 +2ms service=bun cmd=["/opt/homebrew/Cellar/opencode/1.0.167/libexec/lib/node_modules/opencode-ai/node_modules/opencode-darwin-arm64/bin/opencode","add","@opencode-ai/[email protected]","--exact"] cwd=/Users/ilou/.config/opencode running
INFO  2025-12-18T13:59:17 +1ms service=config path=/Users/ilou/code/Atlas_Acceptance_Tests/.opencode/opencode.jsonc loading
INFO  2025-12-18T13:59:17 +0ms service=config path=/Users/ilou/code/Atlas_Acceptance_Tests/.opencode/opencode.json loading
INFO  2025-12-18T13:59:17 +2ms service=bun cmd=["/opt/homebrew/Cellar/opencode/1.0.167/libexec/lib/node_modules/opencode-ai/node_modules/opencode-darwin-arm64/bin/opencode","add","@opencode-ai/[email protected]","--exact"] cwd=/Users/ilou/code/Atlas_Acceptance_Tests/.opencode running
INFO  2025-12-18T14:05:32 +375338ms service=bun code=0 stdout=bun add v1.3.4 (5eb2145b)

installed @opencode-ai/[email protected]

2 packages installed [375.33s]
 stderr=Resolving dependencies
Resolved, downloaded and extracted [2]
Saved lockfile
 done
INFO  2025-12-18T14:05:32 +323ms service=bun code=0 stdout=bun add v1.3.4 (5eb2145b)

installed @opencode-ai/[email protected]

2 packages installed [375.65s]
 stderr=Resolving dependencies
Resolved, downloaded and extracted [2]
Saved lockfile
 done
INFO  2025-12-18T14:05:32 +8ms service=plugin [email protected] loading plugin
INFO  2025-12-18T14:05:32 +2ms service=bun pkg=opencode-copilot-auth version=0.0.9 installing package using Bun's default registry resolution
INFO  2025-12-18T14:05:32 +0ms service=bun cmd=["/opt/homebrew/Cellar/opencode/1.0.167/libexec/lib/node_modules/opencode-ai/node_modules/opencode-darwin-arm64/bin/opencode","add","--force","--exact","--cwd","/Users/ilou/.cache/opencode","[email protected]"] cwd=/Users/ilou/.cache/opencode running
INFO  2025-12-18T14:11:48 +375307ms service=bun code=0 stdout=bun add v1.3.4 (5eb2145b)

installed [email protected]

1 package installed [375.28s]
 stderr=Resolving dependencies
Resolved, downloaded and extracted [4]
Saved lockfile
 done
INFO  2025-12-18T14:11:48 +26ms service=plugin [email protected] loading plugin
INFO  2025-12-18T14:11:48 +0ms service=bun pkg=opencode-anthropic-auth version=0.0.5 installing package using Bun's default registry resolution
INFO  2025-12-18T14:11:48 +0ms service=bun cmd=["/opt/homebrew/Cellar/opencode/1.0.167/libexec/lib/node_modules/opencode-ai/node_modules/opencode-darwin-arm64/bin/opencode","add","--force","--exact","--cwd","/Users/ilou/.cache/opencode","[email protected]"] cwd=/Users/ilou/.cache/opencode running                                                                                                                                                                                                       INFO  2025-12-18T14:50:32 +2324281ms service=bun code=0 stdout=bun add v1.3.4 (5eb2145b)

+ [email protected]

installed [email protected]

14 packages installed [2324.25s]
 stderr=Resolving dependencies
Resolved, downloaded and extracted [10]
Saved lockfile
 done
INFO  2025-12-18T14:50:32 +23ms service=bus type=* subscribing
INFO  2025-12-18T14:50:32 +0ms service=bus type=session.updated subscribing
INFO  2025-12-18T14:50:32 +0ms service=bus type=message.updated subscribing
INFO  2025-12-18T14:50:32 +0ms service=bus type=message.part.updated subscribing
INFO  2025-12-18T14:50:32 +0ms service=bus type=session.updated subscribing
INFO  2025-12-18T14:50:32 +0ms service=bus type=message.updated subscribing
INFO  2025-12-18T14:50:32 +0ms service=bus type=message.part.updated subscribing
INFO  2025-12-18T14:50:32 +0ms service=bus type=session.diff subscribing
INFO  2025-12-18T14:50:32 +0ms service=format init
INFO  2025-12-18T14:50:32 +0ms service=bus type=file.edited subscribing
INFO  2025-12-18T14:50:32 +0ms service=lsp serverIds=deno, typescript, vue, eslint, biome, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, fsharp, sourcekit-lsp, rust, clangd, svelte, astro, jdtls, yaml-ls, lua-ls, php intelephense, dart, ocaml-lsp, bash, terraform, texlab, dockerfile, gleam enabled LSP servers
INFO  2025-12-18T14:50:32 +0ms service=file.watcher init
INFO  2025-12-18T14:50:32 +2ms service=bus type=command.executed subscribing
INFO  2025-12-18T14:50:32 +1ms service=file.watcher platform=darwin backend=fs-events watcher backend
INFO  2025-12-18T14:50:32 +2ms service=server status=started providers
INFO  2025-12-18T14:50:32 +1ms service=provider status=started state
INFO  2025-12-18T14:50:32 +1ms service=server event connected
INFO  2025-12-18T14:50:32 +1ms service=bus type=* subscribing
INFO  2025-12-18T14:50:32 +3ms service=models.dev file={} refreshing
INFO  2025-12-18T14:50:32 +0ms service=models.dev file={} refreshing
INFO  2025-12-18T14:50:32 +1ms service=server status=completed duration=3075340 method=GET path=/event request
INFO  2025-12-18T14:50:32 +0ms service=server status=completed duration=3075340 method=GET path=/config request
INFO  2025-12-18T14:50:32 +1ms service=server status=completed duration=3075341 method=GET path=/agent request
INFO  2025-12-18T14:50:32 +8ms service=provider init
INFO  2025-12-18T14:50:33 +464ms service=vcs branch=no_jira_disable_account_statements_tests initialized
INFO  2025-12-18T14:50:33 +0ms service=bus type=file.watcher.updated subscribing
INFO  2025-12-18T14:50:33 +15ms service=provider providerID=github-copilot found
INFO  2025-12-18T14:50:33 +0ms service=provider providerID=opencode found
INFO  2025-12-18T14:50:33 +0ms service=provider status=completed duration=494 state
INFO  2025-12-18T14:50:33 +8ms service=server status=completed duration=503 providers
INFO  2025-12-18T14:50:33 +1ms service=server status=completed duration=3075837 method=GET path=/provider request
INFO  2025-12-18T14:50:33 +0ms service=server status=completed duration=3075838 method=GET path=/config/providers request
INFO  2025-12-18T14:50:33 +23ms service=server method=GET path=/session request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/session request
INFO  2025-12-18T14:50:33 +0ms service=server method=GET path=/command request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/command request
INFO  2025-12-18T14:50:33 +1ms service=server status=completed duration=1 method=GET path=/command request
INFO  2025-12-18T14:50:33 +0ms service=server method=GET path=/lsp request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/lsp request
INFO  2025-12-18T14:50:33 +0ms service=server status=completed duration=0 method=GET path=/lsp request
INFO  2025-12-18T14:50:33 +1ms service=server method=GET path=/mcp request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/mcp request
INFO  2025-12-18T14:50:33 +0ms service=server status=completed duration=0 method=GET path=/mcp request
INFO  2025-12-18T14:50:33 +1ms service=server method=GET path=/formatter request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/formatter request
INFO  2025-12-18T14:50:33 +5ms service=server method=GET path=/session/status request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/session/status request
INFO  2025-12-18T14:50:33 +1ms service=server status=completed duration=1 method=GET path=/session/status request
INFO  2025-12-18T14:50:33 +2ms service=server method=GET path=/provider/auth request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/provider/auth request
INFO  2025-12-18T14:50:33 +0ms service=server status=completed duration=0 method=GET path=/provider/auth request
INFO  2025-12-18T14:50:33 +1ms service=server method=GET path=/vcs request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/vcs request
INFO  2025-12-18T14:50:33 +0ms service=server status=completed duration=0 method=GET path=/vcs request
INFO  2025-12-18T14:50:33 +1ms service=server method=GET path=/path request
INFO  2025-12-18T14:50:33 +0ms service=server status=started method=GET path=/path request
INFO  2025-12-18T14:50:33 +0ms service=server status=completed duration=0 method=GET path=/path request
INFO  2025-12-18T14:50:33 +28ms service=server status=completed duration=38 method=GET path=/formatter request
INFO  2025-12-18T14:50:33 +73ms service=server status=completed duration=114 method=GET path=/session request

driden avatar Dec 18 '25 14:12 driden

I've tested this on other machines. With the --no-cache option added, it does resolve the issue in scenarios where HTTPS_PROXY would reliably cause hangs. Considering this might be an upstream bug, I'm unsure whether adding the corresponding field is appropriate, but it does affect the experience somewhat. What do you think? @rekram1-node Solving it could probably close around six or seven issues.

ps. When I tried it on that computer, I didn't realize a PR had already been submitted for it by @WAY29

jensenojs avatar Dec 18 '25 15:12 jensenojs