Repository navigation
fix(desktop): make crash-recovery buffer writes durable against power loss - #4864
Merged
Merged
Conversation
Adds write-file-atomic (+ @types) for durable, atomic file writes. Used by the crash-recovery buffer store; the document save path adopts it separately in #4852. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… loss writeBufferStoreFile persists unsaved tab content (the crash-recovery buffer) with a temp-file + rename. That is namespace-atomic — safe against an application crash — but omits fsync, so a power loss / OS reboot can still commit the new directory entry while the data blocks were never flushed, leaving a truncated or full-length zero-filled buffer. This is the same gap the document save path had (#3786). Write through write-file-atomic's sync API (fsync before the atomic rename), which also removes the hand-rolled temp/rename/cleanup and the writeSequence counter (its unique temp naming is handled internally). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
|
Website preview ready: https://pr-4864-marktext-website.ransixi.workers.dev Built from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to the #3786 / #3828 review (#4852): the atomic-save discussion noted that the crash-recovery buffer store — the precedent that change cited — shares the same durability gap.
EditorBufferStore.writeBufferStoreFilepersists unsaved tab content (the buffer restored after a crash) with a temp-file +renameSync. That is namespace-atomic, so it survives an application crash, but it omitsfsync. After a power loss / OS reboot the kernel can commit the new directory entry (rename) while the temp file's data blocks were never flushed — leaving the buffer truncated or full-length zero-filled. Same failure class as the document save path in #3786.Fix
Write through
write-file-atomic's sync API (writeFileAtomic.sync), which fsyncs the temp file before the atomic rename. This also removes the hand-rolled temp/rename/cleanup block and thewriteSequencecounter —write-file-atomichandles unique temp naming and cleanup internally.Notes
mt::fs::*IPC handlers, keybindings/recents config, the debug dump, the upload temp file) aren't document-critical or are inherently temporary, so they're intentionally left as-is.write-file-atomic(+@types) is also added by fix(desktop): save files atomically to prevent data loss on crash #4852 for the document save path; whichever merges first, the other's dependency addition is a no-op.Tests
test/unit/specs/buffer-store-durable.spec.ts: assertswriteBufferStoreFilewrites the state as JSON, overwrites cleanly, and leaves no temp file behind.typecheck,eslint, andbuild:unpack(confirming the new main-process import externalizes) all pass.