fix(#4964): hold the Normal high-water mark before a leading sequence gap#4972
Merged
Conversation
… gap The async daemon could silently advance the high-water mark over a committed-but-not-yet- visible event, sealing a skipped event with no mt_high_water_skips row, no log line, and no metric. Root cause is a blind spot in GapDetector: its interior-gap query only compares consecutive VISIBLE rows, so when the detection Start lands ON a hole (a rolled-back/allocated seq_id, or a SafeZone "-32" boundary that need not be a real event), a gap immediately above Start is invisible to it — there is no visible row at Start to pair with the first row above the gap. It then falls through to max(seq_id) and the Normal mark crosses the gap. Fix: GapDetector gains a leading-gap probe (min(seq_id) where seq_id > Start) and a HoldBeforeLeadingGap flag. When the first committed sequence above Start sits beyond Start + 1, the Normal path holds at Start instead of advancing. A still-in-flight append fills the gap and the next poll advances normally; a genuinely permanent hole is skipped — and recorded via MarkSkippingAsync / mt_high_water_skips — by the existing SafeZone path once the mark has been stale past StaleSequenceThreshold. So every skip now goes through the observable path, and the Normal mark never crosses an unseen event. The hold is Normal-path only: HighWaterDetector.findCurrentMark enables it for DetectionType.Normal, and DetectInSafeZone explicitly disables it so the SafeZone path keeps its skip-forward-to-max behavior (its whole purpose is to break a permanent hole). Existing GapDetector / high-water tests are unchanged; two new GapDetector tests cover the leading-gap hold and the SafeZone skip. Closes #4964. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XKKBPsFJ83jd2o4hyGJnj6
This was referenced Jul 18, 2026
This was referenced Jul 18, 2026
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.
The bug
The async daemon could silently advance the high-water mark over a committed-but-not-yet-visible event — sealing a skipped event with no
mt_high_water_skipsrow, nois_skipped, nodaemon.skippingmetric, and no log line. (From the #4953 investigation.)Root cause
GapDetector's interior-gap query only compares consecutive visible rows:When the detection
Startlands on a hole — a rolled-back/allocatedseq_id, or a SafeZoneHighestSequence - 32boundary (GH-3865) that need not be a real event — a gap immediately aboveStartis invisible to query (1): there is no visible row atStartto pair with the first row above the gap. It falls through tomax(seq_id), and the Normal detection path (which records nothing) advances the mark across the gap.Fix
GapDetectorgains a leading-gap probe (min(seq_id) where seq_id > :start) and aHoldBeforeLeadingGapflag. When the first committed sequence aboveStartsits beyondStart + 1, the Normal path holds atStartinstead of advancing:MarkSkippingAsync/mt_high_water_skips— by the existing SafeZone path once the mark has been stale pastStaleSequenceThreshold.So the Normal mark never crosses an unseen event, and every skip now flows through the observable SafeZone path.
The hold is Normal-path only:
HighWaterDetector.findCurrentMarkenables it forDetectionType.Normal;DetectInSafeZoneexplicitly disables it so the SafeZone path keeps its skip-forward-to-maxbehavior (its whole job is to break a permanent hole and record it).Tests
Existing
GapDetector/ high-water tests unchanged (verified locally). Two newGapDetectorTestcases:normal_path_holds_at_start_before_a_leading_gap_when_start_is_a_hole— the repro:Starton a hole with a leading gap holds atStartinstead of leaping tomax.safe_zone_path_still_skips_a_leading_gap_forward_to_max— guards that the hold does not leak into the SafeZone path.Closes #4964.
🤖 Generated with Claude Code