fix: Stop the paginator when a page cursor repeats - #575
Open
razor-x wants to merge 1 commit into
Open
Conversation
flatten and flatten_to_list looped on has_next_page with no memory of the cursors already used, so a server regression or proxy-cached page that pinned one cursor hung flatten forever and grew flatten_to_list without bound. Nothing else halts the loop, since the per-request timeout resets on every page. Walk the pages once in a private enumerator shared by both methods, remembering each cursor and stopping when a cursor repeats, is nil, or is empty. Also drop the paginator's unused require of http, which loaded the client circularly. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SQW83gyXeUG61RDrHEky97
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.
Paginator#flattenand#flatten_to_listlooped onhas_next_page?with no cursor-repeat detection and no page bound. A server regression or proxy-cached page that returns the samenext_page_cursorhungflattenforever and grewflatten_to_listuntil the process ran out of memory. The per-request timeout resets on every page, so nothing else stopped it.Fix
Ported from seamapi/python#641 and seamapi/php#466: one private
walkenumerator yields each page once, remembers the cursors it has used, and stops when a cursor repeats, is nil, or is empty. Both public methods consume it, so the guard cannot drift between them.Also drops the paginator's unused
require_relative "http", which loaded the client circularly.Tests
New
spec/seam_client/paginator_loop_guard_spec.rb(WebMock): a server that pins one cursor yields exactly two pages and two requests for bothflattenandflatten_to_list; a page reportinghas_next_page: truewith no cursor stops after the first page.Revert-check against
main: the repeated-cursor specs never finish and had to be killed by a 60s timeout.🤖 Generated with Claude Code
https://claude.ai/code/session_01SQW83gyXeUG61RDrHEky97
Generated by Claude Code