fix: Stop the paginator when a page cursor repeats - #1006
Merged
Conversation
Nothing halted pagination against a server that pins one cursor: the per-request timeout resets every page while flattenToArray grows without bound. A next page reported with a null cursor threw a plain error from deep inside iteration instead of ending it. Route flatten, flattenToArray, and page iteration through one private walk generator that tracks seen cursors and stops silently when the cursor is null or repeats. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
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.
Problem
SDK audit finding M6 (medium): the paginator loops on
has_next_pagewith no max-pages bound, no cursor-repeat detection. A server regression or proxy-cached page that pins one cursor hangsflatten()forever and growsflattenToArray()to OOM — the per-request timeout resets every page, so nothing saves the process. A next page reported with anullcursor threw a plain error from deep inside iteration.Fix
Mirrors seamapi/php#466:
flatten,flattenToArray, and page iteration now delegate to one private#walk()generator that tracks seen cursors and stops silently when the next cursor is null or repeats a previous cursor.firstPage/nextPageare unchanged for manual paging.Tests
has_next_page: true→ iteration terminates after fetching each page once (['device-1', 'device-2'])has_next_page: truewith anullcursor → iteration ends cleanly after page 1Per the audit-notes recipe, with the fix reverted the repeat test loops past the mocked pages (fails on the third fetch of the same cursor) and the null-cursor test throws
Cannot get the next page with a null nextPageCursor. Full suite (127 tests), lint, typecheck green.Part of applying the rev-3 SDK audit (one PR per finding). Related: #1002–#1005.
🤖 Generated with Claude Code
https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
Generated by Claude Code