zot fetch: Z1 review deferrals — lazy selection before the Z3 timer, plus minors #828

Open
opened 2026-09-24 23:52:03 +00:00 by kert · 1 comment
Owner

Deferred from the fresh-context review of PR #826 (stack zot fetch, slice Z1). None affects the manual, targeted runs Z1 is for; the first one blocks the Z3 timer.

Blocks Z3 (timer)

  • Lazy selection. zot.fetch.select.select_items materialises every eligible item (get_item → fields/creators/tags/collections, plus get_item_type and has_full_text per id) before the first attempt, while the Zotero desktop is stopped under --hold. --all on ~167k file-less items will hold the desktop down for minutes before --limit can bite. Yield lazily (generator, or ids first and item_ref only after the ledger gate) and fold the deleted/full-text exclusions into the id query.

Minor

  • Title search (resolve.title_candidates) is unverified against a real libgen index.php page — the fixture is synthetic and the spec's "index page parser the AMA script already exercises" does not exist. Capture a real results page (a search through the proxy returned no rows on 2026-09-22) and pin the anchor regex; ([^<]*) also yields an empty title on nested markup.
  • Anna's: a 200 with download_url: null is retried on every candidate of every item instead of disabling Anna's after the first non-md5-specific error; and Anna's is tried once per libgen md5 per item, so an item with several md5s can spend several daily units on one bad CDN day. Consider one Anna's attempt per item.
  • --no-hold on a locked DB surfaces a raw sqlite3.OperationalError rather than a BadParameter naming the desktop.
  • --dry-run still stops/starts the Zotero desktop; either skip the hold for dry runs (reads are safe under WAL) or say so in the help. The env vars (VPN_HTTP_PROXY, ANNAS_ARCHIVE_KEY, ANNAS_DAILY_RESERVE, UNPAYWALL_EMAIL) are not in --help.
  • attach.append_extra strips leading whitespace from an existing extra; use rstrip("\n") + "\n" + line.
  • Scratch dir .state/zot/fetch/ is not swept at run start (per-item cleanup covers exceptions; a KeyboardInterrupt mid-stream still leaves a partial file).
  • select.first_isbn flattens hyphens but not spaces (978 1 64016 228 0 → no ISBN).
  • Budget: annas_left is taken verbatim from the API's downloads_left; if live observation shows the API reports the pre-call count, decrement once (else the reserve is breached by one per run).

Also noted (pre-existing, not this branch)

  • The repo-wide coverage gate: --cov-fail-under=99 prints FAIL at 98.94–98.95% on main and the CI job still reports success, so the gate is not enforced.
Deferred from the fresh-context review of PR #826 (`stack zot fetch`, slice Z1). None affects the manual, targeted runs Z1 is for; the first one blocks the Z3 timer. ## Blocks Z3 (timer) - [ ] **Lazy selection.** `zot.fetch.select.select_items` materialises every eligible item (`get_item` → fields/creators/tags/collections, plus `get_item_type` and `has_full_text` per id) before the first attempt, while the Zotero desktop is stopped under `--hold`. `--all` on ~167k file-less items will hold the desktop down for minutes before `--limit` can bite. Yield lazily (generator, or ids first and `item_ref` only after the ledger gate) and fold the deleted/full-text exclusions into the id query. ## Minor - [ ] Title search (`resolve.title_candidates`) is unverified against a real libgen `index.php` page — the fixture is synthetic and the spec's "index page parser the AMA script already exercises" does not exist. Capture a real results page (a search through the proxy returned no rows on 2026-09-22) and pin the anchor regex; `([^<]*)` also yields an empty title on nested markup. - [ ] Anna's: a 200 with `download_url: null` is retried on every candidate of every item instead of disabling Anna's after the first non-md5-specific error; and Anna's is tried once per libgen md5 per item, so an item with several md5s can spend several daily units on one bad CDN day. Consider one Anna's attempt per item. - [ ] `--no-hold` on a locked DB surfaces a raw `sqlite3.OperationalError` rather than a `BadParameter` naming the desktop. - [ ] `--dry-run` still stops/starts the Zotero desktop; either skip the hold for dry runs (reads are safe under WAL) or say so in the help. The env vars (`VPN_HTTP_PROXY`, `ANNAS_ARCHIVE_KEY`, `ANNAS_DAILY_RESERVE`, `UNPAYWALL_EMAIL`) are not in `--help`. - [ ] `attach.append_extra` strips leading whitespace from an existing `extra`; use `rstrip("\n") + "\n" + line`. - [ ] Scratch dir `.state/zot/fetch/` is not swept at run start (per-item cleanup covers exceptions; a `KeyboardInterrupt` mid-stream still leaves a partial file). - [ ] `select.first_isbn` flattens hyphens but not spaces (`978 1 64016 228 0` → no ISBN). - [ ] Budget: `annas_left` is taken verbatim from the API's `downloads_left`; if live observation shows the API reports the pre-call count, decrement once (else the reserve is breached by one per run). ## Also noted (pre-existing, not this branch) - The repo-wide coverage gate: `--cov-fail-under=99` prints FAIL at 98.94–98.95% on main and the CI job still reports success, so the gate is not enforced.
kert added this to the P51: Zotero full-text connector — Unpaywall, libgen, Anna's (Z1–Z4) milestone 2026-09-24 23:52:03 +00:00
kert added the bib label 2026-09-24 23:52:03 +00:00
Author
Owner

Open-access stack zot fetch is on main (bee5f57, docs d1165cd). It reuses Z1's select / ledger / attach / run machinery, and delivery is the stack's legal open-access cascade only: Unpaywall → Semantic Scholar → PMC S3 → PMC OA → Europe PMC. PR #826 and feat/zot-fetch-z1 are untouched.

Done from this list:

  • Lazy selection. select_ids() is one cheap query. For --all, deleted and full-text items are excluded in SQL. iter_refs() reads each item only when the run reaches it, so --limit cuts in before the rest are read. Covered by tests.
  • --no-hold on a locked DB. The run aborts with a usage error that names the Zotero desktop, instead of a raw sqlite3.OperationalError or one error per item.
  • --dry-run. Read-only, checked against the running desktop, so it no longer stops or starts zotero. UNPAYWALL_EMAIL is now in --help.

Not addressed in the main version: the libgen title-search and Anna's retry/budget items, which only apply to the branch's libgen and Anna's delivery.

Live check on 2026-10-27, run with --item and --hold:

  • 6F8PR88G and MJIDPX7R: PDFs attached, from PMC and Unpaywall respectively.
  • HXG2IZI3 and SS8KYXQW: ledgered no_candidate.
  • Zotero restarted healthy after each run.
Open-access `stack zot fetch` is on main (bee5f57, docs d1165cd). It reuses Z1's select / ledger / attach / run machinery, and delivery is the stack's legal open-access cascade only: Unpaywall → Semantic Scholar → PMC S3 → PMC OA → Europe PMC. PR #826 and `feat/zot-fetch-z1` are untouched. Done from this list: - [x] **Lazy selection.** `select_ids()` is one cheap query. For `--all`, deleted and full-text items are excluded in SQL. `iter_refs()` reads each item only when the run reaches it, so `--limit` cuts in before the rest are read. Covered by tests. - [x] **`--no-hold` on a locked DB.** The run aborts with a usage error that names the Zotero desktop, instead of a raw `sqlite3.OperationalError` or one error per item. - [x] **`--dry-run`.** Read-only, checked against the running desktop, so it no longer stops or starts zotero. `UNPAYWALL_EMAIL` is now in `--help`. Not addressed in the main version: the libgen title-search and Anna's retry/budget items, which only apply to the branch's libgen and Anna's delivery. Live check on 2026-10-27, run with `--item` and `--hold`: - 6F8PR88G and MJIDPX7R: PDFs attached, from PMC and Unpaywall respectively. - HXG2IZI3 and SS8KYXQW: ledgered `no_candidate`. - Zotero restarted healthy after each run.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: homelab/stack#828