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
Recognize the Installer's Own Partial CLAUDE.md Rather Than Backing It Up as a Hand Edit - #2493
When the installer left CLAUDE.md holding bytes it wrote itself, the next run read that file as a hand edit. It backed the file up as "the edited prior file", and --report said it "was edited since the last install". Issue #2454 names two states that reach this, and this change closes both.
A file this run created.write_regular_file opens exclusively first, so it can tell a file it created from one it found. A path that is a link always counts as found. When the write fails, the created file is removed, but only where the path still holds the same device and inode. The path is then left absent, as it was found.
A write cut short on a file that existed.record_leftover_instructions reads the leftover back. Where it is a byte prefix of the render or of the prior content this run wrote, the leftover's digest goes into a stamp that passes its shape check, together with instructionsLeftover: true. The function then reads the stamp back, and the error carries a note only where the stamp does not hold that digest.
Report.--report names a stamped leftover as what an install left when its write failed, separately from an earlier render and from a hand edit. A completed install writes a fresh stamp, which drops the flag.
…t Up as a Hand Edit
A CLAUDE.md write cut short left bytes no stamp vouched for, so the next run
backed them up as a hand edit and --report called the file edited.
- write_regular_file opens exclusively first, and removes a file it created
when the write fails, so the path is left absent as it was found.
- When the CLAUDE.md write is left incomplete, the installer stamps the
digest of what it left, where a stamp passing its shape check exists.
Fixes#2454.
The bare raise inside the unlink handler re-raised the unlink's error, so a
write cut short on a file it could not remove read as nothing installed.
- A path that is a link counts as found whatever the exclusive open did, so
the cleanup never removes a dotfiles link.
- The report names an earlier render or leftover as the installer's own
output rather than as the file the last install wrote.
Part of #2454.
Reading CLAUDE.md back after a failed write could stamp a save that landed
in between, which the next run would then replace with no backup.
- The leftover is stamped only where it is a prefix of the render or of the
prior content the run wrote, so replacing it loses nothing.
- A stamp write left incomplete is named in the error, since the re-run then
backs CLAUDE.md up as a hand edit.
- The write primitive's docstring names every case that raises
IncompleteWrite, and two descriptions of the stamped file name a leftover.
Part of #2454.
- The cleanup compares the path's device and inode with the descriptor's
before removing it, so a file another writer put there stays.
- record_leftover_instructions reads the stamp back after its write and
notes a failure only where the stamp does not hold the leftover's digest.
- A stamped leftover carries instructionsLeftover, so the report names a
write that failed rather than a render that changed.
Part of #2454.
- A KeyboardInterrupt or SystemExit during a created file's write is
re-raised even where the cleanup fails.
- A created file that was removed, or was already gone, is reported as no
longer existing, with the write's own cause, and the CLAUDE.md message no
longer asks to move aside a file that is not there.
- IncompleteWrite's docstring covers every raise site, and
_remove_if_same_file's says the comparison narrows the window.
- A test leaves a leftover of the prior content alone, so the restore branch
of the prefix check is covered.
Part of #2454.
- A close that fails while an interrupt propagates no longer replaces the
interrupt with IncompleteWrite.
- Where removing a created file fails after the write was left incomplete,
the error names both, so a file another writer put at the path is not
reported as this run's own leftover.
- The swap and removal tests act once the descriptor is closed, since
Windows refuses both on a file this process holds open.
Part of #2454.
- main's refusal says "could not be written" where no CLAUDE.md existed,
and the created-file-removed error no longer repeats the path the caller
already names.
- record_leftover_instructions' docstring says a leftover that cannot be
read back gets no note.
Part of #2454.
[P2] Keep created-file setup inside the cleanup scope. After O_EXCL succeeds, os.path.islink(path) runs before the try that closes and cleans up fd. A KeyboardInterrupt in this call, or in the initial fstat below, leaves the descriptor and newly created empty file behind, so the next run can classify it as a hand edit. Move the post-open identity checks into the same cleanup-protected path.
Preserve original write errors when cleanup fails
host-setup/agent-safety/claude/install.py:512
[P2] Preserve the original write error when cleanup also fails. For an ordinary write error, this branch reports only unlink_error in the exception text, while main prints that text and never prints __cause__. The operator therefore cannot see the failure that caused the partial file. Include e in this message, as the IncompleteWrite branch does.
Handle missing stamp separately from stamp-write errors
host-setup/agent-safety/claude/install.py:715
[P2] Do not report an expected missing stamp as a stamp-write error. On a first install that fails while writing CLAUDE.md, read_regular_file(stamp_path) raises FileNotFoundError, and this catch includes it in why, producing a misleading note. Handle FileNotFoundError separately and leave why empty.
Copilot's round 2 on cdd698e named three findings in its overview with no thread: install.py:492 (the interrupt window around the post-open islink and fstat calls), install.py:512 (a created file that cannot be removed is reported with only the removal failure) and install.py:715 (the leftover note includes a missing stamp's FileNotFoundError). All three are deferred to #2499, as items 4, 2 and 3, which was filed from this PR's own local review before the round landed. The maintainer chose to land the fix on its recorded pass and settle these messages together there.
….md (#2502)
## Summary
Promotes one change from `develop`:
- #2493: the agent-safety installer recognizes its own partial
`CLAUDE.md` rather than backing it up as a hand edit.
- A file the write primitive created is removed again when its write
fails, where the path still holds that file.
- A cut-short `CLAUDE.md` write stamps what it left, when those bytes
are a prefix of what the run wrote. The next run then replaces the file
without a backup, and `--report` names it as a failed write rather than
an edit.
Closes#2454.
## Verification
- `test_install.py` passed, 155 tests, on Linux, and every check on
#2493 passed.
- The issue's reproduction runs as a test under a real 4096-byte
file-size limit.
- Follow-ups filed from the review: #2494 (Windows-native identity
check), #2498 (a pre-existing stage-order gap) and #2499 (message
wording).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
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
When the installer left
CLAUDE.mdholding bytes it wrote itself, the next run read that file as a hand edit. It backed the file up as "the edited prior file", and--reportsaid it "was edited since the last install". Issue #2454 names two states that reach this, and this change closes both.write_regular_fileopens exclusively first, so it can tell a file it created from one it found. A path that is a link always counts as found. When the write fails, the created file is removed, but only where the path still holds the same device and inode. The path is then left absent, as it was found.record_leftover_instructionsreads the leftover back. Where it is a byte prefix of the render or of the prior content this run wrote, the leftover's digest goes into a stamp that passes its shape check, together withinstructionsLeftover: true. The function then reads the stamp back, and the error carries a note only where the stamp does not hold that digest.--reportnames a stamped leftover as what an install left when its write failed, separately from an earlier render and from a hand edit. A completed install writes a fresh stamp, which drops the flag.Part of #2454.
Verification
python3 -m unittest test_install: 150 tests, OK, on Linux.RLIMIT_FSIZE. The report no longer says the file was edited, and the re-run writes no backup.ruff,prose_lint.py --diff(sentence-length included) andrepo_gate.py --check eolare clean.local-strict-review: four passes. The fourth is recorded, and it raised the findings listed below.Local Review Findings and Their Dispositions
The first push's recorded pass raised 7 findings. Copilot's first round raised 6, which overlapped with them.
IncompleteWrite's docstring covers every raise site.lstat-then-unlinkcleanup is best effort, and its docstring says it narrows the window rather than closing it.fstatandlstatagree on file identity.🤖 Generated with Claude Code