From bc786f8c558c7baff281d37d46020576adba124a Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Tue, 10 Nov 2026 22:40:15 -0800 Subject: [PATCH] fix(news): Conflicts reports of the same time come in a fixed order GDELT exports are read in parallel, so two reports with the same time arrived in whichever order their exports finished, and the feed test that pages through them failed now and then. Same-time reports now order by most mentions, then by id. --- server/providers/news/keyed.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/providers/news/keyed.js b/server/providers/news/keyed.js index 7bd5ca464..574e44e5b 100644 --- a/server/providers/news/keyed.js +++ b/server/providers/news/keyed.js @@ -642,9 +642,16 @@ export function createKeyedNews({ await firstAnswer(inFlight.get('gdelt')); if (!current()) return { failed: true }; const dayAgo = new Date(now() - DAY_MS).toISOString(); + // Exports are read in parallel, so reports of one time arrive in any + // order: the most mentioned comes first, then by id. const reports = [...gdelt.reports.values()] .filter((r) => r.publishedAt >= dayAgo) - .sort((a, b) => b.publishedAt.localeCompare(a.publishedAt)) + .sort( + (a, b) => + b.publishedAt.localeCompare(a.publishedAt) || + b.mentions - a.mentions || + a.id.localeCompare(b.id), + ) .slice(0, MAX_GDELT_REPORTS); if (reports.length !== gdelt.reports.size) { const kept = new Set(reports);