Corpus integrity¶
Activation gate¶
Same gate as notebook-corpus.md — satisfied. Notebook-local and corpus-wide doctor checks below are required; the acceptance suite is the executable bar for supported bulk-import UI/CLI.
Doctor scopes¶
Scope |
Responsibility |
|---|---|
Notebook doctor |
Extend today’s per-project |
Corpus doctor |
Workspace-wide: corpus index, ImportRuns, cross-notebook ID uniqueness, locator containment |
Both may run offline. Deep mode rehashes managed source and render bytes.
Notebook invariants¶
In addition to existing validate_project / page-result checks, enforce:
Unique
page_id,source_id,render_idwithin the notebookUnique
(source_id, page_index)among pagesFor each source: pages’
page_indexset equals{0..page_count-1}and|pages| == page_countEvery
page.active_render_idresolves; active render belongs to the page’s source;render.source_sha256 == SourceAsset.sha256PDF coherence: when
media_typeis PDF, renderpdf_page_index(when present) equalspage.page_indexpage.width/heightequal active render dimensionsManaged source/render files exist (and match hashes in deep mode)
No orphan page-result files without a page (warning or error per existing practice); no unreferenced authoritative source/render records (source-asset.md)
Approved date metadata satisfies existing date invariants
Well-formed ingest journal or quarantined corrupt journal — never silent delete (import-run.md)
Corpus invariants¶
Every corpus index
notebook_idloads aproject.jsonwhoseid == notebook_idEvery index
managed_relpathis unique, contained underTRANSCRIBE_PROJECTS_DIR, and resolvesnotebook_iduniqueness across the corpus indexGlobal uniqueness of
page_id,source_id, andrender_idacross all registered notebooks (IDs are corpus-wide capable; collisions are errors even if folders differ)Index entry order is well-formed (list); no duplicate entries
ImportRun files that claim committed IDs: those IDs resolve in the cited notebook, or the item is explicitly
skipped/failedwith recorded reasonAt most one live
.ingest-journal.jsoninterpretation per notebook; corrupt journals quarantined and reportedCorpus lock / notebook lock order is an implementation duty; doctor does not prove lock order but may flag concurrent-journal anomalies
Repair and rebuild boundaries¶
May rebuild / delete-and-recreate |
Must never guess-rebuild |
|---|---|
Archive SQLite / FTS |
|
Thumbnails / |
Human-approved metadata |
Disposable Library summary projections |
Provenance, OCR attempt history, edits |
Optional ImportRun registry index file (from run files) |
Managed source bytes |
ImportRun immutable plan bodies and committed item outcomes |
|
Corpus index entries (may re-register a known |
Supported recovery paths must leave doctor green (or only documented warnings) when completed successfully.
Migration enforcement¶
Before writers emit optional SourceAsset linkage fields or ImportRun IDs into transcribe.project:
Follow additive optional v1 rules in source-asset.md
Doctors must accept legacy sources without
import_run_id/original_path/source_size_bytesAfter writers ship, doctors may warn on committed ImportRun items whose sources lack
import_run_idonly when policy requires linkage for that generation—default: warn, do not invalidate legacy notebooks
Acceptance gate (executable)¶
Bulk-import implementation is supported (UI and CLI bulk paths) when the synthetic multi-notebook corpus suite passes all of the following — and that suite is green:
Deterministic crash-injection at each boundary in import-run.md (corpus registration, notebook creation, source promotion, render promotion,
project.jsoncommit, ImportRun item commit, final run-state commit), with resume producing the authoritative winner and no duplicate committed IDsRetry / idempotency under exact
plan_id+plan_fingerprint+import_policy_idequality: second commit is a no-op for committed items; failed items may progress without regenerating IDsDuplicate policy:
skip_existingskips only same SHA in the target notebook; same bytes in another notebook are not silently skipped without explicit corpus-wide dedupe in the plan;create_duplicatealways allocates the preallocated distinct IDsCorpus-index corruption / rebuild: corrupt index quarantined/reported; recovery re-registers from authoritative
project.jsonIDs without inventing newnotebook_ids; locator uniqueness restoredDeep doctor green (or documented warnings only) after every supported recovery path on the synthetic corpus. Retained quarantine artifacts after a successful index rebuild are warnings (
corpus_quarantine_present), not errors — operators may delete them after review.Fixture coverage includes: many notebooks × many pages, duplicate bytes, renamed external files, interrupted imports, missing managed sources, reordered pages, failed OCR, re-import, legacy schema v1 notebooks, Unicode/weird filenames, PDF split provenance, ordering ambiguity refused at validate, malformed journal quarantine. Cancel paths must distinguish
cancelledvscancelled_with_commitswithout rolling back committed items.
Acceptance bar: no page identity loss; no silent overwrite of approved human metadata; deterministic resume; doctor green (warnings-only allowed for documented quarantine retention) after every supported recovery path.
Non-goals¶
Automatic healing that invents missing IDs or approved metadata
Treating archive SQLite as an authority to repair notebooks from
Shipping bulk import behind a feature flag without this suite green (gate is closed; suite must remain green)