Storage resilience: atomic writes, safer temp cleanup, repair/restore tools #4695

Closed
opened 2026-02-16 17:45:04 -05:00 by yindo · 1 comment
Owner

Originally created by @KakashiTech on GitHub (Jan 10, 2026).

Originally assigned to: @thdxr on GitHub.

Summary
OpenCode storage could be corrupted on crashes or disk-full mid-write. This proposes atomic writes, a safe repair routine, and a restore path to recover.

Problem

  • Direct writes risk partial/truncated JSON.
  • Leftover temps accumulate; repair lacked coarse-grained coordination and reporting.
  • Operators need dry-run and limits before touching data at scale.

Proposal

  • Atomic write: temp + fsync(file) + rename + fsync(dir).
  • Repair: dry-run, prefix/limits, safe temp cleanup (.oc-*.tmp), skip-when-locked, JSON report.
  • Restore: bring files back from quarantine preserving structure.
  • Tests for dry-run/restore and temp cleanup.

Non-goals

  • Schema-level validation or semantic corruption detection.
  • Cross-FS transactional guarantees (e.g., NFS/Windows beyond documented best effort).
  • Retention policy for quarantine (can be follow-up).

Risks/Trade-offs

  • rename + fsync(dir) adds slight I/O overhead.
  • Repair writes a report file (operationally useful).
  • Try-lock may skip files busy during repair; reported as skipped.
  • Portability: Bun APIs with Node fsync fallback; best-effort on non-POSIX FS.

Verification

  • Unit tests added.
  • Manual: run repair in a sandbox with XDG paths; confirm JSON report and quarantined files.

Open questions

  • Retention policy for quarantine?
  • Global maintenance lock for repair windows?
Originally created by @KakashiTech on GitHub (Jan 10, 2026). Originally assigned to: @thdxr on GitHub. Summary OpenCode storage could be corrupted on crashes or disk-full mid-write. This proposes atomic writes, a safe repair routine, and a restore path to recover. Problem - Direct writes risk partial/truncated JSON. - Leftover temps accumulate; repair lacked coarse-grained coordination and reporting. - Operators need dry-run and limits before touching data at scale. Proposal - Atomic write: temp + fsync(file) + rename + fsync(dir). - Repair: dry-run, prefix/limits, safe temp cleanup (.oc-*.tmp), skip-when-locked, JSON report. - Restore: bring files back from quarantine preserving structure. - Tests for dry-run/restore and temp cleanup. Non-goals - Schema-level validation or semantic corruption detection. - Cross-FS transactional guarantees (e.g., NFS/Windows beyond documented best effort). - Retention policy for quarantine (can be follow-up). Risks/Trade-offs - rename + fsync(dir) adds slight I/O overhead. - Repair writes a report file (operationally useful). - Try-lock may skip files busy during repair; reported as skipped. - Portability: Bun APIs with Node fsync fallback; best-effort on non-POSIX FS. Verification - Unit tests added. - Manual: run repair in a sandbox with XDG paths; confirm JSON report and quarantined files. Open questions - Retention policy for quarantine? - Global maintenance lock for repair windows?
yindo closed this issue 2026-02-16 17:45:04 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 10, 2026):

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

  • #7733: Storage resilience: atomic writes, safer temp cleanup, repair/restore tools (appears to be identical)
  • #7607: If disk space runs out your active session becomes corrupted (describes the specific failure scenario this proposal addresses)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 10, 2026): This issue might be a duplicate of existing issues. Please check: - #7733: Storage resilience: atomic writes, safer temp cleanup, repair/restore tools (appears to be identical) - #7607: If disk space runs out your active session becomes corrupted (describes the specific failure scenario this proposal addresses) Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4695