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
changing_file leaves lifecycle pending when the wrapped write fails #5615
changing_file() in src/specify_cli/integrations/_file_changes.py does not call after_file_change() when the wrapped write or unlink raises. The lifecycle observer adds the path to pending in before_file_change() and removes it only in after_file_change(), so an exception leaves the path pending. _restore_snapshots() skips pending paths, which can prevent rollback from restoring the original bytes of the failed file.
Evidence
At main commit f2010547121b3351e4923fe467205079e4593a32:
If yield raises, the second call never happens. In _lifecycle.py, before_file_change() adds path to pending, after_file_change() discards it, and _restore_snapshots() skips pending paths.
A focused observer test can reproduce this without a live agent, database, or network: register an observer that records (path, before, removal), make Path.write_text raise inside changing_file(), and assert that the observer receives both the before and after events. On current main, only the before event is recorded.
Expected behavior
The lifecycle is finalized even when the file operation fails, so rollback can consider the original file and restore it if needed.
Actual behavior
The path remains in pending after the failed operation, and rollback may skip it.
Proposed fix
Move yield into try and call after_file_change(path) in finally. Add a regression test for the exception path.
AI assistance disclosure
Claude Code (model Sonnet 5, default settings, autonomous mode) was used to inspect the lifecycle code, construct this report, and prepare the proposed fix and test. No live service, paid account, or personal data was used.
Retracting this report: its premise is wrong. design/integration.md:396-399 intentionally leaves failed writes pending because their bytes cannot be attributed to the operation; rollback must leave those paths alone. test_lifecycle.py:213-231 covers that behavior. Our PR #5611 made the proposed change and was closed after review for this reason. No further patch will be published.
AI disclosure: Claude Code (Claude Sonnet 5, default settings, autonomous mode) inspected the code and drafted this report and patch; no human line-by-line review.
Activity
feiiiiii5 commentedon Nov 29, 2026
Retracting this report: its premise is wrong.
design/integration.md:396-399intentionally leaves failed writes pending because their bytes cannot be attributed to the operation; rollback must leave those paths alone.test_lifecycle.py:213-231covers that behavior. Our PR #5611 made the proposed change and was closed after review for this reason. No further patch will be published.AI disclosure: Claude Code (Claude Sonnet 5, default settings, autonomous mode) inspected the code and drafted this report and patch; no human line-by-line review.