Skip to content

Recognize the Installer's Own Partial CLAUDE.md Rather Than Backing It Up as a Hand Edit - #2493

Merged
ptr727 merged 8 commits into
developfrom
fix/installer-own-partial-claude-md
Oct 7, 2026
Merged

ptr727 merged 8 commits into
developfrom
fix/installer-own-partial-claude-md

Conversation

@ptr727

@ptr727 ptr727 commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

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.

Part of #2454.

Verification

  • python3 -m unittest test_install: 150 tests, OK, on Linux.
  • Issue Recognize the Installer's Own Partial CLAUDE.md Rather Than Backing It Up as a Hand Edit #2454's reproduction runs as a test under a real 4096-byte RLIMIT_FSIZE. The report no longer says the file was edited, and the re-run writes no backup.
  • Each new test was run against the code it guards with that code reverted or mutated, and failed there.
  • ruff, prose_lint.py --diff (sentence-length included) and repo_gate.py --check eol are 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.

🤖 Generated with Claude Code

ptr727 added 4 commits October 7, 2026 11:05
…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.
Copilot AI lite review requested due to automatic review settings October 7, 2026 18:44
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0a75985-1ab1-488d-a882-24f083f95e2a
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.50%. Comparing base (3582087) to head (b2cb996).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2493   +/-   ##
========================================
  Coverage    58.50%   58.50%           
========================================
  Files           16       16           
  Lines         8066     8066           
========================================
  Hits          4719     4719           
  Misses        3347     3347           
Flag Coverage Δ
python-3.13 58.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical cleanup, exception-handling, and ownership-race issues remain unresolved.

6 open findings
What changed in this PR

This PR updates the Claude installer to recognize and report its own partial CLAUDE.md output instead of treating it as a hand edit.

Changes:

  • Tracks and cleans up newly created files after failed writes.
  • Stamps recognizable partial leftovers.
  • Adds regression tests for write failures, reporting, and backups.
File Summary Findings
host-setup/​agent-safety/​claude/​test_install.py Adds coverage for partial writes, cleanup, stamping, and reporting. 1 moderate finding
host-setup/​agent-safety/​claude/​install.py Implements partial-write tracking, cleanup, stamping, and report classification. 3 critical and 3 additional findings

🧠 Review effort: Lite


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

ptr727 added 2 commits October 7, 2026 11:56
- 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved cleanup and error-reporting issues remain, along with a test contract update.

1 open finding
6 resolved since last review
Previously missed (3)

In code that hasn't changed since last review

Medium severity Protect post-open checks with cleanup handling

host-setup/​agent-safety/​claude/​install.py:492

[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.

Medium severity 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.

Medium severity 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.

🧠 Review effort: Lite

@ptr727

ptr727 commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Address the three unresolved review findings before approval.

1 open finding
1 resolved since last review

🧠 Review effort: Lite

@ptr727
ptr727 merged commit e8aa6e4 into develop Oct 7, 2026
13 checks passed
@ptr727
ptr727 deleted the fix/installer-own-partial-claude-md branch October 7, 2026 19:42
ptr727 added a commit that referenced this pull request Oct 7, 2026
….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)
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