Skip to content

Add storage-enforced bounded page reads - #34

Merged
Shearerbeard merged 5 commits into
redesign/bootstrapfrom
card/e42
Nov 22, 2026
Merged

Shearerbeard merged 5 commits into
redesign/bootstrapfrom
card/e42

Conversation

@Shearerbeard

Copy link
Copy Markdown
Owner

What

EventStreams::load_stream_page: bounded, paged reads of one stream's history.

  • The records inside an inclusive position range, oldest first, at most limit of them, with the stream's observed position. The range is the replay boundary a consumer owns; the limit is its page size.
  • at() is the observed head of the whole stream, never a page checkpoint. A consumer advances a page at its requested start plus its returned count, checks endpoint completion before incrementing, and lets an empty page end catch-up.
  • Zero limit, reversed ranges, past-head bounds and missing streams read empty pages that still observe the head - never errors.
  • Both SQL backends apply the range and the count inside a bounded subquery joined to the head observation: an empty page still reports the head row, and rows outside the page are never decoded.
  • Bounds past what SQL can store keep their arithmetic meaning: an upper bound past every storable position includes all of them, a lower bound past them selects none, and an oversized usize limit clamps instead of going negative.

Existing callers are unaffected. External EventStreams implementors must add the method - a breaking addition for implementors, stated as such.

Conformance

  • Shared cases on the in-memory, SQLite and PostgreSQL backends: exact endpoints, truncation by count and by upper bound, zero limit, reversed and empty ranges, past-head and missing streams, unsigned bounds past i64::MAX, same-snapshot head and records under a rival append, and a consumer paging a dense backlog to an endpoint captured from its first observation - a rival append inside the originally requested range but beyond that endpoint never rides a page.
  • SQL-local controls: a strict event type pages without decoding what its bounds and count exclude (both exclusion kinds), while a selected undecodable row still errors; a zero-limit read decodes nothing. The SQLite file-backed block runs the page cases over independently opened actors.

Verification

Rust 1.88.0 (the declared floor):

cargo test --no-default-features --features in_memory,sqlite           # 119 lib cases
cargo test --no-default-features --features in_memory,sqlite,postgres # 156 lib + integration, live compose postgres
cargo clippy --no-default-features --features in_memory,sqlite --all-targets --locked -- -D warnings
cargo clippy --no-default-features --features in_memory,sqlite,postgres --all-targets --locked -- -D warnings
cargo fmt --all --check
cargo test --doc

An adversarial review round before this PR found and fixed one defect: the consumer case's completion arithmetic could overflow at the largest sequence; completion is now checked on the page's own stretch before any increment (ec6b236).

Note: strict Clippy on toolchains newer than the floor (1.95.0) flags three baseline lints in src/test_helpers/repository.rs and tests/saga_outbox_postgres/windows.rs, files this PR does not touch. Left for a separate cleanup.

Changelog entry included under [Unreleased].

Add load_stream_page to EventStreams: the stored records inside an
inclusive position range, oldest first, at most limit of them, with the
stream's observed position. The range is a consumer's replay boundary
and the limit is its page size. The in-memory, SQLite and PostgreSQL
backends implement it; both SQL backends apply the bounds and the
LIMIT inside a bounded subquery joined to the head observation, so
every empty page still reports the head and only the selected rows
reach typed decoding. Zero limits, reversed ranges, past-head bounds
and missing streams read empty pages, never errors.

Shared conformance cases cover exact endpoints, truncation by count
and by upper bound, unsigned bounds past i64::MAX, one-snapshot reads
under a rival append, and a consumer paging a backlog to an endpoint
captured from its first observation; SQL-local controls pin
selection-before-decoding for both exclusion kinds.

Card: E42
The consumer case's completion check ran after the next-start
increment, so a final dense page starting at the largest sequence
would panic on the checked add instead of completing catch-up, and
the comment claimed the opposite order. Check completion on the
page's own stretch - requested start through returned count minus one
- which a page bounded by the endpoint cannot push past the largest
sequence, and only then advance the next start.

Card: E42
The selection-before-decoding control existed near-verbatim in the
SQLite and PostgreSQL test modules. Lift it into the shared spec
suite as a_page_selects_before_decoding, generic over the strict
reader and the loose writer, with each backend wiring its own stores
and its own decode-failure predicate. The consumer case also folds
its first-page assertion into the endpoint it derives and builds the
rival's batch in one block. Coverage is unchanged: every exclusion
kind, the selected failure, and the zero-limit read still assert,
now single-sourced.

Card: E42
@Shearerbeard
Shearerbeard merged commit e922e74 into redesign/bootstrap Nov 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant