fix: invalidate opencode plugin cache on global install#2402
fix: invalidate opencode plugin cache on global install#2402popododo0720 wants to merge 1 commit intocode-yeongyu:devfrom
Conversation
When users run 'bun install -g oh-my-opencode', only the global npm package is updated. opencode resolves plugins from its own cache at $XDG_CACHE_HOME/opencode/node_modules/ with a separate bun.lock, so the stale cached version continues to be used on next launch. The postinstall script now removes the cached oh-my-opencode module and lockfiles, forcing opencode to re-resolve @latest on next startup.
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 2/5
- There’s a high-risk behavior in
postinstall.mjswhere sharedbun.lock/bun.lockbfiles in the opencode cache are deleted, which can unpin versions for other plugins and cause unpredictable installs. - Given the severity (8/10) and potential cross-plugin impact, merge risk is elevated despite the small surface area of change.
- Pay close attention to
postinstall.mjs- deletes shared lockfiles and may affect other plugin installs.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="postinstall.mjs">
<violation number="1" location="postinstall.mjs:60">
P1: Destructive deletion of shared lockfiles unpins versions for all other installed opencode plugins. The code at `postinstall.mjs` deletes the entire `bun.lock` and `bun.lockb` files from the opencode cache directory, which are shared across all plugins. This unpins versions of all other installed plugins and may cause them to update to incompatible versions on next startup. Consider using a more scoped invalidation mechanism that only removes the specific plugin's lockfile entries.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| const targets = [ | ||
| join(cacheBase, "node_modules", "oh-my-opencode"), | ||
| join(cacheBase, "bun.lock"), |
There was a problem hiding this comment.
P1: Destructive deletion of shared lockfiles unpins versions for all other installed opencode plugins. The code at postinstall.mjs deletes the entire bun.lock and bun.lockb files from the opencode cache directory, which are shared across all plugins. This unpins versions of all other installed plugins and may cause them to update to incompatible versions on next startup. Consider using a more scoped invalidation mechanism that only removes the specific plugin's lockfile entries.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At postinstall.mjs, line 60:
<comment>Destructive deletion of shared lockfiles unpins versions for all other installed opencode plugins. The code at `postinstall.mjs` deletes the entire `bun.lock` and `bun.lockb` files from the opencode cache directory, which are shared across all plugins. This unpins versions of all other installed plugins and may cause them to update to incompatible versions on next startup. Consider using a more scoped invalidation mechanism that only removes the specific plugin's lockfile entries.</comment>
<file context>
@@ -22,7 +27,52 @@ function getLibcFamily() {
+
+ const targets = [
+ join(cacheBase, "node_modules", "oh-my-opencode"),
+ join(cacheBase, "bun.lock"),
+ join(cacheBase, "bun.lockb"),
+ ];
</file context>
|
Re: lockfile deletion concern (identified by cubic) — this is an intentional trade-off. Without deleting the lockfiles, The blast radius is limited: |
Summary
bun install -g oh-my-opencodeby invalidating opencode's plugin cache in the postinstall script.Problem
When users run
bun install -g oh-my-opencode, only the global npm package at~/.bun/install/global/node_modules/is updated. However, opencode resolves plugins from its own separate cache at$XDG_CACHE_HOME/opencode/node_modules/with its ownbun.lock. The stale cached version continues to be loaded on subsequent launches, causing version mismatch.Solution
The
postinstall.mjsscript now:node_modules/oh-my-opencode(stale cached module)bun.lockandbun.lockb(required because bun reinstalls the exact pinned version from the lock entry)existsSyncto skip if cache doesn't exist (fresh install)main()with.catch()to never fail the install processSummary by cubic
Invalidate opencode’s plugin cache on global install so the latest
oh-my-opencodeis loaded on next launch. Prevents stale versions afterbun install -g oh-my-opencode.postinstall.mjsdeletes cachedoh-my-opencodeandbun.lock/bun.lockbunder$XDG_CACHE_HOME/opencode(defaults to~/.cache/opencode) to force re-resolve.Written for commit 483f2b0. Summary will update on new commits.