state: Save syncs the state file before renaming it into place (closes #264) #276

Merged
clawbot merged 1 commits from fix/264-sync-state-save into next 2026-10-13 18:27:31 +02:00
1 Commits
Author SHA1 Message Date
sneak c2b3cd4904 state: Save syncs the state file before renaming it into place (closes #264)
check / check (push) Waiting to run
Save wrote state.json.tmp with os.WriteFile and renamed it over
state.json without syncing. After a power loss the rename could reach
the disk before the data, leaving an empty state.json that Load cannot
parse, so every start failed.

Save now writes the temp file through its own handle, syncs and closes
it, renames it, then syncs the data directory so the rename is on disk
too. The new test starts from a leftover temp file longer than the
state; a test cannot observe the syncs, which are confirmed by reading.

Rule suppressed: gosec's file-path warning on the temp file's open, as
Load already does.

Model: opus-5-5
2026-10-13 16:06:53 +00:00