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
Write Host Rule Files Atomically in global_rules.py #4317
host-setup/agent-safety/global_rules.py writes each host-wide rule file in place. An interrupt that lands after the file is truncated and before the write completes leaves the file truncated. Since #4305 the script raises KeyboardInterrupt on SIGINT and SIGTERM, but the window predates that change. The rule files hold the maintainer's own host rules beside the kit's marked block, so a truncation can lose content no install restores.
CodeRabbit raised this on the promotion #4315 as an outside-diff finding, at global_rules.py:211.
Done looks like
Each persistent rule-file write goes to a temporary file in the target's directory, then os.replace swaps it in. A target that is a symlink, such as a dotfiles link, keeps its link: the write resolves the link and replaces the file it points at.
A test interrupts a write and shows the original file intact.
The fix edits host-setup/agent-safety/, so it needs the maintainer's approval on this issue before an attended run implements it.
Sibling in the same kit: CodeRabbit raised the same in-place truncation on #4324 as an outside-diff finding. It sits in the shared persistent writer _write_open_file in host-setup/agent-safety/claude/install.py, which calls os.ftruncate and then rewrites in place. An interrupt between the two leaves settings.json empty or partial. The writer predates #4324, which only adds one more caller to it. This issue's fix should cover both files, with the same temp-beside-target plus os.replace shape, the same symlink preservation, and the same interrupted-write test.
Maintainer approval, 2026-11-21: approved for an attended run, covering both files: host-setup/agent-safety/global_rules.py and the shared persistent writer in host-setup/agent-safety/claude/install.py. Each write goes to a temp file beside the target and is then swapped in with os.replace. Symlinks are preserved, and an interrupted-write test shows the original intact.
Backlog burndown claim (round 3, 2026-11-22): branch burndown/rule-files-atomic-write. Predicted files: host-setup/agent-safety/global_rules.py, host-setup/agent-safety/claude/install.py, tests/test_global_rules.py, host-setup/agent-safety/claude/test_install.py. No other group may edit these files while this claim stands.
Activity
ptr727 commentedon Nov 21, 2026
Sibling in the same kit: CodeRabbit raised the same in-place truncation on #4324 as an outside-diff finding. It sits in the shared persistent writer
_write_open_fileinhost-setup/agent-safety/claude/install.py, which callsos.ftruncateand then rewrites in place. An interrupt between the two leavessettings.jsonempty or partial. The writer predates #4324, which only adds one more caller to it. This issue's fix should cover both files, with the same temp-beside-target plusos.replaceshape, the same symlink preservation, and the same interrupted-write test.ptr727 commentedon Nov 21, 2026
Maintainer approval, 2026-11-21: approved for an attended run, covering both files:
host-setup/agent-safety/global_rules.pyand the shared persistent writer inhost-setup/agent-safety/claude/install.py. Each write goes to a temp file beside the target and is then swapped in withos.replace. Symlinks are preserved, and an interrupted-write test shows the original intact.ptr727 commentedon Nov 22, 2026
Backlog burndown claim (round 3, 2026-11-22): branch
burndown/rule-files-atomic-write. Predicted files:host-setup/agent-safety/global_rules.py,host-setup/agent-safety/claude/install.py,tests/test_global_rules.py,host-setup/agent-safety/claude/test_install.py. No other group may edit these files while this claim stands.Write Kit Files Atomically Through a Temporary File Beside Each Target (