Skip to content

fix: Windows-safe atomic session state writes (EPERM) - #5

Merged
ByBrawe merged 2 commits into
ByBrawe:mainfrom
ActArtech:fix/windows-atomic-state-write
Aug 8, 2026
Merged

ByBrawe merged 2 commits into
ByBrawe:mainfrom
ActArtech:fix/windows-atomic-state-write

Conversation

@ActArtech

Copy link
Copy Markdown

Summary

Fixes /loop breaking on Windows when heartbeat and due-timer updates rewrite session state.

On Windows, OpenCode Loop was writing state as:

  1. create .opencode/opencode-loop/ses_*.json.<pid>.<ts>.tmp next to the target
  2. rename(tmp, target)

That fails with EPERM / EEXIST when antivirus, IDE indexers, or OpenCode's own git snapshotter briefly hold the destination file. Observed effects in production logs:

  • heartbeat-error / due-timer-error with EPERM: operation not permitted, rename ...tmp -> ...json
  • jobs disappearing or failing to persist (jobs: [])
  • OpenCode warnings: failed to add snapshot files for project-local *.tmp pathspecs

Changes

  • Stage atomic payloads under the OS temp directory (outside the project)
  • Replace the target with rename when possible
  • Fall back to copyFile + unlink with short retries on EXDEV / EPERM / EEXIST / EBUSY / EACCES
  • Add comprehensive regression for rapid overwrite + no project-local leftover *.tmp
  • Document .gitignore guidance for .opencode/opencode-loop/
  • Bump package version to 0.5.20 and changelog

Test plan

  • npm test (installer, loopd, smoke, comprehensive) on Windows
  • In a real OpenCode TUI session after install:
    • /loop 0s --max-runs 3 continue from progress.md
    • /loop-status shows the job across heartbeat ticks
    • No new EPERM lines in .opencode/opencode-loop/loop.log
    • No opencode-loop/*.tmp left in the project tree

Notes

This is independent of opencode-ralph-loop load failures (content.match is not a function); that is a separate package.

alaa541 added 2 commits August 7, 2026 15:17
OpenCode Loop rewrites .opencode/opencode-loop/ses_*.json on every
heartbeat and due-timer tick. On Windows, rename over an existing state
file often fails with EPERM/EEXIST while antivirus, IDE indexers, or
OpenCode snapshots hold the destination. Project-local *.tmp files also
leaked into git snapshot pathspecs.

Stage payloads in the OS temp directory, replace the target with rename
when possible, and fall back to copy/unlink with short retries. Add a
regression for rapid state overwrites and document gitignore guidance.
@ByBrawe
ByBrawe merged commit 96f8c21 into ByBrawe:main Aug 8, 2026
@ByBrawe

ByBrawe commented Aug 8, 2026

Copy link
Copy Markdown
Owner

thank you for contribution

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.

3 participants