refactor: consolidate atomic-file-write helpers#430
Merged
tomasz-tomczyk merged 1 commit intomainfrom May 2, 2026
Merged
Conversation
Three independent atomic-write helpers had drifted across the codebase. Consolidate them into a single canonical helper in atomic_write.go. - Move atomicWriteFile from daemon.go to a dedicated atomic_write.go (no behavior change, better location — it's used by review files, config, sessions, plans, and aider integration). - Delete writeFileMkdirAtomic in aider_install.go. Replace its three call sites with atomicWriteFile(path, data, 0o644). The old helper hardcoded perm via O_CREATE flags and skipped Chmod; canonical helper now guarantees 0o644 regardless of umask. - Rewrite plans.savePlanSessions to use atomicWriteFile instead of inline os.WriteFile + os.Rename. This adds the missing fsync — a real durability bug. Without fsync between rename and the kernel flushing the data block, a power loss left a zero-byte file at the target (the inode rename committed but the data did not). The advisory flock around the function is preserved. - Drop redundant os.MkdirAll in saveCritJSON; atomicWriteFile already creates the parent directory. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (19.35%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #430 +/- ##
==========================================
+ Coverage 67.18% 67.35% +0.16%
==========================================
Files 29 30 +1
Lines 9814 9785 -29
==========================================
- Hits 6594 6591 -3
+ Misses 2698 2681 -17
+ Partials 522 513 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2 tasks
tomasz-tomczyk
added a commit
that referenced
this pull request
May 5, 2026
…ode (#464) - installOneFile: use atomicWriteFile (consistent with all other writes post-#430) - aider_install: collapse byte-identical force/!force write branches - cli_install: fix order-sensitive flag parsing (--force before agent name now works) - main: remove dead _ = keys[i] (pre-existing leftover) - share: delete test-only buildLocalFingerprints shim; tests now call buildLocalFingerprintIndex directly - cli_serve: add comment clarifying bindListener retry semantics (explicit port retries, ephemeral fails fast)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three independent atomic-file-write helpers had drifted across the codebase. This PR consolidates them into one canonical helper and fixes a real durability bug along the way.
atomicWriteFilefromdaemon.goto a dedicatedatomic_write.go. No behavior change — better location, given it's used by review files, config, sessions, plans, and aider integration.writeFileMkdirAtomicinaider_install.go. Replace its three call sites withatomicWriteFile(path, data, 0o644). The old helper hardcoded perm viaO_CREATEflags and skippedChmod; the canonical helper now guarantees0o644regardless of umask.plans.savePlanSessions: was using inlineos.WriteFile + os.Renamewith nofsync. On power loss between the rename and the kernel flushing the data block, the inode rename committed but the data did not — leaving a zero-byte plan-sessions file at the target. Now routes throughatomicWriteFile(temp + write + fsync + rename). The advisoryflockaround the function is preserved.os.MkdirAllinsaveCritJSON—atomicWriteFilealready creates the parent directory.Hidden assumptions verified
writeFileMkdirAtomic's call sites (CONVENTIONS.md, .aider.conf.yml) only ever wanted0o644. No executables, so no perm regression.MkdirAll(0o755); canonical uses0o700. Parent dirs (./.crit/,~) already exist in practice — no observable change..tmp.<pid>toos.CreateTemprandom suffix. TestTestAiderInstallAtomicWrite_CleansUpTempfileupdated to assert no.tmpsiblings remain.Review
gofmt -l .cleangolangci-lint run ./...— 0 issuesgo vet ./...cleango test -race -count=1 ./...passes (54.8s)Test plan
daemon_test.goatomicWriteFiletests still pass (unchanged surface)plans_test.go🤖 Generated with Claude Code