[PR #6848] fix: await dependency installation before loading custom tools #12138

Closed
opened 2026-02-16 18:17:04 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6848

State: closed
Merged: No


Fixes an issue where custom tools fail to load with "Cannot find module '@opencode-ai/plugin'" errors due to a tool loading vs. dependency installation "race".

This builds on #6302 by ensuring dependency installation completes before attempting to load custom tools that depend on those packages without impacting OpenCode startup time - e.g. we don't block app startup, just tool loading (which is already on-demand).

notably, this implementation ensures that tools wait only for their own directory's dependencies (minimal blocking).

problem: After #6302, OpenCode runs bun install for each config directory to install dependencies. However, if node_modules already exists, the installation runs asynchronously in the background without waiting. When custom tools are loaded immediately after, they fail to import @opencode-ai/plugin or other dependencies because the install hasn't finished yet.

fix: Track the install promise for each config directory and await it before loading tools from that directory:

  • Config directories start installing dependencies in parallel (non-blocking)
  • When the tool registry loads tools from a directory, it awaits that directory's install promise
  • This ensures tools only import after their dependencies are ready
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6848 **State:** closed **Merged:** No --- Fixes an issue where custom tools fail to load with `"Cannot find module '@opencode-ai/plugin'"` errors due to a tool loading vs. dependency installation "race". **This builds on #6302 by ensuring dependency installation completes before attempting to load custom tools that depend on those packages without impacting OpenCode startup time - e.g. we don't block app startup, just tool loading (which is already on-demand).** notably, this implementation ensures that _tools wait only for their own directory's dependencies (minimal blocking)_. **problem**: After #6302, OpenCode runs `bun install` for each config directory to install dependencies. However, if `node_modules` already exists, the installation runs asynchronously in the background without waiting. When custom tools are loaded immediately after, they fail to import `@opencode-ai/plugin` or other dependencies because the install hasn't finished yet. **fix**: Track the install promise for each config directory and await it before loading tools from that directory: * Config directories start installing dependencies in parallel (non-blocking) * When the tool registry loads tools from a directory, it awaits that directory's install promise * This ensures tools only import after their dependencies are ready
yindo added the pull-request label 2026-02-16 18:17:04 -05:00
yindo closed this issue 2026-02-16 18:17:04 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12138