diff --git a/backend/src/controllers/stream.controller.ts b/backend/src/controllers/stream.controller.ts index 5476fb6e..b7670e84 100644 --- a/backend/src/controllers/stream.controller.ts +++ b/backend/src/controllers/stream.controller.ts @@ -316,7 +316,11 @@ export const getStreamEvents = async (req: Request, res: Response) => { const [events, total] = await Promise.all([ prisma.streamEvent.findMany({ where: whereClause, - orderBy: { timestamp: order }, + // `timestamp` is not unique (events in the same block/ledger can + // share a timestamp), so it can't be the sole sort key for cursor + // pagination. Add `id` as a unique tiebreaker so ordering (and + // therefore cursor pagination) is stable across pages. + orderBy: [{ timestamp: order }, { id: order }], take: limit, ...(cursor ? { cursor: { id: cursor }, skip: 1 } @@ -770,4 +774,4 @@ export const resumeStream = async (req: Request, res: Response) => { logger.error('Error resuming stream:', error); return res.status(500).json({ error: 'Internal server error' }); } -}; +}; \ No newline at end of file