Skip to content

fix(daemon): status publication truncates the live file in place #834

Description

@PierrunoYT

Version / branch / commit

main at 097c2652cba22d929c598347aacc6f95591c9031

OS and environment

Static persistence review; applies on all supported platforms.

Steps to reproduce

  1. Run a daemon status reader concurrently with daemon startup/status publication.
  2. Arrange for the reader to open the status file after truncation but before os.WriteFile completes, or interrupt the process after truncation.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions