Repository navigation
Read the high-water mark through the sequence's lock - #285
Merged
Merged
Conversation
WAX-0001 and WAX-0013 rely on the high-water mark, but neither said how to read the number the mark starts from. A plain query of the sequence's last_value column can briefly return a number up to 32 higher than any yet handed out while nextval writes the sequence to the write-ahead log. A mark built on that number moves past events still in flight, and the reader never sees them. The bake-off's round 2 diagnostic pass traced a read model skip to exactly this. WAX-0001 now says that Wax reads the number with pg_sequence_last_value(), which takes the sequence's lock, and why. WAX-0013 now says that a checkpoint window is settled only when the mark is read that way. Neither change touches a Decision section, so WAX-0001 goes from 2.3 to 2.4 and WAX-0013 from 2.1 to 2.2. Rob approved the wording on 2026-11-15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Rob Grafrath <rob@openarcollective.org>
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.
What this changes and why
WAX-0001 Enriched Event Sourcing defines the high-water mark: the highest global sequence number at or below which every transaction that drew a value has committed or rolled back. Readers of the event stream stop there, and WAX-0013 Event Chain Integrity and Tamper-Evidence ends each checkpoint window there. Neither decision said how to read the number the mark starts from, and the obvious way is wrong.
A plain query of the sequence's last_value column does not take the sequence's lock. In PostgreSQL 17, nextval writes the sequence to the write-ahead log at least once every 33 calls when the sequence has a cache of 1, and while it does, the sequence's row briefly holds a number 32 ahead of the one it hands out. A plain query can see that number. A mark built on it moves past numbers that open transactions are about to commit, and a reader that trusts the mark never reads those events. pg_sequence_last_value() reads the same row under the sequence's lock and cannot see the inflated number.
The Foundation's engine bake-off found this the hard way. Its round 2 diagnostic pass, published at the spikes repository's tag round-2-diag, describes it in the diagnostic pass section of the bake-off README:
This pull request adds the missing rule to the design. In WAX-0001's Sequence Numbers section, it says that Wax reads the starting number with pg_sequence_last_value(), which takes the sequence's lock, and it explains why a plain query can cause the skip the mark exists to prevent. In WAX-0013's section on delta checkpoint anchoring, it says that a window ending at the mark is settled only when the mark is read that way, because a window ending at an inflated number could close over numbers not yet handed out. Correcting the bake-off's own readers is separate work in the spikes repository.
Rob approved the wording on 2026-11-15, as a pull request of its own.
Interacting decisions
Edited: WAX-0001 and WAX-0013.
Unchanged, and consistent with the change: WAX-0003 Database Platform, which names transaction identifiers as what a reader finds its high-water mark from, and WAX-0024 High Availability, Disaster Recovery, and Distributed Workloads, which refers to the mark as WAX-0001 defines it. Both pick up the corrected definition by reference. Nothing here contradicts an adopted decision; the change states a requirement the high-water mark always needed.
If this touches decisions/wax/
Version bumps
Each number below is relative to main at c653153.
Coordination with unmerged branches
Checklist
python3 scripts/validate.py --base mainpasses locally, or I am relying on CI to tell me. (Run on 2026-11-15 against origin/main c653153. Under WSL, every check passed apart from the version check, which cannot run in a Windows worktree from WSL and exited 128 on git merge-base. Run from Windows, the version check passed, and the only errors were the known INDEX.md path-separator false failures. CI runs the full check.)🤖 Generated with Claude Code