Skip to content

fix(pipeline): retry a raw file whose download drops part-way - #3

Merged
clay-good merged 1 commit into
mainfrom
fix/raw-fetch-retry
Nov 15, 2026
Merged

clay-good merged 1 commit into
mainfrom
fix/raw-fetch-retry

Conversation

@clay-good

Copy link
Copy Markdown
Owner

Status: LGTM — ready to merge. Closes #2.

What was wrong

The scheduled EIA-930 check failed on 2026-11-10 with:

hourly: schema: PJM: fetch failed; raw file PJM was never read to the end, so its SHA-256 is unknown

fetch failed is undici's message for a connection that never completed. Nothing in the pipeline retried a raw-file download — pipeline/run.mjs had three bare fetch calls and no retry anywhere in the repo. So the first dropped socket ended the run: xlsxOf never finished reading the body, r.sha256 stayed null, and the integrity check at run.mjs:309 failed the whole refresh.

That is an expensive way to lose a month. EIA rebuilds a workbook for every balancing authority daily and the largest are over 100 MB; the run downloads 69 of them in a row. One blip in 69 large downloads lost the refresh, and the previous version stayed live.

How it was fixed

Raw files now go through fetchRaw, which tries three times with a growing pause (2s, then 4s).

The important detail is where the body is read. read is called inside the attempt, so a failure part-way through a 100 MB download is retried from the start of the download rather than leaving a half-built hash. Retrying only the connection would not have been enough for a file this size.

What does not change:

  • A 4xx other than 408/429 is the publisher's own answer, not a blip. It comes back unread, immediately, on the first attempt — a missing file is not requested three times.
  • Every caller reports failures exactly as before. The HTTP 503 and HTTP 404 messages, and the thrown network error, are byte-for-byte what they were; only the number of attempts before them changed.
  • Opening a streamed file (linesOf, used by EAGLE-I's yearly CSVs) is retried, but a drop once bytes are flowing still fails the run — the hash is part-built by then and the read cannot restart. This is called out in the comment rather than papered over.

Proof it works

verify/tests/pipeline/raw-fetch.test.mjs, 7 tests, all passing:

Test What it pins
a dropped connection is retried the exact TypeError: fetch failed from the issue, twice, then success
a connection that never comes back the publisher's own error is rethrown after 3 attempts, not swallowed
a failure part-way through the body the reproduction: a stream that errors mid-body is downloaded again
a 503 is retried retried, and the last response is returned so the caller still says HTTP 503
a 404 is returned at once, unread calls === 1 — no pointless retries on a real answer
no reader hands back an unread response the body is still streamable for linesOf
the wait grows with each attempt [100, 200] — a briefly overloaded publisher is not hammered

Full unit suite passes.

Notes / nits

  • attempts, delayMs, fetch, and sleep are injectable only so the tests do not sleep for real. This matches how linkCheck already takes { fetch, host, root, now }.
  • Not a new module, so no docs/own-implementations.md entry is needed — it is a helper inside run.mjs, used only there.
  • This makes the download robust. It does not retry a run that fails validation, which is correct: a validator failure means the data changed, not that the network hiccuped.

🤖 Generated with Claude Code

The scheduled EIA-930 check failed on 2026-11-10 because the PJM
workbook's download was dropped: nothing retried it, so the file was
never read to the end, its SHA-256 stayed unknown, and the whole refresh
failed while the previous version stayed live. EIA rebuilds a workbook
per balancing authority every day and the largest are over 100 MB, so
one dropped socket in sixty-nine downloads lost the month's refresh.

Raw files now go through fetchRaw, which tries three times with a
growing pause. The body is consumed inside the attempt, so a failure
part-way through a 100 MB download is retried from the start rather than
leaving a half-built hash. A 4xx other than 408 or 429 is the
publisher's own answer, not a blip: it comes back unread at once and
every caller reports it exactly as before, so no failure message or
status changes. Opening a streamed file is retried too, though a drop
once its bytes are flowing still fails the run, since the hash is
part-built by then and the read cannot restart.

Closes #2.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@clay-good
clay-good merged commit 85f3e3b into main Nov 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pipeline: eia-930 refresh failed

1 participant