Skip to content

Write -Report atomically instead of truncating in place - #28

Merged
amrali-eg merged 1 commit into
masterfrom
fix/atomic-report-write
Sep 17, 2026
Merged

amrali-eg merged 1 commit into
masterfrom
fix/atomic-report-write

Conversation

@amrali-eg

Copy link
Copy Markdown
Owner

Summary

  • Ported from EncodingChecker's BL-24 fix (AtomicArtifactFile) — found by scanning EC's closed defect ledger for gaps LEN's smaller codebase could share.
  • The report writer truncated its destination immediately (StreamWriter with append: false), so an interrupted write left the report empty or half-written, destroying whatever prior report was already there.
  • Extracts Program.WriteArtifactAtomically(path, Action<Stream>): writes a complete temporary file beside the destination (reusing LEN's existing LosslessFileWriter.AtomicReplace, now internal) and replaces the old one only after that write succeeds. TryWriteReportFile is now a thin wrapper supplying the CSV content.

Test plan

  • 4 new tests in AtomicReportWriteTests.cs, mirroring EC's own AtomicArtifactFileTests.cs
  • Mutation-tested: reverted to a truncate-in-place implementation, confirmed a prior report was wiped to empty on a forced write failure, then reverted
  • Full suite: 316/316 (312 existing + 4 new)
  • Smoke-tested via the built exe: a prior report survives, the new one replaces it, no leftover temp file

🤖 Generated with Claude Code

Ported from EncodingChecker's BL-24 fix (AtomicArtifactFile). The
report writer truncated its destination immediately (StreamWriter
append: false), so an interrupted write left the report empty or
half-written, and destroyed whatever prior report was already there.

Extracts Program.WriteArtifactAtomically(path, Action<Stream>): writes
a complete temporary file beside the destination (using LEN's existing
LosslessFileWriter.AtomicReplace, now internal) and replaces the old
one only after that write succeeds. TryWriteReportFile is now a thin
wrapper supplying the CSV content.

Verified: 4 new tests in AtomicReportWriteTests.cs, mirroring EC's
AtomicArtifactFileTests.cs. Mutation-tested by reverting to a
truncate-in-place implementation - confirmed a prior report was wiped
to empty on a forced write failure, then reverted. Full suite 316/316
(312 existing + 4 new). Smoke-tested via the built exe: a prior report
survives, the new one replaces it, no leftover temp file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@amrali-eg
amrali-eg merged commit 322e996 into master Sep 17, 2026
1 check passed
@amrali-eg
amrali-eg deleted the fix/atomic-report-write branch September 17, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant