Skip to content

fix: search the BoltDB history backwards from the newest event - #1394

Merged
dunglas merged 3 commits into
mainfrom
fix/bolt-history-backward-scan
Sep 22, 2026
Merged

dunglas merged 3 commits into
mainfrom
fix/bolt-history-backward-scan

Conversation

@dunglas

@dunglas dunglas commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Fixes #1382

maxHistoryScan bounded a forward walk starting at c.First(), the oldest key. Once the bucket held more than 10,000 events, every Last-Event-ID newer than the 10,000th oldest one was unreachable: the hub logged Can't find requested LastEventID, replayed nothing and answered Last-Event-ID: earliest. Ancient ids (the DoS case the cap protects against) were still found, recent ids (the normal reconnect case) were not.

Changes

  • findLastEventID searches backwards from the newest event (c.Last() / c.Prev()) and returns the found sequence number. The cap now bounds the work for ancient or forged ids, while a client reconnecting after a short drop always finds its cursor.
  • replayHistory replays forward from Seek(fromSeq+1), keeping the pastSeqBound guard against updates dispatched since the subscribe snapshot.
  • historyScanLimit is max(maxHistoryScan, size). A configured size above 10,000 is retention the operator pays for in disk and cleanup passes, so it stays entirely searchable instead of being silently overridden by the constant. size 0 keeps the 10,000 default bound.
  • Dropped the authorized-responseLastEventID tracking from the search phase. It became unreachable in fix(bolt): report "earliest" when the requested Last-Event-ID is missing #1321, which forces earliest whenever the requested id is not found, and it cost a JSON unmarshal per scanned event.

Notes

docs/concepts/reconnection-and-history.md now states the replay-depth bound next to size, which the docs previously described as unlimited.

maxHistoryScan bounded a forward walk starting at the oldest key, so any
Last-Event-ID newer than the first 10,000 stored events was never found and
reconnect replay stopped working on any hub holding more history than the cap.

Search backwards from the newest event instead: the scan limit now bounds the
ancient or forged ids the guard exists for, and a configured `size` raises it
so the retention an operator pays for stays searchable.

Fixes #1382
@dunglas
dunglas force-pushed the fix/bolt-history-backward-scan branch from 0fac467 to bd3330e Compare September 21, 2026 13:43
@dunglas
dunglas merged commit ec55d4b into main Sep 22, 2026
47 checks passed
@dunglas
dunglas deleted the fix/bolt-history-backward-scan branch September 22, 2026 16:24
dunglas added a commit that referenced this pull request Sep 23, 2026
The backward search introduced by #1394 returned the newest update bearing
the requested ID. The spec requires the earliest one, followed by every
later update, including those reusing the ID. The search now scans the
whole window and keeps the oldest match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant