Opencode race condition with installDependencies() #2739

Closed
opened 2026-02-16 17:37:01 -05:00 by yindo · 2 comments
Owner

Originally created by @wolfie82 on GitHub (Nov 9, 2025).

Description

With recent versions of opencode >= 1.0.46, there appears to be a race condition when bun attempts to install packages from package.json in .opencode. We have some custom plugins that no longer function unless we manually do a npm install in the .opencode directory.

Issue:

18:52:01 +8ms - bun add fails (error code 1) - "An unknown error occurred (Unexpected)"
18:52:01 +417ms - bun add succeeds (code 0) - "@opencode-ai/plugin@1.0.40 installed"
18:52:01 +4ms - Plugin loading starts (dynamic-context-loader.ts)
18:52:01 +11ms - ERROR: Cannot find module '@opencode-ai/plugin'

Timeline Analysis:

  1. First bun add attempt fails (exits immediately at +8ms)
  2. Second bun add attempt succeeds (takes 423ms, completes at +417ms)
  3. Plugin loading starts at +4ms (only 4ms after initial failure!)
  4. Import fails at +11ms (7ms later)

The Problem:

The successful bun add at +417ms is too late - plugin loading already started at +4ms.

  1. Concurrent execution - installDependencies() not awaited
  2. Plugin loader doesn't wait - Starts importing before dependencies installed
  3. Race condition - Even when install succeeds, timing is unpredictable

OpenCode version

1.0.46

Originally created by @wolfie82 on GitHub (Nov 9, 2025). ### Description With recent versions of opencode >= 1.0.46, there appears to be a race condition when bun attempts to install packages from package.json in .opencode. We have some custom plugins that no longer function unless we manually do a `npm install` in the .opencode directory. Issue: 18:52:01 +8ms - bun add fails (error code 1) - "An unknown error occurred (Unexpected)" 18:52:01 +417ms - bun add succeeds (code 0) - "@opencode-ai/plugin@1.0.40 installed" 18:52:01 +4ms - Plugin loading starts (dynamic-context-loader.ts) 18:52:01 +11ms - ERROR: Cannot find module '@opencode-ai/plugin' Timeline Analysis: 1. First bun add attempt fails (exits immediately at +8ms) 2. Second bun add attempt succeeds (takes 423ms, completes at +417ms) 3. Plugin loading starts at +4ms (only 4ms after initial failure!) 4. Import fails at +11ms (7ms later) The Problem: The successful bun add at +417ms is too late - plugin loading already started at +4ms. 1. Concurrent execution - installDependencies() not awaited 2. Plugin loader doesn't wait - Starts importing before dependencies installed 3. Race condition - Even when install succeeds, timing is unpredictable ### OpenCode version 1.0.46
yindo added the opentuibug labels 2026-02-16 17:37:01 -05:00
yindo closed this issue 2026-02-16 17:37:02 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Nov 9, 2025):

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

  • #4047: Both involve bun installation failures and plugin loading issues with similar error patterns
  • #4126: Same "Cannot find module" error when dependencies are missing during build/load process

Feel free to ignore if none of these address your specific race condition case.

@github-actions[bot] commented on GitHub (Nov 9, 2025): This issue might be a duplicate of existing issues. Please check: - #4047: Both involve bun installation failures and plugin loading issues with similar error patterns - #4126: Same "Cannot find module" error when dependencies are missing during build/load process Feel free to ignore if none of these address your specific race condition case.
Author
Owner

@wolfie82 commented on GitHub (Nov 9, 2025):

I didn't mention I was running on WSL, which is solved by using WSL 2.0

https://github.com/oven-sh/bun/issues/20724

@wolfie82 commented on GitHub (Nov 9, 2025): I didn't mention I was running on WSL, which is solved by using WSL 2.0 https://github.com/oven-sh/bun/issues/20724
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2739