Skip to content

Fix offset auto-pagination skipping every other page#119

Open
IlyaasK wants to merge 2 commits into
mainfrom
fix-offset-pagination-page-skip
Open

Fix offset auto-pagination skipping every other page#119
IlyaasK wants to merge 2 commits into
mainfrom
fix-offset-pagination-page-skip

Conversation

@IlyaasK

@IlyaasK IlyaasK commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Bug

SyncOffsetPagination.next_page_info() and AsyncOffsetPagination.next_page_info() computed the next request offset as next_offset + len(items). But X-Next-Offset already holds the offset where the next page starts (the API sets it to offset + limit), so every iteration skipped a full page: with 250 items at limit 100, iteration yields items 0–99 and 200–249 — 100–199 silently vanish. X-Has-More still terminates the loop, so nothing ever errored.

Same fix as kernel/kernel-node-sdk#127 (identical template flaw); the Go SDK uses the header directly and was always correct.

Fix

Use X-Next-Offset verbatim as the next request's offset, in both the sync and async page classes. Termination (absent header → None, X-Has-More: false, empty page) is unchanged and now pinned by tests/test_pagination.py.

Why a hand-written commit to generated code

Stainless's hosted generator is winding down post-acquisition, so a template-level fix is not coming. While the service still runs, this commit rides Stainless's custom-code three-way merge; after sunset it is simply the code.

🤖 Generated with Claude Code


Note

Medium Risk
Changes list pagination behavior for all offset-paginated APIs; fixes data loss but could surface RuntimeError where contradictory headers were previously ignored.

Overview
Fixes offset-based auto-pagination in SyncOffsetPagination and AsyncOffsetPagination: the next request now uses X-Next-Offset as-is instead of adding the current page length, which had been skipping every other page on multi-page list iteration.

When X-Has-More: true but X-Next-Offset is missing, pagination now raises RuntimeError instead of stopping quietly. tests/test_pagination.py covers both sync/async classes, and the README clarifies that next_offset is where the next page starts.

Reviewed by Cursor Bugbot for commit 4554697. Bugbot is set up for automated code reviews on this repo. Configure here.

Sync/AsyncOffsetPagination.next_page_info() requested the next page at
next_offset + len(items). The X-Next-Offset header already holds the
offset where the next page starts (the API computes offset + limit), so
adding the current page length skipped a full page per iteration: with
250 items at limit 100, iteration returned items 0-99 and 200-249 and
silently dropped 100-199. X-Has-More still terminated the loop, hiding
the data loss.

Use the header value directly. Absent header already terminated via the
None check, unchanged.

Hand-maintained fix: with Stainless's hosted generator winding down, the
template-level fix is not coming; this commit and its test are the
canonical behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@firetiger-agent

Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

PRs in the kernel, infra, hypeman, and hypeship repos. kernel is a ~mono repo with many logical services underneath, ensure to focus on the implicated service for the PR

Reason: PR is in the kernel repo but affects the Python SDK pagination logic; unclear which logical service this belongs to without more context on the codebase structure.

To monitor this PR anyway, reply with @firetiger monitor this.

Review follow-up: raise instead of silently truncating when X-Has-More
is true but X-Next-Offset is absent, mirror all tests across the Sync
and Async classes so the two generated variants cannot drift apart, pin
the 0 last-page sentinel, and fix the stale next_offset wording in the
README pagination example.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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