Skip to content

fix: Stop the paginator when a page cursor repeats - #1006

Merged
razor-x merged 3 commits into
mainfrom
claude/js-sdk-audit-6x115l-m6-loop-guard
Aug 25, 2026
Merged

fix: Stop the paginator when a page cursor repeats#1006
razor-x merged 3 commits into
mainfrom
claude/js-sdk-audit-6x115l-m6-loop-guard

Conversation

@razor-x

@razor-x razor-x commented Aug 24, 2026

Copy link
Copy Markdown
Member

Problem

SDK audit finding M6 (medium): the paginator loops on has_next_page with no max-pages bound, no cursor-repeat detection. A server regression or proxy-cached page that pins one cursor hangs flatten() forever and grows flattenToArray() to OOM — the per-request timeout resets every page, so nothing saves the process. A next page reported with a null cursor 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/nextPage are unchanged for manual paging.

Tests

  • server pins one cursor with has_next_page: true → iteration terminates after fetching each page once (['device-1', 'device-2'])
  • has_next_page: true with a null cursor → iteration ends cleanly after page 1

Per 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

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
@razor-x
razor-x merged commit 3cf7f3e into main Aug 25, 2026
16 checks passed
@razor-x
razor-x deleted the claude/js-sdk-audit-6x115l-m6-loop-guard branch August 25, 2026 00:05
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.

2 participants