Fix backwards-scan off-by-one in ReadableStorage#258
Merged
Conversation
Co-authored-by: albe <4259532+albe@users.noreply.github.com> Agent-Logs-Url: https://github.com/albe/node-event-storage/sessions/883111c6-3b9d-4839-a829-5e2c1f265c4e
Copilot
AI
changed the title
[WIP] Create PR based on commit 5d9626d
Fix backwards-scan off-by-one in ReadableStorage
Mar 21, 2026
albe
reviewed
Mar 21, 2026
| "version": "0.0.1", | ||
| "scripts": { | ||
| "bench": "node bench-index.js && node bench-storage.js && node bench-eventstore.js" | ||
| "bench": "node bench-index.js && node bench-storage.js && node bench-eventstore.js && node bench-read-scenarios.js" |
Owner
There was a problem hiding this comment.
@copilot the file for this benchmark suite is missing in the PR. Can you reproduce the benchmark suite from the other PR? Otherwise remove it from here.
Contributor
Author
There was a problem hiding this comment.
Added bench/bench-read-scenarios.js in commit f4f8305. It covers the four scenarios described in the PR: forward full scan, backwards full scan, join stream (stream-1 + stream-2), and range scan (middle third). Both stores are pre-populated with 10 000 interleaved events (~512 bytes each) and opened once in readOnly mode before the suite runs.
albe
marked this pull request as ready for review
March 21, 2026 15:25
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 backwards-scan loop in
ReadableStorageused a strict>boundary, causing the final batch to be skipped whenever the range length was an exact multiple of the batch size (10). This meant reads likereadRange(12, 1)would silently drop item 1.Changes
src/Storage/ReadableStorage.js— Changewhile (batchUntil > readUntil)→while (batchUntil >= readUntil)so the terminal batch is always includedtest/Storage.spec.js— Add regression test: write 12 items, read in reverse, assert all 12 are returned in orderbench/package.json— Addbench-read-scenarios.jsto the bench scriptbench/bench-read-scenarios.js— New benchmark covering four realistic read scenarios (forward full scan, backwards full scan, join stream, range scan) on a store with two interleaved streams of 10 000 events (~512 bytes each). Both stores are opened once inreadOnlymode; setup waits for thereadyevent before the suite starts.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.