caseywdunn/corpus: v0.2.0
Description
A hardening + iteration release. v0.2 closes out v0.1's deferred items
(vision pass at corpus scale, expanded lexicon + taxonomy support,
Bouchet batch-script fixes), adds a real update lifecycle (per-stage
resume, input fingerprints, update_corpus.py orchestrator), and lays
in a robustness + observability layer (structured stage_failures[],
silent-failure quality gates, corpus_status rollup, network circuit
breakers). Three substantive bugs surfaced during release validation
and ship in this version: a SLURM-array slicing race that corrupted
per-doc state files
(#55), an
input_fingerprint gap that silently skipped lexicon refreshes on
--resume (#56),
and a broken tesseract-data-* block in environment.yaml that
broke fresh installs
(#52). The deploy
stack also moved from single-EC2 + Let's Encrypt to a shared ALB +
ACM pattern that supports multiple organism corpuscles on one
hostname-routed load balancer. Geographic extraction
(#13) and trait
extraction (#14)
are pushed to later releases.
Added
Update lifecycle
update_corpus.pyorchestrator (#32) — one command runs the pipeline + every post-pipeline script in dependency order with--resume. Forwards the full Stage 1 flag surface so callers don't lose pipeline knobs. Makes "add papers and update everything" a one-liner.- Granular per-stage resume
(#28) — replaces
the all-or-nothing
summary.jsoncompletion marker with per-stage status tracked inpipeline_state.json. Stages whose artifact is already present and whose inputs haven't drifted are skipped on--resume. - Input fingerprints on annotation artifacts
(#29) —
lexicon_sha256andtaxonomy_snapshot_dateare stamped intochunks.json/taxa.json/anatomy.jsonso staleness is detectable without re-reading the source files. --re-annotate-staleflag (#33) — re-runs only the lexicon categories whose fingerprint changed. Subsumed by per-stage resume + per-category fingerprints.- Idempotency contracts on post-pipeline scripts
(#30) —
build_biblio_authority,build_taxon_mentions,backfill_intext_citations, andreconcile_corpus_to_biblioaudited + tested for re-run safety. --audit-orphans(#31) — read-only listing ofdocuments/<HASH>/directories (and LanceDB rows) whose source PDF is no longer in the input set. Deletion stays manual.
Robustness + observability
- Structured
stage_failures[]+ per-stage timing (#34) — reason codes (timeout,crash,external_unavailable,unsupported_format,corrupted,quality_gate) replace v0.1's free-texterrors[]. Every downstream tool reads from the new schema. - Silent-failure quality gates (#36) — flag empty text layers, gibberish OCR output, all-black figures, zero-reference papers, and collapsed-extraction chunks. Surfaces what v0.1 was happily writing without complaint.
corpus_status(#40) — single command rolls up stage completion, failure breakdown by reason, quality flags, and staleness across the whole build. Dashboard for everything else in this section and the update lifecycle.- Huge-document hard cap
(#35) —
page-count gate with a structured
too_largeflag for monographs that would blow past reasonable wallclock. Haeckel 1888 Challenger Siphonophorae is the canary. - External-service flakiness layer
(#37) — shared
retry + backoff + circuit breaker + cache for Grobid, BHL,
CrossRef, OpenAlex via
pipeline/external.py.STRICT_NETWORKenv var fails-fast for release builds. - Standardized
--dry-run(#41) — across all pipeline + post-pipeline CLIs, replacing the prior 4-of-10 inconsistent state.
Vision + figures
- SLURM array support for the vision pass
(#27) —
batch_pass3b.shnow parallelizes the same waybatch_pipeline.shdoes. Prerequisite for running Pass 3b (Qwen2.5-VL-7B) at corpus scale (#11). - Archaic plate prefixes + Roman-numeral support in figure
extraction (#16)
— recovers figure numbers from 19th-c. and early-20th-c. caption
conventions (
Tab. III.,Pl. XII.) the v0.1 heuristics didn't match.
Indices + features
- BibTeX round-trip curation
(#26) —
bib_exportserializesbiblio_authority.sqliteto BibTeX;bib_importbrings hand edits back into the authority database. Closes the loop on user curation of corpus bibliography. - Multi-category lexicons
(#24) —
--lexicon CATEGORY:PATHaccepts any number of YAML files (anatomy, biogeography, …); top-level keys define categories. Annotations carry acategoryfield so per-category resume works. - Plant-source taxonomy support
(#23) —
ingest_taxonomy.pyaccepts non-WoRMS Darwin Core archives, includingtaxa.tsvTaxon-core layouts (#22). - Expanded default Tesseract language pack coverage (#46) — the OCR fallback union covers more 19th-c. European scripts.
MCP server
- Corpuscle-aware server name
(#17) — the
deployed MCP server identifies itself as
corpus:<corpuscle>rather than the barecorpus, with__version__frompipeline/version.pysurfaced viabundle_info. - Inline figure bytes from
get_figure_image— returns PNG content directly so MCP clients don't need filesystem access to the bundle. - Two-layer client-side instructions. The
InitializeResult.instructionsblob now joins a packaged default (mcpsrv/default_instructions.md) with an optional per-corpuscle override prepended on top. Default guidance (defer to corpus taxonomy + bibliography, preserve historical terminology) ships with the server and reaches every client with no operator action; corpus-specific nudges land first via<corpuscle>/instructions.mdwhen present.templates/instructions.mdis the starting scaffold for the corpuscle layer. /healthzliveness probe on the SSE transport. Returns200 okwithout requiring the bearer token — mounted ahead of the auth middleware inmcpsrv.transport._HealthzASGIso uptime monitors and reverse-proxy readiness checks don't need the shared secret. Exposed throughdeploy/nginx.confaslocation = /healthz.
Internal
pipeline/package (#42, #44, #45) — the ~1700-lineprocess_corpus.pyis split into focused submodules (pipeline.annotate,pipeline.chunking,pipeline.metadata,pipeline.figure_passes,pipeline.scan,pipeline.extract,pipeline.runner,pipeline.main).process_corpus.pyis now a thin CLI shim. No behavior change.mcpsrv/package (#15) — the ~2050-linemcp_server.pyis split per concern (papers / taxonomy / bibliography / figures / transports). No behavior change.bib/package (#43) — bundlesbib_metadata,bib_export, andbib_importinto a single namespace.- Single-source
__version__inpipeline/version.py, stamped into bundle manifests + MCPbundle_info.main/dev/vNbranching model adopted;devcarries a PEP 440 pre-release suffix (0.2.0.dev0→0.2.0). schema_versionfield on persistent artifacts so future schema changes can be detected without parsing.pngquantadded to the build environment (#25) so bundled PNGs ship pre-compressed.
Changed
- Repo layout cleanup. Library modules
figures.py,taxa.py,grobid_client.py,embeddings.py,vision.py,external.py, andversion.pymoved from the repo root into thepipeline/package — they were never run directly, only imported. Import sites:from figures import …→from pipeline.figures import …(and likewise for the other six). One-off utilities (dedup_ghost_works.py,unify_doi_corpus_key.py) moved totools/.PLAN.mdmoved todev_docs/. The repo root now holds only user-facing CLI entry points. - Anatomy-only naming scrubbed throughout. The lexicon system
is no longer hard-coded to anatomy; field and file names use
lexicon/categoryinstead. Documentation refreshed in lock step. CLAUDE.md→AGENTS.md— generic agent-guidance filename for compatibility with non-Claude assistants.- MCP hot paths trimmed for token cost —
list_papersrow shape reduced; previously unbounded MCP list returns are now bounded. - Per-PDF subprocess gated by platform (#18) — the docling subprocess wrapper, originally added to contain a Linux segfault, no longer runs on macOS where it was pure overhead.
- Deploy architecture: ALB + ACM, multi-organism support. Was
single-EC2 + nginx + Let's Encrypt; now each EC2 sits behind a
shared Application Load Balancer (
siphonophores-mcp-alb) that terminates TLS with an ACM wildcard cert. nginx on the instance drops to plain:80(no certbot, no TLS). Adds a default/healthendpoint nginx serves directly for ALB target-group health checks (separate from the/healthzMCP probe under bearer auth). One listener rule per organism (host-header match → target group), so addingcnidaria.siphonophores.orgetc. is a target-group + listener-rule + DNS CNAME, no new TLS infra. CloudFormationBucketNameparameter now optional via a newCreateBucketflag so re-deploys can attach to an existing bundle bucket. Full runbook rewritten: dev_docs/DEPLOY.md. INSTALL.mdpromoted to repo root. Moved fromdev_docs/since the content (jbig2enc, OCR language packs, Grobid, pip fallback) is user-facing and belongs alongside README, CONTRIBUTING, and CHANGELOG.dev_docs/keeps its maintainer-only docs (PLAN, DEPLOY, BOUCHET, MCP_TOOLS, TESTING, OVERVIEW). All cross-references updated.
Fixed
- Bouchet batch scripts (#20, #21) — native-library load problems, CUDA / torch wheel selection, and a fail-loud preflight so configuration drift surfaces before the array launches instead of after each task fails individually.
deploy/stack.yaml(#6) — removed stale default-VPC assumptions that broke deploys on accounts without a default VPC.- Docling extraction fails loudly instead of writing placeholder text when the parser produces nothing usable.
- Missing PyMuPDF surfaces as a stage failure instead of a silent skip.
--skip-pipelinerejected with--re-annotate-stale— previously these silently combined into a no-op.rapidfuzzrequired at import inunify_doi_corpus_keyanddedup_ghost_works— failure surfaces at startup, not partway through a run.ingest_to_vector_dbimport wired intopipeline.main— was silently dropped during the package extraction.package_for_servediscovers lexicon outputs dynamically — no more hardcoded list that drifted from the multi-category lexicon work; also bundlesinstructions.mdand warns on missing top-level files.- Three issues filed during release validation (#47, #48, #49) — path handling, cross-paper leakage in a query path, and an incorrect rank field. Closed before release.
- Stage 1 SLURM array tasks could process the same PDF
concurrently and corrupt per-doc state files
(#55). The
pre-resume filter at the top of
pipeline.main.main()ran before batch slicing, so each array task's slice depended on disk state at task-start time. Tasks starting later saw fewer remaining hashes; their slice indices then landed on different members of the list, producing overlapping batches. The two writers raced on a sharedpipeline_state.json.tmpfilename, leaving either an interleaved-bytes payload (31 corrupted summaries in the production run that surfaced this) or aFileNotFoundErroron the rename. Fixed by slicing on the unfiltered hash list (_slice_hashes_for_batchinpipeline.main); resume skipping is now done per-doc inside the loop. Belt-and-braces:_save_pipeline_stateandcreate_summary_jsonnow use per-writer tmp filenames (.tmp.<pid>.<ns>) so any future regression that re-introduces concurrent writers on the same hash gets last-write-wins atomicity instead of corruption. Regression tests intests/test_batch_slicing.py. --resumeouter fast-path ignoredinput_fingerprint, so editing a lexicon or taxonomy never invalidated already-recorded stages (#56). The per-doc fast-path skip inpipeline.maincalled_all_stage_artifacts_completewithout forwarding the live taxonomy/lexicon fingerprints, so a doc whosetaxa_and_lexicon_extractionstage was recorded under (e.g.) a taxonomy-only fingerprint was silently skipped on a re-run that loaded a real lexicon — even though the inner per-stage gate would have correctly flagged it stale, that gate was unreachable. Effective result: the only way to force a lexicon refresh was bumpingPIPELINE_VERSION. Production occurrence: 12,669 docs in job11108546carried a fingerprint withoutlexiconsbecause the source YAML had loaded as{}; the resume run silently passed over all of them. Fixed by addingexpected_fingerprintsto_all_stage_artifacts_completeand a shared_expected_fingerprints_for_runhelper that bothmain.py's outer gate andrunner.py's inner gate now use, keeping the two staleness notions in lockstep. Regression tests intest_per_stage_resume.py.environment.yamlreferences totesseract-data-<code>packages (#52, closes #9) — the 12 per-language entries added in #46 listed package names that don't exist on conda-forge, so a freshconda env createfailed withPackagesNotFoundError. Existing dev envs survived because incremental updates silently skipped the missing packages. Replaced with a newtools/install_tessdata.shhelper that downloads the default fallback set (deu, fra, rus, lat, spa, por, chi_sim, chi_tra, jpn, ell, kor, grc, deu_latf) directly fromtessdata_best. Idempotent; takes a custom language list as positional args; honorsTESSDATA_DIRfor non-conda installs. Subsumes the v0.1 deu_latf-on-Bouchet manual install (#9) —deu_latfis now part of the default download.
Removed
bib_metadata.pyshim — the deprecated re-export shim is removed. Migrate any leftoverfrom bib_metadata import …imports tofrom bib import …(orfrom bib.parser import …for private helpers).
Deferred / known limitations
- Streamable HTTP transport with OAuth (#5) — deferred indefinitely. SSE + bearer-token works for the ~20-collaborator deploy target; revisit only if wider distribution materializes or MCP clients drop SSE support.
- Geographic mention layer (#13) — pushed to v2.0+; the mention-layer surface is likely to be reworked at the major-version boundary.
- Trait extraction + identification keys (#14) — v0.3 candidate. Substantial enough to warrant its own plan section when picked up.
- Embedding model migration path (#38) — design-only for v0.2; implement when a model swap is actually needed (BGE-M3 v2 or a different family).
- MCP server lazy index loading (#39) — premature at 1.8K papers; documented as a known scaling cliff for 10K+ corpuses.
Files
caseywdunn/corpus-v0.2.0.zip
Additional details
Related works
- Is supplement to
- Software: https://github.com/caseywdunn/corpus/tree/v0.2.0 (URL)
Software
- Repository URL
- https://github.com/caseywdunn/corpus