Skip to content

fix(sessions): do not forward session limit as Conversations page size - #4961

Open
tiagovilasboas wants to merge 3 commits into
openai:mainfrom
tiagovilasboas:fix/conversations-get-items-limit-4757
Open

fix(sessions): do not forward session limit as Conversations page size#4961
tiagovilasboas wants to merge 3 commits into
openai:mainfrom
tiagovilasboas:fix/conversations-get-items-limit-4757

Conversation

@tiagovilasboas

@tiagovilasboas tiagovilasboas commented Sep 11, 2026

Copy link
Copy Markdown

Summary

This pull request fixes OpenAIConversationsSession.get_items(limit=N) forwarding the SDK history cutoff as conversations.items.list(limit=N).

For a large finite session limit that exceeds the Conversations API page-size constraint, an otherwise valid Session.get_items(limit=N) call could fail before the OpenAI Python client paginated. Maintainer guidance on #4721 was to omit limit from the provider list call, let the client own pagination, and keep the SDK cutoff local.

The finite-history path now requests items in descending order without a provider page-size argument, stops locally once N items are collected, and reverses them into chronological order. Unlimited and zero-limit paths are unchanged.

Test plan

  • Added a regression that requests 101 newest-first items and asserts:
    • conversations.items.list() is called without limit
    • collection stops after exactly 101 items
    • the returned list is the newest 101 items in chronological order
  • uv run pytest -q tests/memory/test_openai_conversations_session.py tests/memory/test_session_limit.py — 56 passed
  • Independent ordinary review of the complete merge-base diff — clean; no findings
  • .agents/skills/code-change-verification/scripts/run.sh:
    • make format — passed
    • make lint — passed
    • make typecheck — passed (mypy + pyright, 0 errors)
    • make tests — 9611 passed, 29 skipped (parallel); 77 passed, 4 skipped, 55 deselected (serial)

Issue number

Fixes #4757

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

Omit limit from conversations.items.list so the OpenAI client paginates.
Apply the Session.get_items cutoff locally after collecting N newest items.
Assert get_items(limit=101) omits provider page size, stops after N items,
and returns the newest items in chronological order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAIConversationsSession get_items(limit>provider page size) forwards the session limit as provider page size

2 participants