fix(client): don't skip live changes after transaction ID wraparound - #4761
Merged
KyleAMathews merged 3 commits intoAug 14, 2026
Merged
Conversation
Reconstruct epoch-aware transaction IDs from 32-bit replication headers before subset snapshot filtering and cleanup. Add an epoch-two regression case and publish the correction as a client patch release.
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4761 +/- ##
===========================================
+ Coverage 60.07% 71.48% +11.41%
===========================================
Files 409 70 -339
Lines 44235 8975 -35260
Branches 12585 2848 -9737
===========================================
- Hits 26574 6416 -20158
+ Misses 17580 2541 -15039
+ Partials 81 18 -63
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
KyleAMathews
approved these changes
Aug 14, 2026
Contributor
|
This PR has been released! 🚀 The following packages include changes from this PR:
Thanks for contributing to Electric! |
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.
Fixes subset snapshot filtering when PostgreSQL 32-bit transaction IDs wrap across an xid8 epoch. Clients now keep live collections current instead of discarding valid changes after wraparound, including on quiet SSE streams that have not received another up-to-date boundary.
Root Cause
Change messages carry 32-bit transaction IDs, while subset snapshot metadata uses 64-bit epoch-aware IDs. Comparing them directly loses the epoch and can classify a new wrapped transaction as visible in an old snapshot.
Reconstructing the epoch also has a half-range constraint: the 32-bit xid and its 64-bit reference must be within
2^31transactions. A quiet stream could retain a snapshot past that bound because its next change may arrive before anotherup-to-datemessage.Approach
xmax, then use the latest resolved xid for snapshot eviction and duplicate filtering.global_last_seen_lsncontrol messages and each change messagelsn.This mirrors the xid reconstruction strategy already used by the sync service in #2320.
Key Invariants
database_lsn.Non-goals
Trade-offs
Using
xmaxas the epoch reference keeps the fix local and matches PostgreSQL wraparound arithmetic. Its half-range requirement is safe because LSN-based retirement bounds each snapshot lifetime without adding protocol state.Verification
pnpm --dir packages/typescript-client test --run pnpm --dir packages/typescript-client typecheck pnpm --dir packages/typescript-client stylecheckThe full TypeScript client unit suite passed (440 tests), along with focused regression tests, type checking, linting, and formatting checks.
Files changed
packages/typescript-client/src/client.ts— retires snapshots from control and change LSNs in stream order.packages/typescript-client/src/snapshot-tracker.ts— reconstructs epoch-aware transaction IDs before filtering.packages/typescript-client/test/pbt-micro.test.ts— adds cross-epoch property coverage and stream retirement regression.packages/typescript-client/test/snapshot-tracker.test.ts— adds a wrapped xid retirement regression..changeset/tidy-xids-wrap.md— records the client patch.Related
Related: #2320
AI disclosure: Codex helped investigate, test, and prepare this change.