fix(durability): journal the migration, make the merge driver atomic - #215
Conversation
#194 named two callers to migrate onto the transaction primitive. Reading them, only one is a multi-note write, so they get different fixes and the difference is written down. `journal.migrate_journals` IS multi-file: per stray journal it appends bullets to the relocated note, then unlinks the stray. Between those two steps the entries exist in exactly one place — a crash there lost a day of journal entries outright, with nothing to recover from. The whole migration is now one journaled transaction. That needed something the journal could not express: deletion. `Transaction` gains `remove()`, journaled like a write so rolling one back puts the file back. (The `_Entry` docstring already claimed `None` meant "delete on rollback", while the field was typed `str` and nothing implemented it — a docstring for behaviour I never wrote. It is true now instead of deleted.) `merge.run_merge_driver` is NOT multi-note: git hands the driver exactly one file (%A). Its real gap was `write_text`, which truncates in place, so an interrupted merge left a torn note AND an exit code git reads as success — the torn note then gets committed and synced to every peer. Now an atomic write, with a comment saying why a transaction would be the wrong tool. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Warning Review limit reached
Next review available in: 19 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
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. Comment |
2 of 6 in the follow-up batch. Ships in v8.1.0.
The issue's list was half right, and that's the interesting part
#194 named
create_and_disable_sources, the mesh merge driver, andomind migrateas callers to move onto the transaction primitive. Reading them:create_and_disable_sourcesjournal.migrate_journalsmerge.run_merge_driver%A)Wrapping the merge driver in a transaction would have been cargo-culting the issue's wording. It has a real durability gap, just a different one.
migrate_journals— the entries-in-one-place windowPer stray journal it appends bullets to the relocated note, then unlinks the stray. Between those two steps the entries exist in exactly one place. A crash there loses a day of journal entries outright, with nothing to recover from. Now one journaled transaction.
Transaction.remove()Journaling a move needs deletion, which the journal couldn't express.
remove()captures the pre-image like any write, so rolling back a removal puts the file back.Worth flagging: the
_Entry.contentdocstring already claimedNonemeant "this file should not exist afterwards, delete it on rollback if we created it" — while the field was typedstrand nothing implemented it. I wrote a docstring for behaviour I never built, in the v8.0.0 PR. It's now true rather than quietly deleted.The merge driver
ours_path.write_text(merged)truncates in place. An interrupted merge left a torn note and returned an exit code git reads as success — so the torn note gets committed and syncs to every peer in the mesh. Now_atomic_write, with a comment recording why it is not a transaction.Tests
test_interrupted_migration_loses_no_journal_entries— kills the apply mid-migration, asserts the stray comes back byte-identical and nothing is left pending.test_migration_merges_a_same_day_journal_without_losing_either_trailtest_a_journaled_removal_is_rolled_back— deletes, interrupts, asserts the file returns byte-exact.test_removing_a_file_that_never_existed_is_not_a_conflicttest_merge_driver_writes_atomicallyGates
ruff check .·mypy src(strict) ·pytest(890 passed) ·pip-audit— green locally.🤖 Generated with Claude Code