You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A power loss or OS crash during SaveAsync can leave a zero-length profiles.json: temp files are renamed into place without being flushed to disk (gap in #157) #237
The temp file's data is never flushed to stable storage before the rename. There is no FileStream.Flush(flushToDisk: true) and no FileOptions.WriteThrough. That covers a process crash, but not a power loss or kernel crash. On XFS, btrfs, ext4 with noauto_da_alloc, and other filesystems, the rename can reach the disk before the file's data does, which is the well-known zero-length-file-after-rename failure. #157 named "a crash or power loss" as the failure to prevent, and the class remarks promise the file is "never a truncated one".
If this happens to profiles.json, every profile is lost. The next load sees an empty file, treats it as corrupt and moves it aside, but the moved-aside copy is empty too, so nothing can be recovered.
Evidence
Tracing the file-sync and rename system calls during one SaveAsync:
There is no fsync or fdatasync before any of the renames. (Power loss itself wasn't simulated; the gap shows in the system-call trace.)
Suggested fix / acceptance criteria
Write the temp file through a FileStream and call Flush(flushToDisk: true) before disposing it, or open it with FileOptions.WriteThrough. Then do the File.Move.
On Unix, optionally fsync the containing directory after the rename so the rename itself is durable.
Check the fix with a strace, or with a test using an injected writer, showing the data flushed before the rename. The existing Saves_LeaveNoTemporaryFilesBehind test should still pass.
Next step: Write the temp file through a FileStream and call Flush(flushToDisk: true), or open it with WriteThrough, before the move. Optionally fsync the directory on Unix. Verify with strace or an injected-writer test.
Activity
matt-edmondson commentedon Nov 8, 2026
Triage
JsonKeybindingRepository.WriteFileUnlockedAsync, in the temp-write-then-File.Movepath.FileStreamand callFlush(flushToDisk: true), or open it withWriteThrough, before the move. Optionally fsync the directory on Unix. Verify with strace or an injected-writer test.Generated by Claude Code