Fix off-by-one in /items pagination offset (DEMO-25) - #18
Open
thierrypdamiba wants to merge 1 commit into
Open
Conversation
Page numbers are 1-indexed, but the offset was computed as page * limit, so page 1 skipped the first `limit` items and every page showed the next page's data. Compute offset as (page - 1) * limit so page 1 starts at item 1 and all pages cover all items.
thierrypdamiba
marked this pull request as ready for review
August 3, 2026 23:17
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.
This pull request was opened by an automated triage agent acting on behalf of Thierry Damiba, in response to a customer support report tracked in Linear ticket DEMO-25.
Customer report: page 1 of the /items endpoint returned items 11 through 20 instead of 1 through 10, items 1 through 10 never appeared on any page, and page 2 repeated page 1's contents.
Root cause: in buggy-api/src/handler.py, get_page computed the offset as page times limit even though pages are 1-indexed. Page 1 therefore started at offset 10, skipping the first ten items, and every subsequent page showed the following page's data.
Fix: compute the offset as (page - 1) times limit, so page 1 starts at offset 0.
Verification, run in a Daytona sandbox: before the fix, pytest reported 2 failed and 1 passed (test_page_one_starts_at_item_1 and test_all_pages_cover_all_items failed). After the fix, all 3 tests pass: test_page_one_starts_at_item_1, test_page_two_starts_at_item_11, and test_all_pages_cover_all_items. Only the source was changed; no tests were modified.
Note for reviewers: the gateway tool set has no label-writing tool, so this body is the record that an agent authored this PR. Policy forces this PR to draft; a human must promote it to ready for review and merge.
Note
Low Risk
Single-line fix in demo pagination logic with no auth, security, or data-model changes.
Overview
Fixes off-by-one pagination in
get_pageso 1-indexed pages map to the right slice ofITEMS.The offset changes from
page * limitto(page - 1) * limit, so page 1 starts at item 1 (offset 0) instead of skipping the first page of results and duplicating later pages.Reviewed by Cursor Bugbot for commit cbb7143. Bugbot is set up for automated code reviews on this repo. Configure here.