Skip to content

fix(installation): handle Windows upgrade by scheduling binary replacement - #48368

Closed
loisekk wants to merge 14 commits into
anomalyco:devfrom
loisekk:fix/windows-upgrade
Closed

loisekk wants to merge 14 commits into
anomalyco:devfrom
loisekk:fix/windows-upgrade

Conversation

@loisekk

@loisekk loisekk commented Sep 10, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #37055

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Ran into this while trying to upgrade on Windows — the command says it worked but nothing actually changed. Spent a while figuring out what was happening.

The problem is in how upgradeCurl works. It grabs a bash script from opencode.ai/install and runs it, which then tries to mv the new binary over the one that's currently running. On Linux this is fine, but Windows won't let you overwrite a running executable, so the mv just fails silently. The script doesn't catch this and reports success anyway.

The fix adds a separate path for Windows in upgradeCurl. When it detects process.platform === "win32", it calls upgradeCurlWindows instead of running the bash script. This new function:

  • Downloads the zip with curl.exe directly (no bash script involved)
  • Extracts to a temp folder next to the current binary
  • Renames the current binary to .old
  • Starts a batch script in the background that waits for opencode to exit before swapping the files

The batch script loops with move /y until it succeeds, so it doesn't matter if the user is still in a session — it just waits until the process is gone.

I know this pattern might look a bit hacky with the batch file and retry loop, but I couldn't find a cleaner way to handle a locked executable on Windows. Open to suggestions if there's a better approach.

Supersedes #37051 — that one got closed because I didn't fill out the template properly.

How did you verify your code works?

Tested on Windows 10. Built locally, ran opencode upgrade while in a session, then checked that the batch script was actually running in the background. After exiting, confirmed the binary got swapped by running opencode --version and checking the file timestamp. Also verified the temp files got cleaned up after the swap finished.

One thing I'm not 100% sure about — I only tested on Windows 10, not 11. The mechanism should be identical but I haven't verified that personally.

Screenshots / recordings

Not a UI change, so nothing to show here.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

loisekk added 2 commits July 15, 2026 12:46
…ement

On Windows, the 'curl' upgrade method runs a bash install script that
tries to mv the new binary over the running one. Windows locks running
executables, so the mv fails silently and the upgrade reports success
without actually replacing the binary.

This fix adds a Windows-specific upgrade path that:
1. Downloads the zip using curl.exe
2. Extracts it to a temp directory
3. Renames the current binary to .old
4. Spawns a background batch script that waits for the process to exit,
   then replaces the binary and cleans up

The batch script retries the move in a loop, so it handles both cases:
- User exits opencode normally
- User is still in the session (waits until they exit)
@k-stamp

k-stamp commented Sep 18, 2026

Copy link
Copy Markdown

How can we speed up things here? :)

@loisekk

loisekk commented Sep 18, 2026 •

Copy link
Copy Markdown
Author

Hey! Yeah, mostly just waiting on CI at this point the workflows need a maintainer to approve them before anything runs. That's really the only blocker on my end.
If tests fail once they run, I'll fix whatever comes up ASAP. And always open to feedback on the approach it's a small change, just a Windows-specific path in upgradeCurl that handles the binary swap after exit.

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: opencode upgrade fails silently on Windows - binary never replaced

3 participants