Skip to content

fix: Read pagination from the response instead of a client hook - #640

Merged
razor-x merged 2 commits into
mainfrom
claude/python-sdk-audit-o2iid9-07-paginator-hooks
Aug 28, 2026
Merged

fix: Read pagination from the response instead of a client hook#640
razor-x merged 2 commits into
mainfrom
claude/python-sdk-audit-o2iid9-07-paginator-hooks

Conversation

@razor-x

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

Copy link
Copy Markdown
Member

What

The paginator captured the pagination envelope by appending a response hook to the shared client's event_hooks, making the request, then calling .pop() (SDK audit finding H4). That side-channel had four defects, all reproduced by the audit:

  • No try/finally: any failed page request (4xx/5xx, timeout) leaked the hook onto the client permanently — every later response on that Seam instance was force-read and JSON-parsed by a dead paginator's hook.
  • .pop() removes the last hook, not the paginator's own: two interleaved paginators cross-deleted each other's hooks. The async client made this the default failure mode — asyncio.gather over two paginators is normal usage.
  • A non-dict pagination value silently truncated flatten() to one page with no error.
  • The cursor-keyed _pagination_cache grew unbounded and used a "FIRST_PAGE" string sentinel that could collide with a real cursor.

The redesign removes the side-channel entirely:

  • Paginated routes now return a PaginatedList — a list subclass carrying the response's pagination envelope as an attribute. Callers of *.list() see no difference (isinstance(x, list), iteration, equality all unchanged). This is a codegen template change gated on hasPagination, so it lands at every paginated route at once, and any future request-level behavior reaches paginated requests for free (the drift-resistance property from the JS fix wave).
  • The paginator reads data.pagination directly: no hooks, no cache, no sentinel, nothing shared. A missing or non-object envelope raises SeamHttpInvalidResponseError (from fix: Raise a Seam error for a success response that is malformed #638) instead of silently truncating.
  • The paginator's client constructor parameter is retained for signature compatibility but no longer used.

Also bumps @seamapi/fake-seam-connect 2.0.5 → 2.0.6, which fixed /access_codes/list returning no pagination envelope (the same upstream fix the JS wave landed as fake-seam-connect #283) — the new envelope check caught it immediately.

Stacked on #639; diff shrinks as the stack merges.

Testing

New test/paginator_isolation_test.py: two async paginators under asyncio.gather each see their own pagination with zero hooks on the client; a failed page request leaves no hooks; missing/non-object pagination envelopes raise with pinned messages (sync + async); paginated routes still return a plain list carrying the envelope.

Revert check: with the old paginator restored, the tests fail with the audit's exact symptoms — one leaked hook after a failed request (assert 1 == 0 with the lambda visible), interfering concurrent paginators, and DID NOT RAISE on the truncation case.

Full suite: 232 passed; mypy, pylint (10.00), black clean; regeneration drift-free.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y1RzepycXEYA3LStfjt8cY


Generated by Claude Code

@razor-x
razor-x requested a review from a team as a code owner August 27, 2026 21:38
@razor-x
razor-x changed the base branch from main to claude/python-sdk-audit-o2iid9-06-param-guard August 28, 2026 00:15
@razor-x
razor-x force-pushed the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch from 4125828 to cf4d848 Compare August 28, 2026 19:30
@razor-x
razor-x force-pushed the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch from cf4d848 to 6fb281c Compare August 28, 2026 20:36
@razor-x
razor-x force-pushed the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch from 6fb281c to 02cf793 Compare August 28, 2026 20:43
@razor-x
razor-x force-pushed the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch from 02cf793 to 096d284 Compare August 28, 2026 21:04
@razor-x
razor-x force-pushed the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch from 096d284 to c009c74 Compare August 28, 2026 21:09
@razor-x
razor-x force-pushed the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch from c009c74 to 3144672 Compare August 28, 2026 21:12
Base automatically changed from claude/python-sdk-audit-o2iid9-06-param-guard to main August 28, 2026 21:17
@razor-x
razor-x force-pushed the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch from 3144672 to 14404c2 Compare August 28, 2026 21:17
@razor-x
razor-x merged commit 86dce9a into main Aug 28, 2026
23 checks passed
@razor-x
razor-x deleted the claude/python-sdk-audit-o2iid9-07-paginator-hooks branch August 28, 2026 21:23
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