fix: await dependency installation before loading custom tools #6848
+13
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 installfor each config directory to install dependencies. However, ifnode_modulesalready exists, the installation runs asynchronously in the background without waiting. When custom tools are loaded immediately after, they fail to import@opencode-ai/pluginor 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: