opentextbooks: a run can completely fail with a misleading "all books failed" error when only open.umn.edu's own rate-limiting kicks in

Open
#211 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@pawank925 is already working on this.

Since Nov 17, 2026.

  • #212 by @pawank925 — open

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Start with core/download_engine.py and its fetch_bytes_with_retry handling of 429 responses, then read core/pipeline.py's process_one() to see how attempts affect progress and failures. Compare the shared host pacing and Retry-After handling described for sotoki and mwoffliner. Done means throttled requests are paced or retried appropriately and progress or the final error distinguishes attempts from successful books; pull request #212 is already open.

Written by the indexing model from the issue text.

Description

Summary

A real production task (open-textbook-library_ko_all, task fefe81ae-9a44-4137-b920-b1bc8cb33555) failed with:

RuntimeError: All books failed to process. Cannot create ZIM without any content.

despite the task's own progress reporting showing 95% (254/267) done right before the failure — which reads as "it got almost all the way there, then died," but the actual error says zero books succeeded. That apparent contradiction is itself confusing to debug, on top of the underlying failure.

Root cause

  • open.umn.edu (Open Textbook Library's own site) started returning 429 Too Many Requests on the per-book metadata endpoint (https://open.umn.edu/opentextbooks/textbooks/<id>.json), visible for books 1966/1986 in the captured log tail.
  • core/pipeline.py's process_one() wraps each book in a bare except Exception and always calls self.progress.increase_progress() regardless of outcome — so the progress counter tracks attempts, not successes. That's why 95%/254-267 isn't actually meaningful here: it's entirely possible most/all of those "done" books individually failed their metadata fetch (via repeated 429s) and simply never got added to store.works, which is what then triggers compute_flame_ratings's "All books failed to process".
  • core/download_engine.py's fetch_bytes_with_retry does treat 429 as non-fatal and retries with exponential backoff, but: (a) it doesn't honor a Retry-After header if OTL sends one, and (b) there's no shared/global pacing across the pipeline's concurrent per-book workers hitting the same host — so under sustained throttling, many/most of the concurrent requests can each independently exhaust their own max_retry_time=30 budget and fail around the same time, rather than the pipeline backing off as a whole.

Prior art in other openZIM scrapers

We already have working solutions for exactly this ("one host rate-limits us, and the fleet needs to share pacing instead of each request retrying blindly on its own") in two sibling scrapers:

  • sotoki (src/sotoki/utils/imager.py, Imager/HostData): each hostname gets its own adaptive request_interval_milliseconds, honored by a shared scheduling loop so all workers pace themselves against that single shared per-host clock. It explicitly parses Retry-After (parse_retry_after_header, with a per-host exclusion list for hosts known to send bad values) to set a not_before_date, and multiplicatively slows down the per-host interval on 429/503/403/524 (capped at a max interval) while gradually speeding back up after sustained success. Failed downloads are requeued rather than permanently dropped, and the whole run only aborts via a global failure-ratio circuit breaker, not on transient zero-successes-so-far.
  • mwoffliner (src/Downloader.ts): a single shared Downloader instance centralizes backoff (exponential, 1s–60s, failAfter: 10 ⇒ ~6 min budget) for every request against the wiki, explicitly retrying on 429/500/502/503/504/524, bounded by the overall --speed/worker-count and pageRequestInterval settings — i.e. one shared, centrally-paced pipeline per host rather than N independent per-request retry loops.

Suggested fix directions

  1. Respect Retry-After on 429 responses from fetch_bytes_with_retry instead of just blindly exponential-backing-off (see sotoki's parse_retry_after_header).
  2. Shared/adaptive per-host pacing for metadata fetches, along the lines of either prior-art approach above, rather than each concurrent worker retrying independently with no awareness of the others.
  3. Separately: make progress reporting (or at least the final error) distinguish "attempted" from "succeeded" so a run that quietly failed every book doesn't look like it got 95% of the way there.
Dominant language
Python
Stars
7
Forks
4
Avg merge
16h 45m
Merged PRs (30d)
67

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openzim/papers

All issues in openzim/papers

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.