Skip to content

feat(world): crash-safe saves (verify-readback + .bak snapshot)#120

Merged
proggeramlug merged 1 commit into
mainfrom
feat/safe-saves
Jul 17, 2026
Merged

feat(world): crash-safe saves (verify-readback + .bak snapshot)#120
proggeramlug merged 1 commit into
mainfrom
feat/safe-saves

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Editor production-readiness item 5.2 (editor PLAN.md Part 5): saveWorld/savePrefab now write <path>.tmp, read it back and byte-compare (catches the historical zero-byte-write-reports-success failure class), snapshot the previous file to <path>.bak, then write the real file — a crash at any point leaves a good copy on disk. True atomic replace needs a rename FFI (future).

Verified by the editor's new tools/ui-smoke.ps1 interaction test.

https://claude.ai/code/session_01PmL9WgNMkAgvpYSHEZga8K

Summary by CodeRabbit

  • Bug Fixes
    • Improved world and prefab save reliability by verifying saved data before finalizing files.
    • Existing save files are backed up before being replaced.
    • Save failures now return clearer error results while preserving validation behavior.

…e touching the real file

A save is a user's level; half-written is unacceptable. No rename FFI
exists, so instead of atomic replace: write <path>.tmp, READ IT BACK and
byte-compare (the check that catches the historical 0-bytes-reported-ok
writeFile failure), snapshot the current file to <path>.bak, then write
<path>. A crash at any point leaves a verified copy in .tmp or the
previous version in .bak. Applies to saveWorld and savePrefab.

Verified by the editor's ui-smoke script: save produces the siblings and
the saved file parses with the expected entity count.

Claude-Session: https://claude.ai/code/session_01PmL9WgNMkAgvpYSHEZga8K
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b67ad3c-4e09-4fec-a7ae-efc27b1b4d9c

📥 Commits

Reviewing files that changed from the base of the PR and between 57de189 and 4cbbb96.

📒 Files selected for processing (1)
  • src/world/saver.ts

📝 Walkthrough

Walkthrough

src/world/saver.ts adds verified temporary writes, optional .bak snapshots, and final-file replacement. saveWorld and savePrefab now use this flow and return prefixed errors on failure, while validation behavior remains unchanged.

Changes

Crash-safe world and prefab saves

Layer / File(s) Summary
Verified write and backup flow
src/world/saver.ts
safeWrite writes to a temporary file, verifies read-back content, optionally creates a .bak snapshot, and writes verified content to the final path.
World and prefab integration
src/world/saver.ts
saveWorld and savePrefab call safeWrite and prefix returned errors with their operation names.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SaveOperation
  participant safeWrite
  participant Filesystem
  SaveOperation->>safeWrite: JSON path and content
  safeWrite->>Filesystem: Write temporary file
  safeWrite->>Filesystem: Read back and compare content
  safeWrite->>Filesystem: Snapshot existing file to .bak
  safeWrite->>Filesystem: Write verified content to final path
  safeWrite-->>SaveOperation: Success or error
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: crash-safe world and prefab saves with readback verification and backups.
Description check ✅ Passed The description covers the change and verification, though it does not fully follow the template’s checklist and reviewer-notes sections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/safe-saves

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug merged commit f554d34 into main Jul 17, 2026
9 of 10 checks passed
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.

1 participant