From 4238ee0aa33222535b8b06b16d8dbe4dac153cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Alves?= Date: Tue, 16 Jun 2026 17:03:00 +0000 Subject: [PATCH] fix(writer-pipeline): stop eurohandball sitemap timeout error loop (BIT-25342) Narrow eurohandball pathIncludes to news/match pages, add pageTimeoutMs, and report per-URL sitemap probe failures as warnings so transient timeouts do not reopen ERRCLUSTER:97ab5f145754. Co-authored-by: Cursor --- .../config/andebol.net.sources.json | 8 +++--- .../src/cycle-error-report.test.ts | 27 ++++++++++++++++++- writer-pipeline/src/ingest-sources.ts | 3 ++- writer-pipeline/src/lib/cycle-error-report.ts | 11 +++++++- writer-pipeline/src/types.ts | 3 +++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/writer-pipeline/config/andebol.net.sources.json b/writer-pipeline/config/andebol.net.sources.json index 2d01984..04564da 100644 --- a/writer-pipeline/config/andebol.net.sources.json +++ b/writer-pipeline/config/andebol.net.sources.json @@ -31,9 +31,11 @@ "url": "https://www.eurohandball.com/sitemap.xml", "enabled": true, "topics": ["handball", "ehf"], - "maxItems": 25, - "pathIncludes": ["/competitions/", "/news/", "/calendar/", "/match-center/"], - "note": "EHF/Eurohandball: main sitemap is huge; path filter skips /club/ noise; pages fetched for title/summary (no LLM)." + "maxItems": 20, + "pathIncludes": ["/news/", "/match-center/"], + "timeoutMs": 25000, + "pageTimeoutMs": 35000, + "note": "EHF/Eurohandball: main sitemap is huge; path filter keeps news/match pages only (competition index URLs are heavy and not article content — BIT-25342)." }, { "id": "record_pt_main", diff --git a/writer-pipeline/src/cycle-error-report.test.ts b/writer-pipeline/src/cycle-error-report.test.ts index f15b22f..ec31d87 100644 --- a/writer-pipeline/src/cycle-error-report.test.ts +++ b/writer-pipeline/src/cycle-error-report.test.ts @@ -1,7 +1,7 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { initReporter, reportMessage, flush } from './lib/errorReporter.js'; -import { reportCycleErrors } from './lib/cycle-error-report.js'; +import { cycleErrorMessageLevel, reportCycleErrors } from './lib/cycle-error-report.js'; describe('errorReporter', () => { it('no-ops when disabled without token', async () => { @@ -12,6 +12,31 @@ describe('errorReporter', () => { }); }); +describe('cycleErrorMessageLevel', () => { + it('downgrades per-page sitemap probe failures to warning', () => { + assert.equal( + cycleErrorMessageLevel( + 'sitemap eurohandball_sitemap page (https://www.eurohandball.com/en/competitions/foo/): The operation was aborted due to timeout', + ), + 'warning', + ); + }); + + it('keeps whole-source sitemap failures as error', () => { + assert.equal( + cycleErrorMessageLevel('sitemap eurohandball_sitemap (https://www.eurohandball.com/sitemap.xml): HTTP 503'), + 'error', + ); + }); + + it('keeps sitemap truncation as warning', () => { + assert.equal( + cycleErrorMessageLevel('sitemap fpa: no pathIncludes and 500 URLs — truncating to 200 before maxItems'), + 'warning', + ); + }); +}); + describe('reportCycleErrors', () => { it('maps ingest error strings without throwing when reporter disabled', async () => { initReporter({ disabled: true, token: '' }); diff --git a/writer-pipeline/src/ingest-sources.ts b/writer-pipeline/src/ingest-sources.ts index 57b5332..8d73068 100644 --- a/writer-pipeline/src/ingest-sources.ts +++ b/writer-pipeline/src/ingest-sources.ts @@ -285,11 +285,12 @@ export async function ingestAllSources( errors.push(`sitemap ${source.id}: no URLs after filters`); continue; } + const pageTimeoutMs = source.pageTimeoutMs ?? source.timeoutMs ?? 30000; let ok = 0; for (const entry of slice) { try { const html = await fetchTextWithRetry(entry.loc, { - timeoutMs, + timeoutMs: pageTimeoutMs, retries, accept: 'text/html, application/xhtml+xml, */*', }); diff --git a/writer-pipeline/src/lib/cycle-error-report.ts b/writer-pipeline/src/lib/cycle-error-report.ts index db47def..f46ff06 100644 --- a/writer-pipeline/src/lib/cycle-error-report.ts +++ b/writer-pipeline/src/lib/cycle-error-report.ts @@ -1,5 +1,14 @@ import { reportError, reportMessage } from './errorReporter.js'; +/** Map ingest cycle strings to hub severity (partial sitemap page failures are warnings, not loops). */ +export function cycleErrorMessageLevel(message: string): 'warning' | 'error' { + if (!message.startsWith('sitemap')) return 'error'; + if (message.includes('truncating')) return 'warning'; + // Per-URL HTML probe failed but other pages in the same source may have succeeded. + if (/^sitemap .+ page \(https?:\/\//.test(message)) return 'warning'; + return 'error'; +} + /** Report writer-pipeline cycle failures to errors.bitreport.pt (ingest, publish, config). */ export function reportCycleErrors( site: string, @@ -7,7 +16,7 @@ export function reportCycleErrors( context: Record = {}, ): void { for (const message of errors) { - const level = message.startsWith('sitemap') && message.includes('truncating') ? 'warning' : 'error'; + const level = cycleErrorMessageLevel(message); reportMessage(message, level, { site, component: 'writer-pipeline', diff --git a/writer-pipeline/src/types.ts b/writer-pipeline/src/types.ts index 1fca51d..77944d9 100644 --- a/writer-pipeline/src/types.ts +++ b/writer-pipeline/src/types.ts @@ -12,7 +12,10 @@ export interface IngestSource { /** For sitemap: keep URLs whose path includes any of these substrings */ pathIncludes?: string[]; retries?: number; + /** Timeout for fetching the sitemap XML (and RSS/HTML source URL). */ timeoutMs?: number; + /** Timeout for each HTML page fetched from sitemap URL entries (defaults to timeoutMs or 30s). */ + pageTimeoutMs?: number; } /** @deprecated Use IngestSource with kind rss — kept for legacy JSON configs */ -- 2.47.3