Skip to content

fix(sessions): keep Conversations history limits local - #4759

Closed
sylvesterkaczmarek wants to merge 3 commits into
openai:mainfrom
sylvesterkaczmarek:fix/conversations-local-pagination-limit
Closed

fix(sessions): keep Conversations history limits local#4759
sylvesterkaczmarek wants to merge 3 commits into
openai:mainfrom
sylvesterkaczmarek:fix/conversations-local-pagination-limit

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Summary

This pull request fixes large OpenAIConversationsSession.get_items(limit=N) calls by keeping the SDK history limit local instead of forwarding it as the Conversations API page-size parameter.

The previous #4721 established the underlying failure, but its hard-coded provider page-size cap was closed in favor of a narrower maintainer-requested approach: omit limit from conversations.items.list(), let the OpenAI client handle provider pagination, stop locally once the requested number of items has been collected, then reverse the descending results back into chronological order.

This preserves the existing Session.get_items(limit=N) behavior without duplicating provider-owned pagination limits in the Agents SDK.

Test plan

  • Added a focused regression that requests 150 items from a 200-item descending stream.
  • Verifies the provider call receives no limit argument.
  • Verifies the SDK still returns exactly the newest 150 items in chronological order.

Issue number

Closes #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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T15:50:36.113937Z 2b147b7 PR opened
🔒 Security Review Completed 2026-08-29T15:55:27.958848Z 2b147b7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@linhongyu510 linhongyu510 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I independently checked the pagination contract on 2b147b7f. The installed OpenAI SDK AsyncCursorPage.__aiter__() iterates iter_pages(), which calls get_next_page() until exhaustion, so omitting the provider limit still traverses multiple provider pages while this loop stops locally at the resolved Session limit. The descending collection plus final reverse also preserves the Session contract of returning the newest N items in chronological order.

I ran the new pagination regression together with the existing tests/memory/test_openai_conversations_session.py suite from the PR snapshot: 39 passed. I found no blocking behavior issue in this change. This is independent local evidence only; the PR currently has not marked the repository verification checklist as completed.

@seratch

seratch commented Sep 7, 2026

Copy link
Copy Markdown
Member

This addresses the same paging bug as #4873 with the same runtime change. I recommend consolidating on #4873, whose regression also checks that collection stops at the requested count, and closing this duplicate. The intended contract remains newest-N Session items returned chronologically across API pages.

@seratch seratch closed this Sep 7, 2026
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

3 participants