GPT-5 finding
Cross-repo receipts loader can silently underfill the requested limit due to post-query filtering
mediumdata-losshigh
- apps/web/lib/receipts.ts
- apps/web/lib/receipts.ts
The DB query filters only by status='merged' and limits by mergedAt order. Rows with status='merged' but missing mergeSha (or, less likely, mergedAt=null) are returned and then dropped by mapMergedRowsToReceipts. If such invalid rows fall within the top N by mergedAt, the mapped list can contain fewer than the requested limit even when more valid rows exist beyond the limit, leading to an unexpectedly short set and inconsistent pagination semantics.
Recommendation
Tighten the WHERE clause to also require non-null mergedAt and mergeSha (e.g., add isNotNull(outgoingPrs.mergedAt) AND isNotNull(outgoingPrs.mergeSha)). Optionally add a CHECK constraint or trigger to enforce that rows in status='merged' must have non-null mergedAt and mergeSha.