🤖 The AI Prompt That Reviews a Pagination Implementation for Pages That Skip or Repeat Rows When New Rows Are Inserted Mid-Scroll
Offset-based pagination assumes the underlying result set stays still between one page request and the next, and that assumption quietly breaks the moment new rows get inserted, or old ones deleted, while a user is still paging through results – every row’s position can shift by exactly enough to make the next offset either skip a row that moved past it or repeat one that moved back into view. This prompt has an AI assistant trace through a pagination implementation specifically looking for the places where it relies on row position staying fixed across requests, rather than the more commonly checked question of whether the page size and total count math is correct.
🔎 The Problem
THE PROMPT TO USE: "Here is my pagination implementation [paste the query or code that fetches each page, including how it computes offset/limit or any cursor it uses]. Assume rows can be inserted or deleted in the underlying table between one page request and the next. Walk through it and tell me: 1. Does this implementation use a numeric offset (page * page_size) or a cursor based on a stable column value from the last row seen? 2. If it's offset-based, trace through a concrete scenario: a user has fetched page 1 (rows 1-20 by creation date), then a new row is inserted that would sort ahead of row 20. When the user requests page 2 (offset 20), does the new row push what would have been row 20 back into page 2, causing it to appear twice, or does it push row 21 further down, causing it to be skipped entirely? 3. Check whether the sort order used for pagination is actually stable and unique - sorting only by a non-unique column (like creation date alone, with no tiebreaker) can reorder rows with identical values between requests even with no inserts or deletes at all. 4. If a cursor-based approach would avoid this, tell me specifically what stable, unique column (or combination) to cursor on given this schema." WHY IT WORKS: pagination bugs almost never show up in a test with a static, unchanging dataset, so asking the model to specifically trace an insert or delete happening mid-scroll surfaces exactly the failure mode that a normal fixed-dataset test can never expose.
✅ What a Good Answer Looks Like
- A concrete walkthrough of the skip-or-repeat scenario using this specific implementation’s actual offset or cursor logic, not a generic explanation of pagination theory.
- An explicit check of whether the sort order includes a unique tiebreaker column, since that gap causes problems even without any inserts or deletes happening at all.
- A specific, schema-aware recommendation for a cursor column or combination when a switch away from offset-based paging is the right call, not just a generic suggestion to use cursors.
🚨 What to Watch Out For
- Be skeptical of an answer that says offset pagination is fine because the table doesn’t change often – even a low-frequency insert or delete is still enough to skip or repeat exactly one row for exactly one user at exactly the wrong moment, and that’s precisely the kind of bug report that’s nearly impossible to reproduce after the fact.
Offset pagination asks every row to hold still between requests, and the instant a single insert or delete happens mid-scroll, that’s a promise the underlying data was never actually making.
