Repository navigation
Conversation
Rolling back a failed operation unlinked each changed file and recreated it from its snapshot with shutil.copy2. The new file took the restoring user as owner and the directory's default permissions, which on Windows replaces a restricted file's access-control list with inherited entries. The journal now records the (st_dev, st_ino) of each regular file it snapshots. When that same file is still at the path, rollback opens it without truncating or following links, checks the opened file is the snapshotted one, then truncates it, writes the snapshot bytes back and restores mode and times with copystat. A file that was removed or replaced by another file, a symlink or a directory, or that cannot be opened for writing, is recreated as before. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
Rolling back a file in place set its mode and times with copystat after closing it, which follows a symlink swapped in at that path. Set them through the open descriptor where the platform supports it, open with O_NONBLOCK so a FIFO swapped in cannot block the open, and record a snapshotted file's identity only when it did not change while the snapshot was taken. Cover the fallback to recreating a file rollback cannot open, and check the upgrade rewrote the file before failing. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
There was a problem hiding this comment.
🟡 Changes recommended
Rollback can redirect metadata updates to an unintended file, leave extended attributes altered, and abandon remaining recovery steps after metadata permission errors.
4 open issues
What changed in this PR
Updates integration lifecycle rollback to restore individually snapshotted files in place, aiming to preserve file identity, ownership, hard links, and Windows access-control lists. This follows #5402 and supports the rollback requirements for #5117.
Changes:
- Record regular-file identities during snapshot creation.
- Restore matching files in place, with recreation as a fallback.
- Add regression coverage for rewritten files, replacements, and open failures.
Validation was limited to isolated standard-library checks; project tests and Windows validation were not run.
AI-generated review for the requester by GitHub Copilot (model: unknown; autonomous).
| File | Description |
|---|---|
tests/specify_cli/integrations/test_lifecycle.py |
Tests recreation after file replacement or an in-place open failure. |
tests/specify_cli/integrations/test_command_upgrade.py |
Tests rollback preserving a rewritten file’s identity, bytes, and mode. |
src/specify_cli/integrations/_lifecycle.py |
Records snapshot identities and adds in-place file restoration. |
Review effort: Max (adaptive)
|
Please address Copilot feedback |
…stores Restoring a file in place now restores its user extended attributes (where the os module has an API for them, which in CPython means Linux), times and mode only through the verified descriptor. Windows, which has no descriptor form of os.utime, sets them by path while the open handle still pins that file; any other platform without a descriptor form leaves them. A refused or unavailable metadata change no longer aborts rollback: the bytes stay restored, each remaining attribute, entry and directory cleanup still runs, and the file is reported with the recovery snapshots retained. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
|
@mnriem I've addressed the four Copilot threads in c3f7e18.
Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🟡 Changes recommended
Rollback can overwrite replacement files after inode reuse and leave unintended access ACLs in place while incorrectly reporting complete recovery.
5 open issues
Restore POSIX access ACLs during rollback · New Prevent inode reuse from misidentifying replacement files · New Preserve macOS BSD file flags during rollback · New Ensure the test exercises descriptor timestamp refusal handling · New Document partial recovery and directory restoration boundaries · New
4 resolved since last review
Review effort: Max (adaptive)
Rollback now holds a read-only descriptor on each file it may restore in place (outside Windows, up to a quarter of the open-file limit), so an original the operation unlinked cannot lend its inode to a replacement that the identity check would then accept. A file without a pin, or whose pinned inode has no name left, is recreated from its snapshot as before. Windows files are not pinned, since an open file there cannot be replaced. The Linux POSIX access ACL is now restored with the user extended attributes, and BSD file flags that differ after an in-place restore are reported as incomplete with the snapshots retained, as Python has no descriptor form of chflags(). The shared CLI and API references describe the in-place, recreated and partially restored outcomes. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
A Linux or macOS file past the pin limit is still recreated rather than restored in place, but when it is still the snapshotted inode at rollback, so was probably rewritten in place, it is now reported with the recovery snapshots retained rather than silently losing its owner and links. A file the operation is removing is neither pinned nor restored in place. The access ACL is restored after the user attributes, as a read-only ACL would refuse them, archive and compression flags the filesystem changes on a write are no longer compared, the incomplete-restore warning names ownership, links and file flags, and closing one pin can no longer leave the others open. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
|
@mnriem I've addressed the five Copilot threads from the last round in 108d3d0 and 60be027.
Testing:
Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🟡 Changes recommended
Critical rollback races can overwrite concurrently replaced files or delete recovery snapshots even when the pathname no longer points to the restored file.
4 open issues
5 resolved since last review
Review effort: Max (adaptive)
…firmed restores An original file is now pinned before it is snapshotted, and the snapshot is read through the pin, so a file unlinked and recreated in the gap cannot reuse the inode and be taken for the original. After restoring a file in place, rollback rechecks that the path still names the restored file; if it was removed or replaced during the copy, the restore is reported incomplete and the recovery snapshot kept, and the concurrent replacement is left alone. A verified original that cannot be opened for writing and is recreated is now reported with its snapshot retained, as an unpinned one already was, since recreation loses its owner, links and access-control list. Adds tests for the modification time restored on success, the pin taken before the snapshot, a path replaced during restore, and snapshot retention when the open is refused. Assisted-by: Claude Code (model: claude-sonnet-5-5, autonomous)
|
Review round summary, commit 452fb85. Four Copilot review threads addressed:
Verification: Posted on behalf of @echarrod by Claude Code (model: claude-sonnet-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🟡 Changes recommended
Critical rollback defects can restore stale data and leave original contents or permissions unrecovered after path replacement, while warnings may incorrectly claim that contents were restored.
2 open issues
4 resolved since last review
Review effort: Max (adaptive)
|
Please address Copilot feedback |
… ACL-order test Patching os.listxattr also reordered shutil.copystat() when the journal snapshots the file. Python before 3.13 raises EACCES there once a read-only ACL is copied ahead of the user attributes, so the test failed on Python 3.11 before rollback ran. The test now reorders only what _restorable_xattrs() returns, which is what _restore_xattrs() sorts. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioAe4U3H3zhK3uAy6r
…removed parent A directory snapshotted after one of its journalled files was rewritten and then replaced read that file through its pin, so the snapshot held the old inode's bytes rather than the replacement. Rollback recreated the directory with those stale bytes, then reported the file as a conflict and left its original unrestored. A pin is now read only for the file's own first snapshot. The warning for an incomplete restore no longer says the contents came back: a path replaced while its bytes are restored still holds the replacement. It now says the file could not be fully restored, and the rollback docs say the same. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioAe4U3H3zhK3uAy6r
|
Review round summary for @mnriem. Head is now
Tests:
Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review. |
There was a problem hiding this comment.
🔵 Needs a closer look
Rollback can overwrite concurrent edits because its post-open check validates only file identity, while POSIX-only test hooks cause Windows tests to fail.
8 open issues
Inject decoy descriptor through FileHelper.open_rewrite on Windows Mock FileHelper.open_rewrite to test rollback-open failure on Windows Verify full file state after opening to prevent concurrent-edit truncation Preserve metadata baseline on duplicate after-notifications Use verified no-follow descriptor when changing root permissions Restore captured attributes after recreation or retain the sidecar Track non-automatic file flags when detecting metadata changes Test _pin_limit boundaries and getrlimit failure behavior
Review effort: Max (adaptive)
- FileHelper.rewrite_descriptor(fd, content) replaces an open file's content from offset 0, truncates after writing and flushes with the same write loop and F_FULLFSYNC policy as create_private_bytes, so a caller's in-place rewrite does not carry its own copy of either - design/file-helper.md documents it, and that create_private_bytes also refuses a file the filesystem gave to another uid - tests: replace from any offset, flush after writing, a write making no progress, and which F_FULLFSYNC errors are tolerated Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioDHJd7GtWMKZNgrHC
…-restore-in-place Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioDHJd7GtWMKZNgrHC # Conflicts: # design/file-helper.md
|
Round summary (head 6fea1bc): 6fea1bc merges the latest #5493 (59728c4, which adds Tests locally on macOS: file-helper, Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously. Claude Code wrote the code, tests and this summary. No line-by-line human review. |
…attributes - the in-place restore compares the opened file's whole state, not just its inode, so an in-place edit between the check and the open is kept as a conflict instead of truncated - a repeated after-notification with no write in between (record_existing after write_file_and_record) keeps the metadata the write left, so a mode changed in between is still kept as someone else's edit - BSD file flags set after the operation's write count as a metadata edit, ignoring the ones the filesystem sets on a write - a replaced file recreated from its snapshot gets its captured extended attributes back, pinned or not; if they cannot be set it is reported incomplete and its sidecar retained - FileHelper.chmod changes the root through a no-follow descriptor that must still be the root the helper was built on - the rollback-open and decoy tests patch FileHelper.open_rewrite, which Windows reaches through CreateFileW rather than os.open - tests for _pin_limit's quarter-limit, cap, unlimited and failure paths - tests for each fix, failing before the change; design docs updated Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioDHJd7GtWMKZNgrHC
|
Round summary (head bdb1d0b): bdb1d0b addresses the eight open review threads:
Tests: every new behaviour test fails with the previous Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously. Claude Code wrote the code, tests and this summary. No line-by-line human review. |
- an O_APPEND descriptor ignores the seek, so the truncate that follows cut the new bytes off; it is now refused with EINVAL before anything is written, and the contract is limited to open_rewrite descriptors - tests: the append-mode refusal (fails before the change), short writes retried by rewrite_descriptor and create_private_bytes, and a short write followed by an error removing the private file Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioDHJd7GtWMKZNgrHC
…-restore-in-place Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WioDHJd7GtWMKZNgrHC # Conflicts: # design/file-helper.md
There was a problem hiding this comment.
🔵 Needs a closer look
Unresolved critical defects allow rollback to overwrite concurrent edits and lose original attributes, permit permission changes outside the helper’s root, and cause Windows test failures.
No open issues 🎉
8 resolved since last review
Inject decoy descriptor through FileHelper.open_rewrite on Windows Mock FileHelper.open_rewrite to test rollback-open failure on Windows Verify full file state after opening to prevent concurrent-edit truncation Preserve metadata baseline on duplicate after-notifications Use verified no-follow descriptor when changing root permissions Restore captured attributes after recreation or retain the sidecar Track non-automatic file flags when detecting metadata changes Test _pin_limit boundaries and getrlimit failure behavior
Review effort: Max (adaptive)
There was a problem hiding this comment.
🟡 Changes recommended
Opening the root with O_RDONLY unnecessarily requires directory-read access, preventing the owner from restoring permissions after setting the directory to 0o300 even though native chmod succeeds.
1 open issue
Review effort: Max (adaptive)
FileHelper.chmod on the root opened it O_RDONLY, which needs read access
that native chmod does not. After chmod(".", 0o300) the owner could not
restore 0o700 through the helper. The root is now changed through the
search-only (or O_PATH) descriptor pinned at construction, falling back to
its /proc/self/fd entry where Linux refuses fchmod on O_PATH. The root's
path must still lstat as the established root, so a root renamed and
replaced since construction is still refused.
Assisted-by: Claude Code (model: claude-opus-5-5, autonomous)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015w5WipyxRcrpJi6SbAGTJR
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because critical rollback races and I/O-failure paths can overwrite concurrent edits, erase file contents, or broaden access permissions.
No open issues 🎉
1 resolved since last review
Review effort: Max (adaptive)
There was a problem hiding this comment.
🟡 Changes recommended
Rollback can silently broaden access by skipping restoration of empty ACL states or overwriting concurrent permission restrictions, while pinned snapshots can exceed the journal’s memory budget.
3 open issues
Review effort: Balanced
| if path in self.pending or path not in self.written_metadata: | ||
| self._remember_written(path) |
There was a problem hiding this comment.
Not changed, and I'm leaving this open for a maintainer to decide.
I tried the suggested guard: refuse a before-write when metadata_changed() is true. It made 18 existing tests fail, including test_recovery_without_ownership_modes_preserves_unproven_paths and the test_damaged_event_adapter_recovery_* cases. In each one the mode change between the two writes comes from the operation itself. During install_integration_events, setup sets events.py executable (0o644 to 0o755) and then calls record_file() on it, so its before-write hits the guard. The journal cannot tell that chmod apart from one made by another writer, so the guard turns ordinary installs into hard failures.
To close this window properly, the operation's own chmods would also need to be journalled. That changes what external adapters can do (write, chmod, then record), and it goes beyond this PR. The existing protection still applies after the operation's last write: rollback keeps a metadata-only edit made after that write as a conflict.
Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review.
|
Please address Copilot feedback and fix test & lint errors |
…butes, restore empty sets - the in-place restore compared the opened handle's fstat with a path stat; on Windows fstat reports the metadata-change time as st_ctime and a path stat the creation time, so every in-place restore there was kept as a conflict and its snapshot retained. It now re-stats the opened file by path and confirms it is the same file - a pinned snapshot reads its attributes once, through the pin, charged to the snapshot budget as they are read, and keeps that capture instead of reading them unbudgeted to copy and again to record - a recreated file whose original had no restorable attributes has the ones it inherited (a default ACL's access ACL) removed, rather than skipping an empty capture - tests: each fails before the change Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WisnsWbfoqQHWaDzRhH
…endings Both seeded or edited files whose line ending Windows text mode writes as CRLF, so a same-size edit left a stray LF and the assertions failed there once the in-place restore ran on Windows. The same-size case now seeds bytes, and the edit before the restore opens overwrites only the word. Assisted-by: Claude Code (model: claude-opus-5-5, autonomous) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015w5WisnsWbfoqQHWaDzRhH
|
Round summary (head e5cfa38): 86068a2 and e5cfa38 fix the failing pytest job and two of this round's three review threads:
Evidence: on macOS, the full suite has 17605 passed and 275 skipped. The one local failure, Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review. Analysis, code and tests are AI-generated. |
|
Please address Copilot feedback |



Description
Follow-up to #5402, and a prerequisite for #5117. When a built-in
initorupgradefails and the lifecycle journal rolls back,_restore_snapshots()deleted each snapshotted file and recreated it withshutil.copy2. The bytes came back, but a recreated file is a new file. On Windows it loses its access-control list and can inherit broader permissions from its directory. On POSIX it loses its owner and any hard links. Copilot raised this on #5117 (#5117 (comment)): itsopenai.yamlrewrite keeps the file's ACL in place, but a rollback through the journal would undo that.The journal now records each snapshotted file's identity (device and inode), but only when the file did not change while it was being snapshotted. On rollback, if that same file is still at the path, it is opened without following links (and without blocking on a FIFO). Rollback checks that it is still the same file, then writes the original bytes back in place. Mode and times are restored through the open descriptor, so a swapped-in symlink cannot redirect them. A file that was removed, replaced, or cannot be opened is recreated exactly as before.
Limit: files inside a snapshotted directory are still deleted and recreated. Only individually snapshotted files are restored in place.
Testing
test_builtin_upgrade_rollback_restores_a_rewritten_file_in_place(tests/specify_cli/integrations/test_command_upgrade.py) hard-links a customisedSKILL.md, then makesintegration upgrade --forcefail after the file has been rewritten. It checks that the original bytes and mode are back and that it is the same file. The test fails onmainand passes with this change.tests/specify_cli/integrations/test_lifecycle.pyadds two tests. A file that the operation replaced is recreated, not written through. A file that rollback cannot open falls back to being recreated.Full suite on macOS: 16801 passed, 616 skipped, 1 failed. The failure,
test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, also fails onmainlocally: the long venv path wraps in the output.uvx ruff@0.15.0 check src testsandgit diff --checkare clean.I could not test Windows ACLs directly. That they are kept follows from the file keeping its identity, which the tests check.
Tested locally with
.venv/bin/specify --help(Windows PowerShell:.\.venv\Scripts\specify.exe --help)Ran relevant existing tests with
.venv/bin/python -m pytest tests -q(Windows PowerShell:.\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks andLC_ALL=en_US.UTF-8on macOSTested with a sample project (if applicable)
AI Disclosure
AI disclosure: Claude Code (model: claude-opus-5-5), running autonomously. The agent wrote the code, the tests and this description, and ran a
/code-reviewpass on the change. No line-by-line human review before opening.🤖 Generated with Claude Code
https://claude.ai/code/session_015w5Wio5NK7XbSPGaMEKqVe
Depends on #5493. This branch merges #5493 and moves its rollback I/O onto the public
FileHelperAPI it adds (stat,open_rewrite,create_private_bytes), plusopen_read,utimeandchmodadded here, so the FileHelper migration guard passes. It should merge after #5493.