fix(buzz-db): return an empty page from get_channel_window when limit is 0 - #3536
Open
hasky00 wants to merge 1 commit into
Open
fix(buzz-db): return an empty page from get_channel_window when limit is 0#3536hasky00 wants to merge 1 commit into
hasky00 wants to merge 1 commit into
Conversation
hasky00
force-pushed
the
fix/channel-window-zero-limit
branch
from
July 29, 2026 14:01
13c6811 to
b0ec12a
Compare
… is 0 get_channel_window derived `has_more` from the pre-truncation `limit + 1` probe but read `next_cursor` from the truncated row set, so a `limit == 0` call returned `has_more = true` with `next_cursor = None` — breaking the documented `Some` iff `has_more` invariant and panicking or infinitely looping any caller that trusts it. Guard `limit == 0` and return an empty, exhausted page, which also skips a needless database round-trip. Adds a Postgres-gated regression test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Hasky <239224029+hasky00@users.noreply.github.com>
hasky00
force-pushed
the
fix/channel-window-zero-limit
branch
from
July 29, 2026 14:30
b0ec12a to
031424a
Compare
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.
Summary
get_channel_windowinbuzz-dbcan violate its own documented paginationcontract when called with
limit == 0.ChannelWindow::next_cursoris documented asSomeiffhas_more(
crates/buzz-db/src/thread.rs). The function deriveshas_morefrom alimit + 1probe row before truncation, but derivesnext_cursorfrom thetruncated row set:
With
limit == 0and at least one matching row, this returnshas_more = trueandnext_cursor = None, breaking the invariant. Acaller that trusts the contract (
window.next_cursor.expect("has_more implies next_cursor")— exactly what the module's own pagination test does) panics,and a keyset-pagination loop would spin forever returning empty pages.
The sole current production caller clamps the limit with
.max(1), so thisisn't reachable from the HTTP surface today — but it's a latent contract
violation in a public
DatabaseAPI that any future caller can trip.Fix
Guard
limit == 0at the top ofget_channel_windowand return an empty,exhausted page (
rows: [],has_more: false,next_cursor: None). Thishonors the invariant and also skips a pointless database round-trip for a
zero-row request.
Test
Adds
channel_window_zero_limit_reports_empty_exhausted_page, mirroring theexisting
channel_window_*Postgres tests: it inserts rows, requests azero-limit window, and asserts the page is empty,
has_moreis false, andnext_cursorisNone. (Marked#[ignore = "requires Postgres"]like itssiblings.)
Verification
cargo fmt -p buzz-db -- --check— cleancargo check -p buzz-db --tests— cleancargo clippy -p buzz-db --tests— cleanThe new test requires Postgres and follows the repo's existing
#[ignore = "requires Postgres"]convention.🤖 Generated with Claude Code