Skip to content

fix(session): fix snapshot write failure on Windows - #548

Merged
jensenojs merged 1 commit into
sudo-tee:mainfrom
wzj-zz:fix/session-tab-persistence
Oct 22, 2026
Merged

jensenojs merged 1 commit into
sudo-tee:mainfrom
wzj-zz:fix/session-tab-persistence

Conversation

@wzj-zz

@wzj-zz wzj-zz commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Problem

On Windows, os.rename() cannot overwrite an existing file. After the first snapshot write succeeds, all subsequent writes fail with "File exists" because the target file already exists.

This causes three reported bugs:

All three share the same root cause: the snapshot file is never updated after the initial write, so any changes (new tabs, session switches, session deletions) are silently lost.

Fix

On Windows, remove the existing snapshot file before renaming the temporary file. On Linux, os.rename() already supports overwriting atomically, so no change is needed.

Changes

  • lua/opencode/services/session_tab_persistence.lua: Add os.remove(path) before os.rename() on Windows in write()

Fixes #545
Fixes #541 (Bug 3)
Fixes #546

os.rename cannot overwrite an existing file on Windows, causing all
subsequent saves to fail after the first write. Remove the target file
before renaming the temporary file, keeping the operation atomic on
platforms that support it.

Fixes sudo-tee#545
Fixes sudo-tee#541 Bug 3
Fixes sudo-tee#546
@wzj-zz
wzj-zz force-pushed the fix/session-tab-persistence branch from 2478990 to 665d1b9 Compare October 21, 2026 23:18
@jensenojs
jensenojs merged commit b842eca into sudo-tee:main Oct 22, 2026
7 checks passed
@jensenojs

Copy link
Copy Markdown
Collaborator

thanks!

@sudo-tee

Copy link
Copy Markdown
Owner

Thanks for taking care of this. I was a bit swamped the past days.

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

Labels

None yet

Projects

None yet

3 participants