directory-pipeline

Release 0.3: landing plan and pre-release review

Created 2026-10-17. Status: Ready for the PRs. Decisions are made, and Phases 0 and 2 are done locally, on branch release-0.3:

release-0.3 is more than 50 commits ahead of local main, which is 13 ahead of origin/main. A clean checkout passes CI’s steps: ruff, 695 tests passing with 16 skipped (the ones that need the local registry), and the full dry-run matrix.

Nothing is pushed yet. Remaining: Phase 0’s pushes, then Phases 1, 3, 4 and 5.

This replaces PR #10’s framing as “base for the 0.3 release”. Most of #10 is already on main as cherry-picks, and the rest has been rebased into alignment-column-criterion.

Where things stand

v0.2.0 was tagged 2026-06-11. Since then the work has spread across five places.

Stream Where Commits State
ALTO export, column-merge detector, slice_manifest.py, prompt contracts, leaf-script state, manual-alignment preservation, … origin/main 47 (+5 merges) pushed, CI green 2026-09-15
OCR retry ladder and degenerate detection, entry binder, Gemini default bumps, measured cost accounting, LoC fixes local main 13 not pushed. 489 tests pass, ruff clean
Per-column alignment, running heads, shared column detection, inversion-aware selection alignment-column-criterion 5 sits on local main’s tip. Supersedes PR #10
Collection registry, ad-delimiter NER, section column and explorer switch, thumbnail sizing, Surya --blank-threshold, unmatched-rate outliers ocr-retry-hardening (aee65e7..8740c4a) 11 never reviewed; see the review below
Blank-page fix, interrupted-download repair; gutter-hoist evidence and plan working tree of ocr-retry-hardening — uncommitted

ocr-retry-hardening is the old linear trunk. Its other 25 commits are copies of what is now on main and alignment-column-criterion. Only the 11 commits above, plus the working tree, are unique to it.

The whole stack lands linearly, in this order: main, then alignment-column-criterion, then the 11, then the working tree, then the fixes.

It was replayed in a scratch worktree on 2026-10-17:

Side branches

Branch What Recommendation
origin/claude/jev-directory-pipeline-ljnhjt Jev evaluation (docs, 1 commit) merge, like the Lorya review
claude/data-explorer-improvements-b546iu explorer-improvements plan (docs, 2 commits) merge
claude/local-ocr-city-directories-ey5741 --local-ocr backend using Chandra MLX or Apple Vision (8 commits, 7 unpushed) 0.4; see the note below this table
htr-alto-experiments experimental line-crop OCR fallback (1 commit, local only) tag archive/…, push the tag, delete the branch
origin/claude/load-external-csv-sMJ70 --external-csv for explorer and map (March, before 0.2) tag and delete; the explorer has since been rewritten
origin/claude/analyze-test-coverage-zOZ5Y PR #4, closed delete; superseded by the test suite

Why local OCR waits for 0.4:

Push it now as a backup.

Delete these after the tag; they are merged or superseded:

Three worktrees are stale, all detached on merged commits:

Open PRs

#10 (alignment-running-heads): close it as superseded by the release PR.

#5 (Fondren-Rice, PDF input) is an outside contribution. It has been open since 2026-05-13 with no reply and now conflicts. It cannot merge as written:

Reply before tagging either way. A reasonable 0.4 item that would credit the contributor: a PDF source that writes a synthetic manifest.json, the way slice_manifest.py does.

Pre-release review

Scope:

Findings are ordered by severity.

Blockers: CI goes red, or a shipped feature breaks

B1. Sixteen tests depend on a gitignored file. Two parametrized tests in tests/test_collections.py assert judgements that live in analysis/collection_registry.local.txt:

They pass on this machine and fail in any fresh clone, CI included. Either point them at a tmp_path registry (or the .example file), or skipif the local file is absent. The rest of that test file already tests layering with tmp_path.

B2. Explorer and map thumbnails break on IIIF Image API 3 services, the Green Books among them. Commit cfafcaf requests size full for any crop narrower than the display width (pipeline/explore_entries.html:793, pipeline/geo/map_entries.py:165). Checked live on 2026-10-17:

service full max
iiif.nypl.org/iiif/3/ (Cantaloupe, v3) 400 “Invalid size” 200
tile.loc.gov (v2) 200 400

No single keyword works for both. The repo already records this split: utils/iiif_utils.image_url() (line 187) says v3 needs max and v2 needs full, and names Internet Archive as a v3 server.

The fix:

B3. tools/analyze_retry_ladder.py never excludes a collection. The shadowing happens like this:

  1. It imports utils.collections.classify (line 61).
  2. It then defines its own classify(message) (line 95), which replaces the import.
  3. The filter at line 244, classify(part)[0], now gets a kind string such as "unknown".
  4. It takes the first letter of that string, which is always truthy, so nothing is excluded.

--all-collections therefore changes nothing, and nothing reports it. No test covers this path. Alias the import (classify as classify_collection) and add a test.

B4. ruff fails. The four errors:

The branch’s other two errors are already fixed on main and disappear in the replay: F821 (item_id in sources/loc_utils.py) and F541 (tools/report_cost.py).

Fix before tagging: cheap now, a schema or UX break once released

F1. The new section column collides with NER schemas. extract_entries.py:1168 and :1238 call entry.setdefault("section", page_section).

Several prompts already use a section field:

Two consequences:

Decide the contract before 0.3 writes it into published CSVs. Two options:

Renaming after release is a CSV schema change for green-books.

F2. The build_aligned_lines() docstring describes the rejected rule. pipeline/align_ocr.py:982 says “the one leaving less Gemini text unboxed wins”. That is the coverage rule the 2026-09-04 evidence folder exists to stop someone restoring. The code actually calls _alignment_cost(). A one-sentence fix.

F3. Two leaf-only flags that the release depends on. main.py and pipeline forward neither:

The new align outlier report (align_ocr.py:958) tells users to “try –blank-threshold 0.5 on those pages”. But run_surya_ocr.py has no page selection and no --force; its only flags are --batch-size, --blank-threshold and --quiet. Following the hint today means:

  1. Delete those pages’ _surya.json files by hand.
  2. Re-run the leaf script with the flag.
  3. Re-align.

Two ways to fix it:

F4. Align records its stage on partial failure. align_ocr.py:1646 gates on counts["ok"] alone. OCR now gates on no failures and no corrupt pages, for the reason given in its own comment: a 1%-finished run must not look like a clean one, because main.py trusts the state file. Apply the same one-line rule here.

F5. Old [OCR FAILED] placeholders are treated as finished pages. Before 6b165df, a page that failed every retry got a .txt containing [OCR FAILED: page could not be transcribed after all retries]. 6b165df stops writing them, but the skip check in process_image() only re-runs empty files. So existing placeholders are never retried, and align and extract read the placeholder as page text.

Found 2026-10-17: 17 placeholders in output/, in 8 collections:

Fix: treat a file starting [OCR FAILED like an empty one (delete it and retry).

Say it in the release notes

Per-column alignment on city directories. The evidence folder (docs/evidence/2026-09-04-column-selection-criterion/) says Tulsa makes more bad picks than the rule it replaced. That figure is an artifact; correct the README before release. Its harness has two faults:

Re-run on 2026-10-17, compare_criteria.py still prints “inversion-aware 20/22” for 100 Tulsa pages. But on those same pages the selection step ran once, and all 22 “whole-page picks” are alignments that differ while binding the same number of lines.

To fix the harness, take the whole-page candidate from production’s revert path (_build_line_aligned_lines(fallback_order, …)) and compare the outputs themselves. Tulsa 1921 under the 0.3 code: a fresh alignment matches the tree on disk on 149 of 150 sampled pages, and the column path completed on 1 of 59 multi-column pages.

The green-books audit of 2026-09-05 recommends shipping the inversion-aware selection as a code fix.

A placement pilot on 2026-10-17 narrowed this.

Results:

The pilot’s limits:

Reading of the result: on city directories the per-column path rarely completes. On the panel and on Tulsa there is no measurable gain where it ran, and it mostly did not run. It says nothing about columns 3+. The levers are the gutter-hoist fix and column-start location, both 0.4. An opt-out flag is not needed for 0.3.

The pilot is now docs/evidence/2026-10-17-column-alignment-panel/.

Gutter hoist (docs/plans/gutter-hoist-fix.md): about 450 lines are mis-bound on 1,676 pages, and Guard 1 reverts 960 more. Deferred, with a plan.

The blank-page fix changes which pages get OCR’d. The old check silently skipped 1,142 pages that had ink. Volumes OCR’d between 2026-06-11 and this release can have real pages with no .txt. Re-running --gemini-ocr sends only those pages, because pages with a .txt are skipped as existing; then re-run align and extract.

Models. The defaults are:

Checked against the live API and Google’s deprecation page on 2026-11-16:

gemini-2.0-flash is retired and returns 404.

OCR now samples at temperature 0.1 rather than 0.0 (decision 7). Two OCR runs of the same page will no longer return identical text. Existing .txt files are skipped as before, so only newly OCR’d pages are affected. NER stays at 0.0.

Nits

Two are fixed. The two still open are carried to 0.4:

Docs and housekeeping

All done on release-0.3. The list is kept as the record:

Found after Phase 2

A second review, and then the smoke run, turned up the following. Each is fixed on release-0.3 with tests.

commit what
e0bb208 B2’s fix labelled LoC’s synthetic manifests ImageService3, so explorer crops asked tile.loc.gov for max and got 400. The version is now read from the service URL first, and LoC services are v2. Checked live.
11e3218 The Colab review notebooks globbed the wrong OCR file pattern and defaulted to a retired model.
1eea5de Pages that came back empty were left out of the billed-page count.
c85c644 A response stopped by a safety or other filter returned no text and was reported as an empty page, with no retry. It now takes the RECITATION ladder and fails if nothing rescues it.
45b1896 Image downloads did not retry on a timeout, and a page that never arrived still ended in “Done.” Timeouts now retry twice, and missing pages are counted from disk and fail the stage.
3314eb5 main.py printed “✗ Failed” and exited 0, so scripts and the dashboard saw success.
2a5d425 On a 1924 phone book, fix_entries flagged 42 of 179 rows as duplicates: office and residence lines, and people sharing a surname. Where neither row has an address, a differing phone number now rules a pair out. No other CSV on disk changes.
cc48163 report_cost.py billed extraction’s calls to the OCR retry ladder: it reported 3.00 calls per page on a run with no retries. Extraction’s calls are now tagged ner, ner:fallback and ner:review, and retries are counted from the tags.
aeb27b5 docs/pipeline-stages.md and tools/README.md brought up to 0.3.

Found integrating the 1958 Green Book (2026-10-21, uncommitted; reported from the green-books session):

what
NER failures (api_error, error:, parse_error) were one log line each. The stage was still recorded complete and the run exited 0, so page 0078 was lost without a report. Extraction now names failed pages, prints them even under --quiet, doesn’t record the stage, and exits 1.
align_ocr’s only signal for boxes scaled to a square placeholder canvas (info.json unreachable) was a per-page warning. The run summary now lists them with the repair commands, read back from disk. On the 1958 backup it flags exactly the five pages that rescale later found.
fix_entries --infer-categories silently dropped every inferred category when the schema’s category column is named section: 1,816 rows on 1958. The fix is the green-books session’s one-line detect_schema edit; there is now a regression test.
A 402 (prepaid credit spent, 2026-11-09) has the same status as a 429, so 20 refused pages each slept through the rate-limit backoff. It now raises CreditsExhausted on the first call, and both OCR and NER stop the run and exit 1 instead of failing the rest page by page.
rescale_canvas_fragments.py and patch_canvas_fragments.py defaulted to gemini-2.0-flash (an era pin, docs/refactor-plan.md T1). They now default to the slug most common among aligned files under the directory, scanning the whole tree. That is still 2.0-flash on the Green Books root, and the current model on a new volume.

End-to-end smoke run (2026-10-17)

The volume was ia_smoke_0_3_louisburg1924: four canvases of the 1924 Louisburg–Franklin County telephone directory on Internet Archive, sliced with slice_manifest.py. It ran with --no-flex, on Surya with MPS.

step result
pipeline run Download, then OCR, extract (178 entries) and explorer. One page timed out at 60 s on every attempt; IA’s image server answers that request with a 504 after 60 s. That page exposed the download and exit-code gaps above.
pipeline ocr Surya took about 61 s per page. Align auto-detected the OCR model.
pipeline extract Re-aligned pages were re-extracted without --force: 179 entries, 9 unplaced, 3 reading-order violations.
--export-alto 3 ALTO files.
pipeline postprocess Fix, then explorer. This step exposed the duplicate false positives.
report_cost.py $0.0299 for 9 calls (3 OCR, 6 NER across two extractions) over 3 pages. No retries.

Landing sequence

Phase 0: commit what exists only on this laptop

Run on ocr-retry-hardening:

git add utils/image_utils.py pipeline/download_images.py pipeline/run_gemini_ocr.py \
        pipeline/run_surya_ocr.py tests/test_image_utils.py tests/test_run_gemini_ocr.py \
        tests/test_download_images.py docs/evidence/2026-10-16-blank-page/
git commit     # the blank-page fix and download repair
git add docs/evidence/2026-09-22-gutter-hoist/ docs/plans/gutter-hoist-fix.md CLAUDE.md
git commit     # gutter hoist recorded as deferred work
git add prompts/harvest/ner_prompt.md
git commit     # the prompt the token-burn evidence calls
git push origin claude/local-ocr-city-directories-ey5741    # 7 commits exist only here
git tag archive/htr-alto-experiments htr-alto-experiments
git push origin archive/htr-alto-experiments

Phase 1: push main’s 13 commits

Push them so CI sees them on their own: git push origin main. Use a PR instead if you want CI to run before they land.

Phase 2: build release-0.3

git switch -c release-0.3 alignment-column-criterion
git cherry-pick 4bb96df..8740c4a     # the 11
#   One conflict, in tools/report_cost.py: keep main's lines (no f-prefix) and add
#   `if exclusion_note: print(exclusion_note)` after the "Tiers:" line.
git cherry-pick <the three Phase 0 commits>

Then, in order:

  1. One commit each for B1 to B4, F1 to F5, and the opt-out flag if you take it.
  2. Merge the Jev and explorer-plan branches. Expect small conflicts in their pointer lines in AGENTS.md and CLAUDE.md.
  3. Finish with the docs pass and the version bump.

Phase 3: PR and validation

Open “Release 0.3” against main. Link it from #10, then close #10.

CI must pass in a clean checkout; that is what catches B1.

Optional, CPU-only, with no API spend: re-align one city-directory volume into a copy and run tools/audit_entry_bindings.py on it. The column-criterion evidence names this as the next measurement, and it would settle whether the opt-out should be the default for city directories.

Phase 4: release

Merge with a merge commit, not a squash: the commit messages carry the evidence, and a squash loses it.

git switch main && git pull
git tag -a v0.3.0 -m "v0.3.0"
git push origin v0.3.0
gh release create v0.3.0 --title "v0.3.0 — …" --notes-file <notes>

Then reply on #5.

Phase 5: clean up

git worktree remove .claude/worktrees/epic-cannon
git worktree remove .claude/worktrees/hopeful-clarke
git worktree remove output/green_books_and_related/the_green_book_9ea5d5b0/.claude/worktrees/recursing-chebyshev-fb174c
git branch -d release-0.3 alignment-column-criterion city_directories claude/epic-cannon \
    claude/hopeful-clarke claude/recursing-chebyshev-fb174c rosetta-preflight-and-env-docs \
    t11-stage-registry
# these landed as cherry-picks, which git cannot see as merged, hence -D:
git branch -D ocr-retry-hardening fix/loc-serial-volume-manifest alignment-running-heads \
    htr-alto-experiments
git tag archive/load-external-csv origin/claude/load-external-csv-sMJ70
git push origin archive/load-external-csv
git push origin --delete alignment-running-heads city_directories claude/hopeful-clarke \
    claude/directory-pipeline-aws-plan-ccbt3a claude/directory-pipeline-review-bynegl \
    claude/uv-hugging-face-directory-pipeline-0wm8ei claude/analyze-test-coverage-zOZ5Y \
    claude/load-external-csv-sMJ70 claude/jev-directory-pipeline-ljnhjt \
    claude/data-explorer-improvements-b546iu

git worktree remove refuses when a worktree holds uncommitted work; look inside before reaching for --force. Delete ocr-retry-hardening only after v0.3.0 exists.

Decisions (made 2026-10-17)

  1. Per-column alignment ships as the default, with no opt-out flag. On city directories it rarely completes: 4 of 19 panel pages, and 1 of 59 sampled Tulsa pages. Where it ran it cost 4 of 217 lines. The “Tulsa bad picks” caveat was a harness artifact.
  2. The structural section column is named volume_section (F1). The explorer keys on it, which leaves NER’s own section field alone.
  3. PR #5: reply before tagging, close it in favour of a tracking issue, and build PDF input as a source in 0.4, crediting the contributor.
  4. Local OCR waits for 0.4. Push its 7 unpushed commits as a backup in Phase 0.
  5. main’s 13 commits land through a PR, so CI runs first.
  6. The gold panel stays local. The pilot becomes an evidence script that reads ../city-directory-extraction when present. It contains no gold, and its README reports aggregates only, with no gold lines quoted. Why not copy panel pages:
    • The panel has never been published. city-directory-extraction is public, but data/* is gitignored.
    • Our own Surya and Gemini output for those exact pages nearly reproduces the gold: 80% of gold lines are character-identical to Surya.
    • historical-ocr-eval scores OCR engines against that text.

    The Tulsa box-vs-Surya regression fixture moves to 0.4, alongside the gutter-hoist work that needs it.

  7. OCR’s default temperature is 0.1, not 0.0; NER’s stays 0.0 (2026-10-20). Both are constants in utils/models.py, and each compare tool follows its own stage’s constant.
    • DEFAULT_OCR_TEMPERATURE covers the first OCR call and the escalation call. The retry ladder keeps [0.1, 0.3, 0.7], so its first rung is now a fresh draw at the default rather than a step up. The change is based on run experience, not a paired measurement; the measurement is listed under “After 0.3”.
    • DEFAULT_NER_TEMPERATURE stays 0.0 for three reasons:
      • Sampling flips close calls. In NER those are judgments (category, field assignment, ditto handling), so 0.1 would make the same kind of entry come out differently from page to page.
      • NER is re-run far more often than OCR, so that variation would churn rows across re-extractions.
      • It would add noise to every before/after comparison of NER output.

      An unparseable NER response already gets one retry with the fallback model. None of the 10,944 extracted pages on disk has a leftover parse-error file.

Release notes outline

Same shape as v0.2.0’s.

Data safety

Placement

Explorer

New stages and tools

Models and cost

Sources

Development

Known issues

After 0.3

Code, for 0.4:

Data, in green-books (none of these block the release):