Skip to content

fix(sessions): paginate OpenAI conversations session reads - #4956

Open
Neonstudio28 wants to merge 1 commit into
openai:mainfrom
Neonstudio28:fix/openai-conversations-session-pagination
Open

fix(sessions): paginate OpenAI conversations session reads#4956
Neonstudio28 wants to merge 1 commit into
openai:mainfrom
Neonstudio28:fix/openai-conversations-session-pagination

Conversation

@Neonstudio28

Copy link
Copy Markdown

Summary

OpenAIConversationsSession.get_items(limit=N) was forwarding the local session limit as the Conversations API page size. Provider page-size limits could therefore reject otherwise valid session reads before pagination ran. This change lets the existing async iterator own provider pagination, applies the session cutoff locally, and preserves chronological ordering.

Test plan

  • uv run pytest tests/memory/test_openai_conversations_session.py tests/memory/test_session_limit.py -q — 56 passed (16 existing asyncio deprecation warnings).
  • uv run ruff check src/agents/memory/openai_conversations_session.py tests/memory/test_openai_conversations_session.py — passed.
  • git diff --check — passed.
  • Targeted mypy and pyright checks for the changed runtime file — passed.
  • The repository verification wrapper completed formatting and linting, then stopped at pre-existing repository-wide type errors in sandbox/voice/optional-extension modules. The full test target also hit unrelated optional-environment and restricted-temp-directory failures; the changed session tests pass independently.

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

Copilot AI 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.

🟢 Approval recommended

No unresolved review comments remain, and all reviewers assessed it as ready.

Pull request overview

Fixes OpenAI Conversations session pagination by applying limits locally while preserving chronological ordering.

Changes:

  • Delegates provider pagination to the async iterator.
  • Adds regression coverage for local limits and ordering.
File summaries
File Summary
tests/memory/test_openai_conversations_session.py Verifies local limiting and pagination behavior.
src/agents/memory/openai_conversations_session.py Applies limits after provider pagination.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f44c8eb733

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 101 to 104
async for item in self._openai_client.conversations.items.list(
conversation_id=session_id,
limit=session_limit,
order="desc",
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound the provider page size for small limits

When callers use a small positive history limit (for example, get_items(limit=1)) on conversations containing large item payloads, omitting limit makes the paginator fetch its full default page before this loop can break. Previously the request fetched no more than the requested number of items; retain a provider-safe capped page size so oversized limits paginate but the common small-window path does not download unnecessary conversation data and add avoidable latency.

Useful? React with 👍 / 👎.

@seratch seratch changed the title fix: paginate OpenAI conversations session reads fix(sessions): paginate OpenAI conversations session reads Sep 11, 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