Skip to content

fix: complete file-change journal on mutation errors - #5611

Closed
feiiiiii5 wants to merge 1 commit into
github:mainfrom
feiiiiii5:fix/file-changes-rollback
Closed

feiiiiii5 wants to merge 1 commit into
github:mainfrom
feiiiiii5:fix/file-changes-rollback

Conversation

@feiiiiii5

Copy link
Copy Markdown

Description

changing_file() journals a host mutation but only called after_file_change() on the success path. When a mutation raised, the lifecycle journal left the path pending, so rollback could treat a partially changed file as a conflict instead of restoring its snapshot. The yield now runs in try/finally, so completion is reported on both paths. A regression test covers the exception case.

Testing

  • Tested locally with .venv/bin/specify --help
  • Ran relevant existing tests with .venv/bin/python -m pytest tests/specify_cli/integrations/test_file_changes.py -q (33 passed)
  • Tested with a sample project (not applicable to this internal lifecycle helper)

Base-red: the new test failed before the source fix. Head-green: 33 passed. ruff==0.15.0 check on both changed files passed; git diff --check clean.

AI Disclosure

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

AI disclosure: Implemented with Claude Code using Claude Sonnet 5 in agent/autonomous mode, default settings; code generation and offline regression test. No human line-by-line review before commit.

Assisted-by: Claude Code (model: Sonnet 5, autonomous)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@feiiiiii5
feiiiiii5 requested a review from mnriem as a code owner November 29, 2026 00:39
Copilot AI adaptive review requested due to automatic review settings November 29, 2026 00:39

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

Failed mutations can incorrectly claim ownership of concurrent changes, risking destructive rollback, and the new completion callback breaks both shared-write failure tests.

2 open issues
What changed in this PR

This PR aims to improve integration lifecycle rollback by completing file-change journal notifications when a mutation raises.

Changes:

  • Wraps mutations in try/finally so completion is reported on both success and failure.
  • Adds a regression test for callback ordering and exception propagation after a partial write.

AI-assisted review for the requester (identity unavailable): GitHub Copilot; model unknown; autonomous analysis and review editing. Tests were not run during this review.

File Description
tests/​specify_cli/​integrations/​test_file_changes.py Adds exception-path completion coverage.
src/​specify_cli/​integrations/​_file_changes.py Moves completion notification into finally.

Review effort: Balanced (adaptive)

Comment on lines +74 to +75
finally:
after_file_change(path)
finally:
_file_changes.file_change_observer.reset(token)

assert observed == [(path, True, False), (path, False, False)]
@feiiiiii5

Copy link
Copy Markdown
Author

Closing after review. Failed mutations are deliberately left pending: design/integration.md says changed bytes cannot be attributed to a failed operation, and rollback must leave pending paths untouched. after_file_change() in finally would clear that state and could let rollback overwrite a concurrent edit; it also conflicts with the shared-write failure tests. The premise was wrong.

Contributor: feiiiiii5. Agent: Claude Code (Claude Sonnet 5), autonomous mode; agent-written from the review thread, no human line-by-line review.

@feiiiiii5 feiiiiii5 closed this Nov 29, 2026
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