Skip to content

fix(durability): journal the migration, make the merge driver atomic - #215

Merged
CryptoJones merged 1 commit into
mainfrom
fix/txn-callers-and-atomic-merge
Aug 2, 2026
Merged

fix(durability): journal the migration, make the merge driver atomic#215
CryptoJones merged 1 commit into
mainfrom
fix/txn-callers-and-atomic-merge

Conversation

@CryptoJones

Copy link
Copy Markdown
Owner

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, and omind migrate as callers to move onto the transaction primitive. Reading them:

caller multi-note? fix
create_and_disable_sources yes transaction (shipped in v8.0.0)
journal.migrate_journals yes transaction (this PR)
merge.run_merge_driver no — git hands it one file (%A) atomic write (this PR)

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 window

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 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.content docstring already claimed None meant "this file should not exist afterwards, delete it on rollback if we created it" — while the field was typed str and 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_trail
  • test_a_journaled_removal_is_rolled_back — deletes, interrupts, asserts the file returns byte-exact.
  • test_removing_a_file_that_never_existed_is_not_a_conflict
  • test_merge_driver_writes_atomically

Gates

ruff check . · mypy src (strict) · pytest (890 passed) · pip-audit — green locally.

🤖 Generated with Claude Code

#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]>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@CryptoJones, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e6a4d6a9-2501-4489-8f5f-2024e30110ef

📥 Commits

Reviewing files that changed from the base of the PR and between 7338130 and d315d39.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • src/omind/journal.py
  • src/omind/merge.py
  • src/omind/txn.py
  • tests/test_journal.py
  • tests/test_merge.py
  • tests/test_txn.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CryptoJones
CryptoJones merged commit bcba912 into main Aug 2, 2026
16 checks passed
@CryptoJones
CryptoJones deleted the fix/txn-callers-and-atomic-merge branch August 2, 2026 20:38
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.

1 participant