Skip to content

fix(conversations): compute has_more and support cursor pagination in list_items#5612

Open
vamsi-01 wants to merge 1 commit intoogx-ai:mainfrom
vamsi-01:fix/conversations-list-items-has-more-pagination
Open

fix(conversations): compute has_more and support cursor pagination in list_items#5612
vamsi-01 wants to merge 1 commit intoogx-ai:mainfrom
vamsi-01:fix/conversations-list-items-has-more-pagination

Conversation

@vamsi-01
Copy link
Copy Markdown

What does this PR do?

The Conversations list items API hardcoded has_more=False and ignored the after cursor parameter, which broke client-side paginators (e.g. OpenAI Agents SDK) when a conversation had more items than the default limit of 20. This meant users could silently lose conversation history beyond the first page.

The fix delegates ordering, cursor filtering, and limit to the sqlstore's fetch_all method (which uses the limit+1 pattern to determine has_more), matching the existing pattern used by responses_store. The after cursor from ListItemsRequest is now wired through so clients can paginate through all items.

Closes #5611

Test Plan

Added two unit tests covering the fix:

  • test_list_items_has_more_pagination, verifies has_more=True when items exceed limit, and False when they don't.
  • test_list_items_cursor_pagination, verifies multi-page cursor-based pagination produces non-overlapping pages covering all items.

All existing tests continue to pass (19 conversation tests, 11 responses-conversation tests).

uv run pytest tests/unit/conversations/test_conversations.py -x --tb=short -v

Output:

tests/unit/conversations/test_conversations.py::test_conversation_lifecycle PASSED
tests/unit/conversations/test_conversations.py::test_conversation_items PASSED
tests/unit/conversations/test_conversations.py::test_invalid_conversation_id PASSED
tests/unit/conversations/test_conversations.py::test_invalid_conversation_id_on_retrieve PASSED
tests/unit/conversations/test_conversations.py::test_invalid_conversation_id_on_update PASSED
tests/unit/conversations/test_conversations.py::test_invalid_conversation_id_on_delete PASSED
tests/unit/conversations/test_conversations.py::test_nonexistent_conversation_raises_conversation_not_found PASSED
tests/unit/conversations/test_conversations.py::test_retrieve_nonexistent_item_raises_conversation_item_not_found PASSED
tests/unit/conversations/test_conversations.py::test_openai_type_compatibility PASSED
tests/unit/conversations/test_conversations.py::test_items_not_returned_on_creation_or_retrieval PASSED
tests/unit/conversations/test_conversations.py::test_policy_configuration PASSED
tests/unit/conversations/test_conversations.py::test_add_items_defaults_message_type PASSED
tests/unit/conversations/test_conversations.py::test_create_conversation_defaults_message_type PASSED
tests/unit/conversations/test_conversations.py::test_list_items_has_more_pagination PASSED
tests/unit/conversations/test_conversations.py::test_list_items_cursor_pagination PASSED
============================== 15 passed in 0.88s ==============================

End-to-end verification with 25 items (more than the default limit of 20):

# Creates 25 items, then paginates through them
result = await svc.list_items(ListItemsRequest(conversation_id=conv.id))
# Items returned (default limit): 20
# has_more: True   <-- was False before this fix

# Paginating with limit=10:
# Page 1: 10 items, has_more=True
# Page 2: 10 items, has_more=True
# Page 3: 5 items, has_more=False
# Total items retrieved via pagination: 25

… list_items

The Conversations list items API hardcoded has_more=False and ignored
the after cursor parameter, which broke client-side paginators like the
OpenAI Agents SDK when a conversation had more items than the default
limit of 20.

Delegate ordering, cursor filtering, and limit to the sqlstore's
fetch_all method (which uses limit+1 to determine has_more), matching
the existing pattern in responses_store. Wire through the after cursor
from ListItemsRequest so clients can paginate through all items.

Closes: ogx-ai#5611
Signed-off-by: Vamsi Mathala <vmathala@redhat.com>
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.

Conversations API hardcodes has_more=False

1 participant