Skip to content

Use atomic writes for config file saves - #13

Merged
thrr87 merged 1 commit into
mainfrom
claude/fix-cli-concurrency-issues-0QGDO
Feb 6, 2026
Merged

thrr87 merged 1 commit into
mainfrom
claude/fix-cli-concurrency-issues-0QGDO

Conversation

@thrr87

@thrr87 thrr87 commented Feb 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implement atomic writes for config file operations to prevent corruption from incomplete writes. The changes use a temporary file with os.fsync() to ensure data is written to disk before atomically replacing the target config file with os.replace().

This improves reliability when saving configuration, especially in scenarios with:

  • Sudden process termination
  • Filesystem errors during write
  • Concurrent access to config files

The ensure_config_file() function now delegates to save_config() to use the same atomic write mechanism.

Testing

  • python -m pytest

Notes

  • Uses tempfile.mkstemp() to create a temporary file in the same directory as the target config file, ensuring they're on the same filesystem for atomic os.replace()
  • Includes proper cleanup of temporary files in exception handlers
  • The atomic write pattern is now consistent across all config save operations

Prevents partial writes and corruption of config.yaml when the process
is interrupted mid-write or multiple CLI processes race on the same file.

https://claude.ai/code/session_01JKkksiVQuP5HJVUshkmRS6
@thrr87
thrr87 merged commit dac3042 into main Feb 6, 2026
1 check passed
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.

2 participants