Repository navigation
Conversation
Fixes Merit-Systems#1072. ORDER BY on tx_count/total_amount/etc had no secondary sort key, so Postgres could return tied rows in a different order between two separate paginated queries (LIMIT/OFFSET), duplicating or omitting rows across page boundaries. recipient/sender is already the GROUP BY key in both queries, so it's a ready-made unique tiebreaker. Extracted the ORDER BY builder into a dependency-free order-by.ts per service, since list-mv.ts transitively constructs live Prisma/neon/redis clients at import time and would otherwise be untestable in isolation.
Contributor
|
@Svector-anu is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
rsproule
approved these changes
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1072.
What changed
sellers/list-mv.tsandbuyers/list-mv.tssort by the requested column (tx_count,total_amount,latest_block_timestamp,unique_buyers/unique_sellers) with no secondary sort key. Postgres does not guarantee a stable order among tied rows across separate query executions, soLIMIT/OFFSETpagination can duplicate a tied row on one page and omit another entirely — matching this issue's report and the confirming comment ("pagination on the sellers list double-serves boundary rows on ties").recipient(sellers) /sender(buyers) is already theGROUP BYkey in both queries, so it's unique per row after grouping — a ready-made tiebreaker requiring no schema change.Fix
Added
recipient ASC/sender ASCas a secondary sort key to both queries (skipped for theeditorialsort in sellers, which already sorts byrecipientas primary — avoids a redundantORDER BY "recipient" ASC, recipient ASC).The SQL-building logic is extracted into new
order-by.tsfiles (one per service) so it's unit-testable in isolation —list-mv.tstransitively constructs live Prisma/neon/redis clients at module-import time (via@x402scan/transfers-dband@/lib/cache), which made the function untestable while colocated there.Reachability
Both queries are the live data source for the public sellers/buyers list endpoints — not test/mock code, reachable by any paginated request.
Verification
GROUP BY+ORDER BY+LIMIT/OFFSETshape of the actual query. Two ordinary sequential page requests (LIMIT 5 OFFSET 0thenLIMIT 5 OFFSET 5) against unchanged data returned an overlapping row at the boundary — no concurrent writes needed to trigger it, since Postgres's top-N sort doesn't guarantee consistent tie-break order between separate query executions., recipient ASC/, sender ASCin the generated SQL text); restored the fix → all 5 pass again.pnpm --filter @x402scan/app test -- --run→ 198/198 passing (18 files), no regressions.pnpm --filter @x402scan/app run types:checkoutput is byte-for-byte identical with and without this change (345 pre-existing errors either way, none in touched files) — confirmed viagit stash+ rerun, so those failures are pre-existing and unrelated to this PR.eslintclean on all touched files (--max-warnings 0).Also found, not fixed here (flagging, not bundling)
facilitators/list.tsandbuyers/sellers/list.tshave the identical missing-tiebreaker pattern. Left out of this PR to keep it scoped to the reported issue — happy to send a follow-up if useful, or an issue is fine too, whatever's preferred.Provenance
Fix drafted by an external agent (OpenAI Codex, GPT-5.6 via AgentRouter) in a sandboxed, git-less worktree; I (Claude) independently re-derived the root cause and reproduction from scratch first, then independently re-verified the drafted diff — reran the mutation-resistance check myself, restructured the testability approach after discovering the drafter's original design would have required stubbing the whole app's env-var validation to run in CI, and re-ran the full test/lint/typecheck suite myself before opening this PR.