Skip to content

Commit b6e642f

Browse files
committed
fix(webapp): correct backward pagination slice on session list
Devin catch on #3417 — the ClickHouse sessions list was slicing `sessionIds.slice(1, size + 1)` on the backward path, which skipped the item closest to the cursor and surfaced the sentinel (the `size+1`th item that proves hasMore=true) to the user. Trace, with items c01…c11 and cursor=c07 (page size 3): - Backward query: `session_id > c07 ORDER BY ASC LIMIT 4` → `[c08, c09, c10, c11]`. Legitimate content is the first three (`[c08, c09, c10]`); `c11` is the sentinel. - Previous slice: `[c09, c10, c11]` → displayed DESC `[c11, c10, c09]` — user never sees c08, sees sentinel c11 instead. Fix: collapse both directions to `sessionIds.slice(0, size)`. The sentinel is always the last item regardless of direction, so the two branches had no reason to diverge. Cursor computations (`previousCursor = reversed.at(1)`, `nextCursor = reversed.at(size)`) already line up with the corrected slice — no change needed there. Verified: webapp typecheck clean.
1 parent 84d3db1 commit b6e642f

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

apps/webapp/app/services/sessionsRepository/clickhouseSessionsRepository.server.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ export class ClickHouseSessionsRepository implements ISessionsRepository {
7474
}
7575
}
7676

77-
const idsToReturn =
78-
options.page.direction === "backward" && hasMore
79-
? sessionIds.slice(1, options.page.size + 1)
80-
: sessionIds.slice(0, options.page.size);
77+
// Both directions slice the first `size` IDs: the `size+1`th item is
78+
// the sentinel proving another page exists (hasMore), not part of the
79+
// page content. Backward queries sort ASC (items closest to the cursor
80+
// first), so `[0..size)` is still the legitimate window and the last
81+
// element is the sentinel — identical to the forward case.
82+
const idsToReturn = sessionIds.slice(0, options.page.size);
8183

8284
let sessions = await this.options.prisma.session.findMany({
8385
where: {

0 commit comments

Comments
 (0)