Skip to content

Chat message pagination drops visible rows when reported messages sit in the Firestore page #12709

Closed

Description

@aryanorastar

GET /v2/messages (and the other get_messages callers) can return fewer than limit visible messages even when older visible messages still exist, and the next offset can advance past rows the client never saw.

Evidence

In backend/database/chat.py get_messages:

  1. Firestore applies .limit(limit).offset(offset) on the raw newest-first stream.
  2. Python then skips any row with reported is True.

So a reported row in the middle of a raw page steals a slot from a later visible message. Example newest-first stream [visible-a, reported, visible-b, visible-c] with limit=2 returns only [visible-a]; visible-b is never fetched on that page. Callers that stop after one page (mobile loads offset 0 once) or treat len < limit as EOF never see those messages.

The same failure class is already acknowledged elsewhere in this file:

  • get_cache_aligned_messages over-fetches raw rows specifically because filtering after limit drops visible history.
  • get_messages_reconcile_page uses a bounded scan budget so reported rows do not consume page capacity.

Offset pagination on get_messages itself still does the broken limit-then-filter path.

Call sites

/v2/messages, /v2/desktop/messages, MCP get_chat_messages, and related helpers all go through this function with limit/offset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions