Skip to content

Auto-updater breaks global npm install: stub binary + missing shims, hung npm processes left behind #42291

Closed

Description

@hyp-type

Bug Report: Auto-updater can permanently break the global install (stub binary + missing shims), and hung npm install processes keep running

Environment: Windows 11 (10.0.26200), node v24.15.0, npm 11.12.1, opencode installed via npm install -g opencode-ai

Summary

On every startup, opencode spawns a background npm install -g opencode-ai@<latest> (the parent process of the npm process is the opencode.exe process itself). When the npm registry is unreachable/flaky (e.g. ECONNRESET), this install hangs for 15+ minutes and, when it finally progresses, it can leave the global installation in a broken state:

  1. npm extracts the new tarball, which overwrites bin/opencode.exe (the currently running binary!) with the 479-byte placeholder stub that says "Error: opencode-ai's postinstall script was not run."
  2. npm removes the old bin shims (opencode, opencode.cmd, opencode.ps1) before creating new ones - the failed install leaves only .opencode-* temp files behind.
  3. The postinstall then fails with EBUSY: resource busy or locked because the still-running opencode processes hold the old binary file (Windows locks running executables) - the install rolls back, but the shims are never recreated and the stub stays in place.

Result

  • opencode is no longer recognized in new terminal sessions (command not found).
  • Even invoking the exe directly prints the "postinstall was not run" stub error.
  • Existing opencode sessions keep working (the old binary stays mapped in memory) - so the breakage is invisible until you open a new terminal.

Observed evidence

  • npm install -g [email protected] started at 16:49 and 16:56, parented by cmd.exe /d /s /c whose parent was the opencode.exe process (auto-update), still alive/hung ~30 min later.
  • npm debug log: ECONNRESET Invalid response body while trying to fetch https://registry.npmjs.org/opencode-ai: aborted.
  • After the failed install: bin/opencode.exe = 479-byte stub (LastWriteTime = the moment of the breakage), shims missing, .opencode-UwDeVezx / .opencode.cmd-* / .opencode.ps1-* temp files left behind.

Suggested fixes

  1. Don't replace the binary in place while a process is running from it - install/verify first, then atomically swap; or refuse to update when an opencode process is still running (on Windows this can never work).
  2. Verify postinstall succeeded before removing old bin links, and restore the previous state on failure.
  3. Run the updater with a network timeout/retry limit instead of hanging indefinitely in the background.
  4. Provide a supported way to disable auto-update (e.g. autoupdate: false) - today there is no config option to opt out.

Activity

  1. github-actions commented on Aug 13, 2026

    @github-actions
    Contributor

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

    If either of those covers your case, please add a comment there with any new details rather than filing a new issue.

  2. MilkyWay008 commented on Aug 16, 2026

    @MilkyWay008

    Saw the same EBUSY loop when the auto-updater tried to replace the running exe, Windows locks the binary so the postinstall never finishes and you're left with the stub. Close all opencode windows, taskkill /IM opencode.exe /F, kill any stray npm processes, then re-run npm install -g [email protected] to recreate the shims. If the registry fetch keeps dying with ECONNRESET, npm cache clean --force first. Oh, btw, in case it might help that, I built a portable Hermes OTG repo, check it, imo it may be able to help you diagnose and figure out the fix in no time. https://github.com/MilkyWay008/Hermes-OTG

  3. qixuancao commented on Aug 20, 2026

    @qixuancao

    Linux confirmation for the auto-update failure mode (OpenCode 2 preview 0.0.0-beta-17639, Node 24.16.0, npm 12.0.2):

    The background updater logged a successful command equivalent to:

    npm install --global @opencode-ai/[email protected]
    

    but the installed bin/opencode2.exe was replaced by the package's 232-byte placeholder stub. New invocations failed immediately with:

    Error: @opencode-ai/cli's postinstall script was not run.
    

    This happened even though npm config get ignore-scripts returned false. An already-running service continued to work, making the breakage visible only after restart/new invocation.

    Manual recovery was:

    node <global-node-modules>/@opencode-ai/cli/postinstall.mjs
    

    which restored the native executable and made opencode2 --version work. So this is not limited to Windows locking behavior; the updater should verify that postinstall produced a runnable binary before reporting success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions