Repository navigation
refactor(database): write the safe event order once, so the audit chain can't drift from consumers - #306
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
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. |
…nd the sealer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PiquelChips
force-pushed
the
refactor/single-safe-event-order
branch
from
November 2, 2026 14:38
01c01a8 to
d9d490c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#30 said the safe consumer order for
domain_eventswould be written once, inEventRepository::read_after. In practice the audit sealer repeated the rule in its own query,AuditRepository::unsealed. That rule is: read in(txid, sequence)order, and only from transactions older thanpg_snapshot_xmin. If the two copies drifted apart, the hash chain could silently skip events or put them in the wrong order.The rule now lives in one
in_safe_order!query macro inrepositories/mod.rs. It wrapssqlx::query_as!, so queries are still checked at compile time, and adds the snapshot filter andORDER BY e.txid, e.sequence.read_afterandunsealedboth build on it. The sealer still addsLIMIT $1 FOR UPDATEafter it, so its row locks, chain positions and the runtime role's grants don't change.read_afterstays because the alerts work (#83) will consume it..sqlx/is regenerated: only the query text changed, and the result types sqlx recorded are identical.Proof:
just db testpasses for the events, audit and runtime-role tests, including the interleaved-transaction testread_after_never_skips_an_event_committed_out_of_order, the sealer'sevents_are_sealed_in_safe_order_and_checkpointedandruntime_role_has_only_row_privileges. The.sqlxcheck,clippy -D warningsandfmt --checkalso pass.Reviewed with review-loop: 1 round with 2× gpt-6.1-sol and claude-opus-5-5. Verdict: approved
Note
Written by Claude Opus 5.5 in Claude Code and reviewed by GPT-6.1 Sol and Claude Opus 5.5 (via T3 Code)
🤖 Generated with Claude Code