Skip to content

fix(opencode): atomic storage writes with retry/backoff + quarantine on Windows; tolerant reads#11646

Open
KakashiTech wants to merge 5 commits intoanomalyco:devfrom
KakashiTech:feat/storage-atomic-retry-quarantine
Open

fix(opencode): atomic storage writes with retry/backoff + quarantine on Windows; tolerant reads#11646
KakashiTech wants to merge 5 commits intoanomalyco:devfrom
KakashiTech:feat/storage-atomic-retry-quarantine

Conversation

@KakashiTech
Copy link

@KakashiTech KakashiTech commented Feb 1, 2026

What

  • Atomic write on Windows: temp → fsync(file) → rename → fsync(dir) with retry/backoff on open/rename.

  • Tolerant reads: retries on transient FS errors; if JSON is corrupt or retries exhaust, move to quarantine instead of crashing.

  • Quarantine: preserve data when rename/open is blocked (AV/sharing) and when JSON is malformed.

  • Tests: invalid JSON → quarantine; rename failure (target path is a directory) → quarantine.

Why (Windows)

  • Corporate AV often causes transient sharing violations leading to UV_UNKNOWN on open/rename (e.g. ...storage\part\msg_\prt_.json). This made storage unusable for some users (Error: UV_UNKNOWN: unknown error #8792).
  • This change keeps storage responsive by retrying transient errors and safely isolating bad/locked files.

Details

  • Retries: 6 attempts, exponential backoff (≈50ms → 1.6s).
  • Temp file name: .oc-<basename>.<pid>.<ts>.tmp in the same directory.
  • Directory/file fsync used where supported; failures are tolerated safely.
  • Quarantine path: storage/quarantine/<timestamp>/<relative-original-path>.json.

Verification

  • bun install and bun test: 789 passing, 0 failing.
  • Manual: on Windows with Defender enabled, confirm no hard crash, and that corrupt/locked files end up in quarantine when needed.

Trade-offs

  • Slight I/O overhead from fsync and retries, bounded and only on contention.
  • Creates a quarantine folder for recovery workflows.

Links

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

Hey! Your PR title feat(storage, windows): atomic write + retry/backoff, quarantine; tolerant reads; tests doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@KakashiTech KakashiTech changed the title feat(storage, windows): atomic write + retry/backoff, quarantine; tolerant reads; tests fix(opencode): atomic storage writes with retry/backoff + quarantine on Windows; tolerant reads Feb 1, 2026
@Musti94AI
Copy link

I have tested this and your solution seems to work @KakashiTech
I am running OpenCode locally and no issues until now.

@Musti94AI
Copy link

I tried the fix the last couple of days and I had no problems at all! Works perfectly :)
@rekram1-node Thanks in advance for the review! Looking forward to getting this merged. And thank you @KakashiTech !

@jnargi
Copy link

jnargi commented Feb 10, 2026

Confirm this solution works, hope this gets merged into main soon

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.

Error: UV_UNKNOWN: unknown error

3 participants