Repository navigation
feat(reporting): order the account change feed by (xid, seq) - #3289
Merged
Merged
Conversation
The account feed ordered by seq and cut each page before the first in-flight change, which depends on lock discipline (#3228). Order it by (xid, seq) behind xid < pg_snapshot_xmin(...), as the deployment-wide feed does, and drop the truncation guard. - Account cursors carry xid. A seq-only cursor from before is mapped to a position that skips nothing (the smaller of the oldest later change's xid and the snapshot's xmin) and upgraded; it fails with CURSOR_EXPIRED if a change with a higher seq was pruned. - The account horizon gains (xid, seq) columns, the consumer table's check constraint is replaced, and (account_id, xid, seq) is indexed. - pruneChanges, retireExpiredPeriods and compaction holds use (xid, seq) for account consumers; pre-upgrade rows hold by seq. Closes #3283 Co-Authored-By: Claude Sonnet <[email protected]>
- pruneChanges takes victims in (xid, seq) order, so a limited batch cannot leave a retained change below the account horizon. - Cursor seq and xid are range-checked, so out-of-range values fail as INVALID_INPUT. - A NULL-xid consumer row is replaced only by a cursor whose seq is not behind. - Document mixed-fleet maintenance, rollback and concurrent index creation. - Tests: minimal redelivery of a mapped legacy cursor, exact mapped values, prune batching, concurrent migration appliers, compaction hold in (xid, seq) order, legacy cursor save against a new-format row. Co-Authored-By: Claude Sonnet <[email protected]>
bokelley
enabled auto-merge (squash)
October 15, 2026 20:55
There was a problem hiding this comment.
Ladon verdict: Approve
Approve.
Clean review with no blocking or Medium findings. Verified against the decision table top-down:
- No critical/high findings (row 1 no match).
gated_pathsis false (row 2 no match) — notereview_decisionis REVIEW_REQUIRED, but with gated_paths false the hard gate does not apply.high_riskis false, no deleted/modified high-risk triggers (rows 3–5 no match).- No prior decision (row 6 no match).
- No no-auto-approve team match (row 7 no match).
- Zero medium findings, so row 8 (≥3 medium) does not fire.
- Falls through to row 9 → approve.
Checked: account change feed reordered to (xid, seq) matching the deployment feed; legacyAccountCursorXid is snapshot-safe via LEAST(xmin, min-unread-xid) so no post-legacy-cursor change is skipped; assertRetained fail-closes on the original cursor; prune horizon advances monotonically with no fail-open window; cursor validation tightening (fitsUnsigned) is strictly better. Changeset is present and correctly scoped for an @experimental reporting-storage break with a full migration note; migration constraint-swap is guarded, idempotent, and covered by concurrent-applier + re-apply tests.
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.
Closes #3283
What
The account change feed now orders by
(xid, seq)behindxid < pg_snapshot_xmin(pg_current_snapshot()), the way the deployment-wide feed already does. It no longer depends on the account lock to keepseqin commit order, and the #3228 truncation guard is gone. A change with a lowerseqand a higherxidthat commits late is returned on a later page, after the cursor, instead of being skipped. A writer that takes a different lock key can no longer cause a missed change.Old-cursor decision: map, don't expire
An account cursor from before this change is
{ seq }with noxid. Failing it withCURSOR_EXPIREDwould force every consumer to resync, and a BigQuery sink would reload its history. A mapping that never skips exists, sochangesAfteraccepts it:(X, S)withX = LEAST(snapshot xmin, oldest visible xid among the account's changes with seq > S), computed in one statement.Shas anxidat or above both terms: a visible one is at or above the minimum, and one not yet visible belongs to a transaction in flight or started after the snapshot, whose id is at or abovexmin. So nothing is skipped.seqand a higherxid, and, if a long transaction was open at that moment, every change committed since it began. Consumers are at-least-once already. The returned cursor is in the new format even on an empty page, so a sink saves it on the next batch.pruned_through_seq(highestseqpruned, unchanged semantics) next to the new tuple horizon, and a legacy cursor fails withCURSOR_EXPIREDif any change with a higherseqwas pruned. A tuple compare alone would miss a pruned change with a higherseqand a lowerxid(covered by a test).cursor_xidand hold bysequntil the consumer saves its next cursor.saveFeedConsumerCursorgiven a legacy cursor maps it the same way.Other changes
pruneChangesselects victims in(xid, seq)order and records the per-account tuple horizon;pruneChanges,retireExpiredPeriodsand snapshot compaction share onefeedConsumerBehindChangepredicate.REPORTING_LEDGER_CHANGES_MIGRATION(idempotent, advisory-locked): adds the horizonxidcolumns, replaces the consumer table's check constraint, adds(account_id, xid, seq). The old(account_id, seq)index is kept (it serves the legacy mapping). Plan verified: with a realistic table the account page is an ordered index scan with no Sort.seqandxidare range-checked so out-of-range values fail asINVALID_INPUTrather than a raw database error.docs/guides/REPORTING-LEDGER.md. Changeset: minor with a migration note (mixed-fleet maintenance, rollback,CREATE INDEX CONCURRENTLY).Tests
PG suites in
test/lib/reporting-*.test.jspass with--test-concurrency=1(1092 tests). New: lower-seq/higher-xid late commit, held-back change, other-account transaction, legacy mapping (never skips, minimal redelivery, in-flight transaction), legacy expiry on a pruned higher seq, legacy consumer holds, prune ordering and batching, compaction and retirement holds in(xid, seq)order, migration upgrade and 8 concurrent appliers, plan check, BigQuery sink resuming a legacy cursor.Review gate
seqand records onlypruned_through_seq), rollback after new-format cursors is unsupported, and large tables should build the index concurrently.(xid, seq)order). Added the missing tests it listed (minimal redelivery, exact mapped values, legacy save over a new-format row, concurrent migration, compaction hold, cursor range). Flake runs: 5/5 alone and alongside other suites; cross-file concurrent runs of the horizon-race tests were already not run concurrently in CI.review:codex --all): the repo is unreadable in its sandbox, so I fed it the diff on stdin. It raised the same rolling-upgrade pruner issue (addressed by documentation, see above); its "no tests" findings were from a diff that excluded tests. Declined: a conservative compatibility check usingpruned_through_seqfor new-format cursors, because mixed-fleet maintenance cannot be made safe in general and the false-expiry cost would hit normal operation.🤖 Generated with Claude Code