Skip to content

fix(integrations): restore a rewritten file in place on rollback - #5470

Open
echarrod wants to merge 43 commits into
github:mainfrom
echarrod:fix/rollback-restore-in-place
Open

echarrod wants to merge 43 commits into
github:mainfrom
echarrod:fix/rollback-restore-in-place

Conversation

@echarrod

@echarrod echarrod commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #5402, and a prerequisite for #5117. When a built-in init or upgrade fails and the lifecycle journal rolls back, _restore_snapshots() deleted each snapshotted file and recreated it with shutil.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)): its openai.yaml rewrite 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 customised SKILL.md, then makes integration upgrade --force fail 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 on main and passes with this change.

  • tests/specify_cli/integrations/test_lifecycle.py adds 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 on main locally: the long venv path wraps in the output. uvx ruff@0.15.0 check src tests and git diff --check are 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 and LC_ALL=en_US.UTF-8 on macOS

  • Tested with a sample project (if applicable)

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

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-review pass 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 FileHelper API it adds (stat, open_rewrite, create_private_bytes), plus open_read, utime and chmod added here, so the FileHelper migration guard passes. It should merge after #5493.

echarrod and others added 2 commits November 17, 2026 22:39
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
@echarrod
echarrod requested a review from mnriem as a code owner November 17, 2026 22:43
Copilot AI adaptive review requested due to automatic review settings November 17, 2026 22:43

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

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)

@mnriem

mnriem commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 17, 2026
…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
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 09:57
@echarrod

Copy link
Copy Markdown
Contributor Author

@mnriem I've addressed the four Copilot threads in c3f7e18.

  • In-place rollback now restores mode, times and user.* extended attributes only through the verified descriptor. Windows has no descriptor os.utime, so there the times are set by path while the open handle still pins the file. Anywhere else without descriptor support, the metadata is left alone.
  • A metadata change that is refused or unavailable no longer aborts rollback. The bytes stay restored, every other attribute, entry and directory cleanup still runs, and the file is reported in a separate warning with the recovery snapshots kept.
  • New tests in tests/specify_cli/integrations/test_lifecycle.py cover the metadata refusal, the symlink swapped in without descriptor support, a descriptor that opens a different file, and extended attributes. The extended-attribute tests run only on Linux, and I ran them in a container. A Windows-only test checks the handle-pinning assumption; I could not run it locally, so Windows CI is its first run. All of these except the different-file test fail on a9463b7 and pass now. The different-file test covers a guard that already existed, so it can only fail when that guard is removed.
  • Full suite on macOS: 16804 passed, 619 skipped and 1 failed. The failure is test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, which happens only on my machine and is not related to this change. ruff check is clean.

Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review.

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.

echarrod and others added 2 commits November 18, 2026 11:08
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
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 11:24
@echarrod

Copy link
Copy Markdown
Contributor Author

@mnriem I've addressed the five Copilot threads from the last round in 108d3d0 and 60be027.

  • Rollback now keeps a read-only descriptor open on each file it may restore in place, so an original that was unlinked cannot lend its inode to a replacement. It does this outside Windows, for up to a quarter of the open-file limit and at most 1024 files. A file without a pin, or whose pinned inode has no name left, is recreated from its snapshot. If such a file still has its original inode, it was probably rewritten in place, so it is reported with the recovery snapshots retained. A file the operation is removing is never restored in place.
  • The Linux POSIX access ACL is now captured and restored along with the user.* attributes, and an ACL the operation introduced is removed. Both changes go through the verified descriptor, and the ACL is applied after the user attributes, since a read-only ACL would refuse them.
  • BSD file flags that differ after an in-place restore are reported as an incomplete restore, and the snapshots are kept. Flags the filesystem changes on a write (UF_COMPRESSED on macOS, UF_ARCHIVE on FreeBSD and DragonFly) are ignored. The warning now names ownership, links and file flags.
  • The timestamp-refusal test adds its wrapper to os.supports_fd, so it reaches the PermissionError handler. It fails with that handler removed.
  • The shared CLI and API references, and the _journalled docstring, now describe the in-place, recreated and partly restored outcomes.

Testing:

  • New tests: inode reuse without a link to the original, a file observed as removed and then rewritten, unpinned files that were rewritten or replaced, pin release on failure and on commit, a copy2 from an older template, access ACLs (introduced and changed), ACL ordering and BSD flags.
  • Linux (Debian container, ext4 volume, non-root): all of them run, and tests/specify_cli/integrations has 1316 passed and 3 skipped. The inode-reuse, ACL and removal tests fail on c3f7e18. The ordering test fails only when the ACL-last ordering is removed, and lists the ACL first because ext4 always lists user.* first.
  • macOS: the flag tests fail on c3f7e18. The full suite has 16813 passed, 622 skipped and 1 failed. The failure is the same machine-specific test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer as before, and is not related to this change.
  • Windows: nothing has been run locally.
  • ruff check src tests (0.15.0) is clean.

Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review.

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.

…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)
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 14:44
@echarrod

Copy link
Copy Markdown
Contributor Author

Review round summary, commit 452fb85. Four Copilot review threads addressed:

  • _lifecycle.py pin ordering: the original file is now pinned before it is snapshotted, and the snapshot is read through that descriptor, so a file replaced in the gap cannot reuse the inode and be mistaken for the original. Test: test_builtin_journal_pins_a_file_before_snapshotting_it.
  • Path replaced during an in-place restore: after the copy, rollback checks that the path still names the restored file. If not, the restore is reported incomplete and the recovery snapshot is kept; the replacement is not overwritten. Test: test_builtin_journal_keeps_the_snapshot_when_the_path_is_replaced_during_restore.
  • Verified original that cannot be opened for writing: it is recreated as before, but is now reported with its snapshot retained, like an unpinned one. test_builtin_journal_recreates_and_reports_a_file_it_cannot_open_in_place covers the warning and retention.
  • Modification-time test: test_builtin_journal_restores_the_original_modification_time asserts the saved st_mtime_ns, the same inode, and no incomplete-restore warning.

Verification: uv run --extra test pytest tests gave 11738 passed, 291 skipped, 1 failed. The failure, test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, compares wrapped output that includes the long local worktree path; it is not touched by this change.


Posted on behalf of @echarrod by Claude Code (model: claude-sonnet-5-5), running autonomously; agent-written, no line-by-line human review.

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 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)

@mnriem

mnriem commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

echarrod and others added 2 commits November 19, 2026 10:33
… 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
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 11:00
@echarrod

Copy link
Copy Markdown
Contributor Author

Review round summary for @mnriem. Head is now abcd6641. It addresses both Copilot threads from 2026-11-18 and fixes the failing pytest job.

  • Failing test (test_builtin_journal_restores_user_attributes_before_a_read_only_access_acl, 0d612332): the test patched os.listxattr globally. That also reordered shutil.copystat() when the journal snapshots the file. Python before 3.13 raises EACCES in shutil._copyxattr once a read-only ACL has been copied ahead of the user attributes, so the test failed on ubuntu/3.11 before rollback ran. Python 3.13 and later ignore EACCES there. The test now reorders only the journal's own reads (_restorable_xattrs), which is what _restore_xattrs() sorts. It still fails if that ACL-last sort is removed. The snapshot's copystat() is unchanged from main.
  • Stale parent snapshot (_lifecycle.py:261, abcd6641): a pin is now read only for the file's own first snapshot. A later snapshot of a directory that holds the file reads it from its path. New regression: test_builtin_journal_snapshots_a_replaced_file_from_its_path_when_its_parent_is_removed rewrites a file, replaces it, then removes its parent. It fails on 452fb853, where the file is left with the rewritten bytes and reported as a conflict. It passes now.
  • Warning wording (_lifecycle.py:834, abcd6641): an incomplete restore now reads "Could not fully restore ...: their contents, ownership, links, permissions, timestamps, extended attributes or file flags may differ from the originals". The rollback paragraph in docs/integrations/cli.md says the same. I reworded the warning rather than reporting path swaps as conflicts, so behavior is unchanged. The replaced-during-restore test now checks the wording.

Tests:

  • Linux, Python 3.11 and 3.14, as a non-root user in a container: test_lifecycle.py and test_command_upgrade.py give 102 passed and 3 skipped (Windows and BSD-flag cases). The ACL tests ran rather than skipped.
  • Linux, Python 3.11, tests/specify_cli and tests/integrations with xdist: 10692 passed and 51 skipped. Two runs each had one or two subprocess tests fail, and the failing tests differed between runs: test_stdio.py::test_real_stdio_server_initializes_discovers_and_calls_first_class_tools and test_installed_adapters.py::test_round3_extension_event_refresh_loads_adapter_in_fresh_process[disable]. Both modules pass when run on their own (689 passed).
  • macOS, the same two lifecycle modules: 99 passed, 6 skipped.
  • ruff on the changed files reports no new findings.

Posted on behalf of @echarrod by Claude Code (model: claude-opus-5-5), running autonomously; agent-written, no line-by-line human review.

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.

echarrod and others added 2 commits November 20, 2026 22:10
- 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
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 22:16
@echarrod

Copy link
Copy Markdown
Contributor Author

Round summary (head 6fea1bc):

6fea1bc merges the latest #5493 (59728c4, which adds FileHelper.rewrite_descriptor and a design note) so this branch stays current with its prerequisite. The one conflict was in design/file-helper.md, where both sides added independent method bullets, and both are kept. There are no code changes in this PR's own files.

Tests locally on macOS: file-helper, tests/specify_cli/integrations/ (lifecycle, upgrade, switch) and codex, 2099 passed and 118 skipped. ruff@0.15.0 and check_file_helper_migration.py are clean.


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
@echarrod

Copy link
Copy Markdown
Contributor Author

Round summary (head bdb1d0b):

bdb1d0b addresses the eight open review threads:

  • In-place restore compares the opened file's whole state, so an in-place edit between the check and the open is kept as a conflict, not truncated.
  • A repeated after-notification with no write in between no longer moves the metadata baseline.
  • BSD file flags set after the operation's write count as a metadata edit.
  • A recreated file gets its captured extended attributes back, or is reported incomplete with its sidecar retained.
  • FileHelper.chmod on the root goes through a verified no-follow descriptor.
  • The rollback-open and decoy tests now patch FileHelper.open_rewrite, so they work on Windows.
  • New tests cover _pin_limit's branches.
  • design/integration.md and design/file-helper.md are updated to match.

Tests: every new behaviour test fails with the previous _lifecycle.py and file_helper.py. Locally on macOS (Python 3.13), the FileHelper, tests/specify_cli/integrations/ and tests/integrations/ suites gave 5609 passed, 126 skipped and 3 failed under -n 8. The three are generic-integration message checks that pass when the file is re-run alone (261 passed). ruff@0.15.0, markdownlint and check_file_helper_migration.py are clean. Windows is not verified locally.


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.

echarrod and others added 2 commits November 20, 2026 22:32
- 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

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.

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

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)

Comment thread src/specify_cli/file_helper.py Resolved
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
Copilot AI adaptive review requested due to automatic review settings November 21, 2026 18:33

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.

🔵 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)

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

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

Comment on lines +601 to +602
if path in self.pending or path not in self.written_metadata:
self._remember_written(path)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@mnriem

mnriem commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback and fix test & lint errors

echarrod and others added 2 commits November 24, 2026 12:43
…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
Copilot AI balanced review requested due to automatic review settings November 24, 2026 13:46
@echarrod

Copy link
Copy Markdown
Contributor Author

Round summary (head e5cfa38):

86068a2 and e5cfa38 fix the failing pytest job and two of this round's three review threads:

  • Windows test failures (run 44936153671). The in-place restore compared the opened handle's fstat with a path stat of the same file. On Windows, fstat reports the metadata-change time as st_ctime, but a path stat reports the creation time. So every in-place restore there was kept as a conflict, and its snapshot retained. Probed on Windows CI, where the two st_ctime_ns values differed and every other field matched. Rollback now stats the opened file again by path and confirms it is the same file. test_builtin_journal_restores_in_place_when_a_handle_stat_reports_another_ctime simulates the difference and fails before the change. Once the restore ran on Windows, two lifecycle tests also failed there because of CRLF line endings. e5cfa38 makes them independent of line endings.
  • Pinned snapshot attributes (r4668525057). A pinned snapshot now reads the file's attributes once, through the pin. Each value is charged to the snapshot budget as it is read, and that capture is kept rather than read a second time. test_builtin_journal_charges_a_pinned_snapshot_s_attributes_as_they_are_read read 14 attributes before the change and reads 4 after it.
  • Empty attribute set on a recreated file (r4668524963). An empty capture is now restored too. This removes attributes the recreated file inherited, such as a default ACL's access ACL. test_builtin_journal_restores_an_empty_attribute_set_on_a_recreated_file fails before the change.
  • Permission change between two writes (r4668524805): not changed. The suggested guard rejects the operation's own unjournalled chmods (for example, setup making events.py executable before record_file) and broke 18 existing tests. Details are on the thread, which is left open for a maintainer.

Evidence: on macOS, the full suite has 17605 passed and 275 skipped. The one local failure, test_non_windows_uv_tool_dry_run_still_previews_installer, comes from Rich wrapping the long worktree path, and it passes in CI. In a Linux container (python:3.12-slim, non-root user), the integration, FileHelper and preset tests have 2851 passed. On fork CI at e5cfa38, ubuntu 3.11/3.14/3.15 and windows 3.14/3.15 are green. macOS 3.15 is green at 86068a2, and the macOS 3.14 jobs could not get a hosted runner. ruff@0.15.0 and check_file_helper_migration.py are clean.


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.

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.

🔵 Needs a closer look

An unpublished finding about a potential file-descriptor leak during cleanup requires human assessment of the resource-lifecycle risk.

1 open issue
2 resolved since last review

Review effort: Balanced

@mnriem

mnriem commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants