Skip to content

Migrate offset pagination to stable keyset cursors #284

Description

@lamenting-hawthorn

Problem

Several session/turn list operations use opaque page tokens backed by SQL/in-memory offsets. Deep offset pagination becomes increasingly expensive because stores must scan and discard preceding rows, and concurrent inserts can shift page boundaries.

Adding an arbitrary maximum offset would be a breaking product-policy choice rather than a durable fix: legitimate clients eventually hit the ceiling and previously issued deep tokens become invalid.

Proposed direction

Move the affected list operations to stable keyset/cursor pagination using an existing ordering key and deterministic tie-breaker. Preserve the existing opaque page_token HTTP contract so clients do not depend on cursor internals.

Design questions

  • Which resources should migrate first: sessions, turns, or both?
  • What ordering tuple should each cursor encode to remain stable across equal timestamps?
  • Must previously issued offset tokens remain valid during a transition?
  • Should previous-page navigation remain supported, and what reverse-query contract should stores use?
  • Can the existing session-event cursor implementation serve as the canonical pattern?

Acceptance criteria

  • Query cost does not grow linearly with page depth.
  • No duplicates or omissions under inserts between page requests for the documented ordering semantics.
  • In-memory, SQLite, and Postgres stores pass the same pagination contract tests.
  • Tokens remain opaque and malformed tokens fail deterministically.
  • Any migration/backward-compatibility behavior is documented before implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions