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
fix(daemon): status publication truncates the live file in place #834
Static persistence review; applies on all supported platforms.
Steps to reproduce
Run a daemon status reader concurrently with daemon startup/status publication.
Arrange for the reader to open the status file after truncation but before os.WriteFile completes, or interrupt the process after truncation.
Observe empty/partial JSON, or loss of the previous valid status file.
Relevant code: internal/daemon/server.go:200-214.
writeStatusFile calls os.WriteFile directly on the final path. os.WriteFile truncates the existing file before writing the replacement.
Expected behavior
Readers should observe either the previous complete status or the new complete status. A failed/interrupted update should not destroy the previous valid document.
Actual behavior
Concurrent readers can observe invalid JSON, and interruption after truncation can leave the status file empty or partial.
Suggested fix and regression test
Write to a unique same-directory temporary file, sync/close it, atomically rename it over the final path, and sync the parent directory where supported.
Add a test with a coordinated reader during publication and fault injection before rename; assert readers never observe partial JSON and the old document survives failed publication.
Reported by PierrunoYT from a full codebase audit.
Confirmed on current main. writeStatusFile still calls os.WriteFile directly against s.opts.Paths.Status (internal/daemon/server.go:211), so the live file is truncated before the replacement lands and a reader in that window sees empty or partial JSON. An interrupt in the same window loses the previous valid status entirely.
Sorry for the wait. We want the fix, and it should be the temp-file-plus-rename pattern already used elsewhere in the tree (atomicWriteFile in internal/daemon/remote/sessionlink.go:78 is the shape). Send the PR.
Approved. Verified at internal/daemon/server.go:211 — the status file is written with os.WriteFile, which opens O_TRUNC on the live path. A reader arriving mid-write sees empty or partial JSON, and an interrupted process leaves no previous valid status behind.
The fix is the usual one: write a sibling temp file and rename over the target, so readers only ever observe a complete document.
Activity
Vasanthdev2004 commentedon Aug 5, 2026
Confirmed on current main.
writeStatusFilestill callsos.WriteFiledirectly againsts.opts.Paths.Status(internal/daemon/server.go:211), so the live file is truncated before the replacement lands and a reader in that window sees empty or partial JSON. An interrupt in the same window loses the previous valid status entirely.Sorry for the wait. We want the fix, and it should be the temp-file-plus-rename pattern already used elsewhere in the tree (
atomicWriteFileininternal/daemon/remote/sessionlink.go:78is the shape). Send the PR.Vasanthdev2004 commentedon Aug 12, 2026
Approved. Verified at
internal/daemon/server.go:211— the status file is written withos.WriteFile, which opensO_TRUNCon the live path. A reader arriving mid-write sees empty or partial JSON, and an interrupted process leaves no previous valid status behind.The fix is the usual one: write a sibling temp file and rename over the target, so readers only ever observe a complete document.