Skip to content

Stop caching file: text; validate DOI quotes against local full text and sign excerpts - #176

Merged
caufieldjh merged 6 commits into
mainfrom
caufieldjh/local-full-text-signing
Nov 17, 2026
Merged

caufieldjh merged 6 commits into
mainfrom
caufieldjh/local-full-text-signing

Conversation

@caufieldjh

Copy link
Copy Markdown
Contributor

Closes #173. Closes #174.

#173: file: text is no longer cached

  • file: references (text, SVG, drawio) are not written to cache_dir or any cache. Validation never read these entries back (Always read file: references from the file, under one canonical id #148), and the file is often a paper the project may not redistribute.
  • New cache_local_files: true restores the old write for your own notes.
  • file: IDs are named relative to reference_base_dir (or the working directory if unset), so file:/home/me/repo/papers/a.md becomes file:papers/a.md and cache entries carry no home directory. Files outside it keep their absolute path.
  • cache reference file:... says the file was read but not cached.
  • Docs tell users to look for leftover content_type: local_file entries written by ≤0.6.0.

#174: local full text and excerpts sign

  • Mapping. local_full_text: {DOI:...: papers/x.md} or local_full_text_dir (files named by cache stem, .md/.txt, ~ expanded). If the file exists, quotes for that ID are matched against it, ahead of any fetched text. Metadata is fetched and cached as usual. The file's text is never cached or kept in the memory cache. If the file is absent (CI), behaviour is unchanged.
  • excerpts sign DATA_FILES... [--reference ID] [--check]. Validates each quote against the local file, applying the normal matcher and fair-use caps. Passing quotes go to signed_excerpts_dir/<stem>.yaml:
    • Each quote is stored as written in the data, with verification: {method, source_sha256, validator_version, verified_at}. The bundle also gets source_char_count, so CI can apply max_reference_fraction.
    • Re-signing is deterministic. Existing excerpts and their fields (target_repo) are kept, and an excerpt already verified against the same hash is left alone.
    • An existing bundle is never used as evidence when signing.
    • Exit codes: 1 if a quote fails to verify, a requested reference has no local text, or --check finds drift; 2 for usage errors.
  • signed_excerpts_require_verification (default off) makes validation ignore excerpts with no verification.source_sha256.
  • The docs say this is an attestation, not a cryptographic signature: it does not stop someone who can edit the bundle, including an agent writing bundles directly. Real signatures would be a follow-up.

Also

  • _version.py called version(__name__), so __version__ was always 0.0.0. It now reports the package version, which bundles record.
  • Schema-free evidence extraction moved from cli/repair.py to validation/evidence_items.py (still re-exported from cli/repair.py).

Tests

  • New: tests/test_file_reference_not_cached.py, tests/test_local_full_text.py, tests/test_excerpts_sign.py (written first).
  • Existing tests that assumed file: is always cached now set cache_local_files=True or expect relative IDs.
  • Ran each test file separately, plus doctests, mypy and ruff. Remaining failures are in test_pmid_network, test_wikipedia_source and test_bookshelf_provider, where local test servers time out in my sandbox. They fail identically on a clean main checkout.

🤖 Generated with Claude Code

…and sign excerpts

#173: file: references are no longer written to any cache unless
cache_local_files is set, and file: IDs are named relative to
reference_base_dir (or CWD) so entries carry no home directory.

#174: local_full_text / local_full_text_dir map a cited reference ID to a
local file whose text is matched but never cached. New `excerpts sign`
writes snippet-only bundles with a verification record (source SHA-256,
validator version, date) and source_char_count. Optional
signed_excerpts_require_verification makes validation ignore unrecorded
excerpts.

Also fixes __version__ always reporting 0.0.0, and moves schema-free
evidence extraction to validation/evidence_items.py for reuse.

Closes #173
Closes #174

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 1m 44s —— View job


PR review: stop caching file: text; local full text and excerpts sign

  • Read the diff and the surrounding code (signed_excerpts, SupportingTextValidator, the fetcher save paths)
  • Review source changes
  • Review tests
  • Post feedback

The PR is in good shape and I found nothing that should block merging. The privacy model holds up: the local text is laid over the fetch result on each call and never goes into _remember/_save_*, and cache reference passes use_local_full_text=False. The signer turns off signed_excerpts_dir, so an existing bundle can't vouch for a quote, and the docs say clearly that this is an attestation, not a cryptographic signature. The tests were written first and cover the main invariants. The points below are ordered by importance.


Potential bugs

1. local_full_text_dir resolves relative paths differently from local_full_text. In etl/reference_fetcher.py (local_full_text_path), entries in local_full_text go through FileSource.resolve_path, so a relative path is taken from reference_base_dir. local_full_text_dir uses Path(directory).expanduser() as is, so a relative path is taken from the working directory. The field description says "same rules otherwise", which suggests both use reference_base_dir. Anyone who sets reference_base_dir and a relative local_full_text_dir: papers/ will find nothing when they run from another directory. Because a missing file is ignored on purpose, nothing reports the miss.
Fix this →

2. _bundle_path doesn't check the bundle's reference_id and ignores the disambiguated name. In excerpt_signing.py, _bundle_path only tries cache_filename(...) and returns any file with that name. The validator's _load_signed_excerpts also tries the disambiguated_cache_filename stem and rejects a bundle whose reference_id names a different reference. When two IDs map to the same stem (the case that disambiguated_cache_filename exists for), excerpts sign would merge verified quotes into the other reference's bundle. The validator would then skip that bundle, so the signed quotes never take effect. It's rare, but it fails silently. Suggested fix: use the same candidate list, skip any bundle whose reference_id doesn't match, and fall back to the disambiguated name.

Design and robustness

3. Old excerpts are never removed, so the bundle can drift past the fair-use caps. _merge keeps every existing excerpt, which is the intended behaviour. But max_total_chars_per_reference and max_reference_fraction only count the quotes cited in this run. Over several edits to the data files, a bundle can collect more of a closed paper than either cap allows, and that bundle is the file that gets committed. Also, when the source hash changes, entries no longer cited keep their old source_sha256. Two possible fixes:

  • Have --check warn about, or have a --prune flag remove, excerpts no longer cited by any data file.
  • Check the cumulative cap over the merged bundle rather than over this run's quotes.

4. Relative file: IDs depend on the working directory when reference_base_dir is unset. FileSource.reference_id_for names files relative to the working directory, so the same data gives different IDs depending on where you run it. Files reached through ../ keep their absolute path, so the home directory can still end up in an opt-in cache entry. Suggestion: have the docs recommend setting reference_base_dir whenever cache_local_files is on.

5. Minor: the local file is read more than once per reference. Each validator.validate(text, ref) call goes through fetch and then _with_local_full_text, which reads and parses the file again. _source_text_stats then reads it once more to hash it. That re-reading is intended, so edits are picked up. The cost per paper is small, but if the file is edited during a run, the recorded source_sha256 may not match the text the quotes were checked against. Hashing the bytes that were actually parsed would close that gap.

Code quality

  • Moving _extract_evidence_items into validation/evidence_items.py and re-exporting it from cli/repair.py is clean. The docstring still says "Extract evidence items from data for repair". Now that excerpts sign uses it too, it could be reworded.
  • sign_excerpts raises ValueError when there is no destination, and the CLI checks the same thing first. That's fine, since the library function is public.
  • The _version.py fix is correct. __version_tuple__ handles dev and local suffixes such as 0.6.1.dev3+gabc.

Security

  • No new network paths or writes beyond signed_excerpts_dir. yaml.load in the signer uses round-trip mode (not unsafe). The validator still uses typ="safe".
  • signed_excerpts_require_verification only checks that a source_sha256 is present, as the docs say. It's worth repeating in the release notes that this guards against hand-typed entries by mistake, not against tampering.

Test coverage

Coverage is strong: idempotent re-signing, merge keeping fields, dry run, fair-use caps, strict mode, CLI exit codes, no leak into the memory cache, ~ expansion. Missing cases:

  • A relative local_full_text_dir with reference_base_dir set (point 1).
  • A bundle whose name collides with another reference's (point 2).
  • cache reference DOI:... with a local mapping, checking that it reports the cached or fetched text and not the local file.

Not done

uv isn't installed in this Actions runner, so I couldn't run the tests, mypy or ruff. This review comes from reading the code. If you want me to run checks in future, uv needs to be on the PATH and allowed under --allowedTools.

…esolution

- local_full_text_dir resolves a relative directory against
  reference_base_dir, like local_full_text values.
- excerpts sign uses the same bundle names as validation (usual, then
  disambiguated stem) and never merges into a bundle recording another
  reference_id.
- A bundle whose merged quotes exceed max_total_chars_per_reference or
  max_reference_fraction is not written; nor is one whose source changed
  while its quotes were checked.
- New --prune removes excerpts this command signed earlier that are no
  longer cited; excerpts from elsewhere are kept.
- Docs recommend reference_base_dir with cache_local_files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 1m 10s —— View job


PR review (after 0f3b042)

  • Read the new commit and the full diff
  • Check which earlier review points it addresses
  • Review for new problems
  • Post feedback

The new commit deals with every point from the last review. Below is what changed, then a few new problems the changes introduce. I found nothing that should block merging. Point 1 is the one I'd fix first.

Earlier points

# Point Status
1 Relative local_full_text_dir ✅ Now resolved with FileSource.resolve_path, with a test
2 _bundle_path naming collisions ✅ Tries the same file names as validation, skips a bundle whose reference_id is different, has a doctest and a test (see point 3 below for one leftover gap)
3 Bundle growing past the caps ✅ Caps are checked on the whole merged bundle, and --prune was added
4 Relative file: IDs ✅ Docs now recommend reference_base_dir
5 Hash vs. text checked ✅ The hash is compared before and after checking, and the bundle isn't written if it changed
– Docstring, cache reference test ✅

New problems

1. --prune can delete signed quotes when it shouldn't (excerpt_signing.py:372, _merge).

  • A wrong local file wipes the bundle. If every quote fails (for example, the mapping points at the preprint instead of the published paper), verified is empty. --prune then goes ahead and removes every excerpt this command signed earlier. The bundle is still written, even though the command exits 1. Failures don't stop the write, so one wrong file deletes good excerpts.
    • Suggestion: skip pruning for any reference that had a failed quote in this run, or don't write the bundle at all when there are failures.
  • Running on some of the data files. excerpts sign one_file.yaml --prune removes quotes for the same reference that are cited in data files you didn't pass. The docs should say to pass every data file with --prune.
  • References no longer cited are never pruned. The loop only covers references found in collect_quotes. If a reference is dropped from the data entirely, its bundle keeps every excerpt. The docs say --prune removes excerpts "the data no longer cites", which isn't true for this case.
    • Either document that, or with --prune also go through the bundles in directory whose reference has local text but no quotes this run. (Pruning without local text could also work, since it needs no verification.)

Fix this →

2. The cap is only checked when the bundle changes (excerpt_signing.py:385). _bundle_cap_problem runs only after _merge returns True. An over-cap bundle that doesn't change is reported as "unchanged" and exits 0, including under --check. That happens if the bundle was edited by hand or by an agent, or if the caps were lowered later. Since --check is what CI runs, it would be worth checking the cap on every bundle it visits. Also, the over-cap message could suggest --prune, because without it the user can't get back under the cap except by editing the file.

3. The signer and the validator compare reference_id differently (excerpt_signing.py:149). The validator normalizes the stored ID first: _same_reference_id(self.fetcher.normalize_reference_id(str(stored_id)), normalized_id) in supporting_text_validator.py:639. _bundle_path compares the raw stored string. Suppose a hand-written bundle records reference_id: pmid:1, PMID: 1 or a https://doi.org/... form. The signer treats it as another reference's bundle and writes a new one under the disambiguated name. The validator still matches the usual name first, so the newly signed quotes are never read. To fix this, normalize stored with the fetcher, as the validator does (pass the fetcher, or a normalize callable, into _bundle_path).

4. Unlikely edge case in _bundle_path. When the usual name is taken, the fallback returns stems[1] even if that file exists and records a third reference ID. That would need a hash prefix collision, so it's very unlikely. Returning a distinct name, or raising, would make it fail loudly rather than merge into the wrong bundle.

Minor

  • The CLI summary now says N problem(s). Failures with no quote text print on one line, which is fine.
  • _source_text_stats reads the file twice per reference. The cost is negligible.

Test coverage

The new tests cover the collision, both cumulative caps, pruning, a file edited mid-run, the relative directory and cache reference. Tests worth adding:

  • --prune when every quote for a reference fails, so a wrong local file doesn't wipe the bundle (point 1).
  • --check on an over-cap bundle that hasn't changed (point 2).
  • A bundle whose reference_id is written in a non-normalized form (point 3).

Not run

The project's dependencies (uv, pydantic) aren't installed in this runner, so I couldn't run the tests, mypy or ruff. This review comes from reading the code.

…rmalization

- --prune skips a reference with any failed quote, so a wrongly mapped
  file cannot delete good excerpts; it also prunes signed excerpts from
  bundles for references the data no longer cites.
- Fair-use caps are checked on every bundle visited, so --check reports
  an unchanged bundle that is over them; the message suggests --prune.
- Bundle lookup normalizes the stored reference_id as validation does.
- When other references hold both bundle names, report a failure instead
  of merging into the wrong bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 1m 6s —— View job


PR review (after 8db4bf9)

  • Read the new commit
  • Check which earlier review points it addresses
  • Review for new problems
  • Post feedback

The new commit fixes all four points from the last review, and each fix has a test. I found one small new bug in the new --prune pass over bundles the data no longer cites. Nothing blocks merging.

Earlier points

# Point Status
1 --prune deleting good excerpts ✅ A reference with any failed quote is not pruned (prune_here), and that is tested. The docs now say to pass every data file. References the data no longer cites are now pruned, except when --reference is given.
2 Cap only checked when a bundle changes ✅ _update_bundle checks the caps before the unchanged early return, and the message points to --prune
3 reference_id not normalized ✅ _bundle_path takes a normalize callable, and the signer passes fetcher.normalize_reference_id
4 Both bundle names taken ✅ Returns None, which is reported as a failure

New problems

1. The pass over uncited bundles can write the wrong file (excerpt_signing.py:409-421).
The loop globs every *.yaml/*.yml in the directory and reads its reference_id. It then calls _update_bundle(normalized_id, …), which looks the bundle up again with _bundle_path. That second lookup only tries the cache-stem names, so it can return a different file from the one the loop is visiting:

  • A bundle with a non-standard name, e.g. a hand-named smith2020.yaml containing reference_id: PMID:5. _bundle_path returns PMID_5.yaml, which doesn't exist. _update_bundle starts a fresh CommentedMap, and _merge sets excerpts = [] and returns changed=True. The result is a new empty PMID_5.yaml, and smith2020.yaml is never pruned. With --check --prune the first run reports it as out of date.
  • Both X.yaml and X.yml for one reference. Both resolve to X.yaml, so that file is processed twice and the .yml file is never pruned.

Validation ignores files with non-standard names, so this doesn't break validation. It does write junk files and leave the excerpts it meant to remove. The simplest fix is to skip a file unless _bundle_path(directory, normalized, normalize) == path. Another option is to pass path into _update_bundle directly.

Fix this →

2. A small gap in the "every bundle visited" cap check (excerpt_signing.py:394). if not verified and not prune_here: continue runs before _update_bundle. If every quote for a reference fails and --prune isn't given, that reference's bundle is not cap-checked. This barely matters, since those failures already make the command exit 1. The docs ("checked for every bundle visited") are still accurate if "visited" is read narrowly.

3. Uncited bundles that are still over the cap fail every --prune run. An uncited bundle can hold entries from a private store that --prune keeps. If those alone exceed max_total_chars_per_reference, the uncited pass reports a cap failure on every --prune run, and the user can't fix it with the signer. That is arguably correct behaviour, but a sentence in the docs would save someone some confusion.

Code quality

  • _update_bundle takes 12 parameters, and both call sites pass them all positionally (report, yaml, directory, normalized, …, [], None, None, None, True, dry_run). The second call is hard to check by eye. Passing them by keyword, at least from verified onward, would help.
  • In the uncited pass, verification or {"source_sha256": ""} is never read because verified is empty. It's harmless, but _merge could accept Optional[dict] instead.

Performance and security

No concerns. The new pass reads each bundle once with YAML(typ="safe") and does no network calls. normalize_reference_id only rewrites strings (and resolves paths for file: IDs).

Test coverage

The six new tests match the commit's changes. Worth adding:

  • --prune with a bundle whose file name is non-standard and whose reference the data no longer cites (point 1).
  • A .yaml/.yml pair for one reference under --prune.

Not run

uv and the project's dependencies (pydantic, ruamel.yaml) aren't installed in this runner, so I couldn't run the tests, mypy or ruff. This review comes from reading the code.

…ndle

The uncited-bundle prune pass now skips a file unless it is the one
_bundle_path resolves for its reference, so a hand-named bundle or the
.yml twin of a .yaml is not mistaken for another file and no empty
bundle is written. Docs note that excerpts from elsewhere over a cap are
reported on every --prune run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 42s —— View job


PR review (after a9d164d)

  • Read the new commit and the code around it
  • Check which earlier review points it addresses
  • Review for new problems
  • Post feedback

The new commit fixes the last review's main bug and both of its code-quality notes. I found nothing that should block merging. What's left are a few small robustness points.

Earlier points

# Point Status
1 The pass over uncited bundles could write the wrong file ✅ Fixed. A file is now skipped unless _bundle_path(directory, normalized, normalize) == path (excerpt_signing.py:426). The new test covers a hand-named smith2020.yaml (no empty PMID_5.yaml is written) and a .yaml/.yml pair (processed once).
2 Cap check skipped when a reference's quotes all failed ✅ The docs now say "every bundle the command would write to", which matches the code
3 Uncited bundles still over the cap fail every --prune run ✅ Documented, with "trim it by hand"
– 12 positional arguments to _update_bundle ✅ Arguments after validator are keyword-only (*)
– Placeholder {"source_sha256": ""} ✅ _merge accepts Optional[dict] and returns early when it is None. Pruning runs before that return, so it still happens.

I followed the uncited pass through _merge with verification=None, prune=True and verified=[]. It removes every entry signed with local_full_text, keeps entries from elsewhere, and doesn't add anything. That is correct.

Remaining minor points (none blocking)

1. One bad YAML file in signed_excerpts_dir stops the whole --prune run. The uncited pass calls _stored_reference_id on every *.yaml/*.yml file (excerpt_signing.py:416). That uses YAML(typ="safe").load, which raises on malformed YAML. One broken or unrelated file in the directory therefore crashes excerpts sign --prune with a traceback. _bundle_path has the same problem for the two candidate names, but globbing the whole directory makes it far more likely. Reading files the user controls is a case CLAUDE.md allows a try/except for. Catching YAMLError there and recording a SignFailure (or a warning) naming the file would fail more gracefully.

2. A fully pruned bundle is left as an empty file. When every excerpt in an uncited bundle was signed by this command, --prune writes excerpts: [] and keeps the file. That's harmless, since validation just finds no excerpts. Deleting the file might be what users expect, or the docs could say the file is kept. Related: an uncited bundle with no excerpts key gets excerpts: [] added and is reported as written, so --check --prune flags it as out of date once.

3. Test gap: a mixed uncited bundle under --prune. The tests cover pruning signed entries and keeping hand-written ones separately. A test with one uncited bundle holding both kinds would pin down the verification is None early-return path in _merge.

Code quality, performance, security

  • The comments and the _merge docstring ("verification may be None only when verified is empty") are clear. An assert verification is not None or not verified would enforce that contract cheaply.
  • Performance: the uncited pass reads each bundle up to three times (_stored_reference_id, _bundle_path, then the round-trip load in _update_bundle). That's negligible for bundle-sized files.
  • Security: no new concerns. All loads use safe or round-trip mode, there are no network calls, and writes stay inside signed_excerpts_dir.

Overall

In my view the PR is ready to merge. The privacy guarantees hold: file: text and local full text are never cached. The attestation model is documented honestly, and the bundle merge/prune/cap behaviour now holds up in the edge cases raised across the three earlier reviews.

Not run

uv isn't installed in this runner, so I couldn't run pytest, mypy or ruff. This review comes from reading the code.

… lists

A bundle that is not valid YAML is reported as a sign failure naming the
file, rather than stopping the run with a traceback. A bundle with no
excerpts list is left untouched when there is nothing to add or prune,
so --check --prune does not flag it. Adds a test for pruning a bundle
that mixes signed and external entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 1m 0s —— View job


PR review (after 3830897)

  • Read the new commit and the code around it
  • Check which earlier review points it addresses
  • Review for new problems
  • Post feedback

The commit deals with the three remaining points from the last review, and each one has a test. I found nothing that should block merging. What's left is a few small hardening gaps of the same kind the commit fixes.

Earlier points

# Point Status
1 A malformed YAML file stops the --prune run ✅ The uncited pass catches YAMLError and records a SignFailure that names the file. _update_bundle catches it around _bundle_path and the round-trip load. Tested with broken.yaml.
2 Empty excerpts: [] added to a bundle that had no list ✅ _merge returns early when there is no list and nothing was verified, so --check --prune no longer flags the file. Tested, and the test checks the file bytes are unchanged.
3 No test for a mixed uncited bundle ✅ test_prune_of_a_mixed_uncited_bundle_keeps_entries_from_elsewhere

I traced the early return in _merge. It comes after the title and source_char_count updates, so those still apply to a bundle with no list. The only caller that reaches it with verified=[] is the uncited pass, which passes None for both, so nothing changes. That is correct.

Small remaining gaps (none blocking)

1. Valid YAML that isn't a mapping still crashes (excerpt_signing.py:485). Take a PMID_1.yaml whose content is a list (- text: foo) or a plain scalar:

  • _stored_reference_id returns None.
  • _bundle_path then accepts that file.
  • existing is a list, and bundle = existing or CommentedMap(...) passes it to _merge, which calls bundle.get("title"). That raises AttributeError and the run ends with a traceback.

The uncited pass is safe because a None stored ID is skipped, but the main signing path is not. This is the same "user-controlled file" case as the YAMLError handling. The simplest fix is to report a failure when existing is not None and not isinstance(existing, dict), with no extra try.

Fix this →

2. One _bundle_path call is still unguarded (excerpt_signing.py:434). In the uncited pass, if _bundle_path(directory, normalized, ...) != path can read other candidate files for that ID, such as the .yml twin or the disambiguated name. That call is outside the new try, so a malformed sibling still crashes the run. It would take an unusual directory layout. Moving the check inside the try, or letting _bundle_path treat an unreadable candidate as taken, would close this.

3. Non-UTF-8 files. path.read_text(encoding="utf-8") raises UnicodeDecodeError, which isn't a YAMLError. A stray binary or Latin-1 .yaml file in signed_excerpts_dir still crashes --prune. Catching (YAMLError, UnicodeDecodeError) in both places would cover it.

4. Message wording.

  • The _update_bundle failure says "existing bundle is not valid YAML" but doesn't name the file. The uncited pass does name it. Adding path.name would make the two consistent, since with the disambiguated stem the user can't easily tell which file is meant.
  • The CLI prints these as NOT signed: broken.yaml is not valid YAML…. That reads a little oddly for a file that has nothing to do with signing. problem: or skipped: might be clearer. This is cosmetic.

5. Exit behaviour, worth documenting. A malformed file anywhere in signed_excerpts_dir now makes every excerpts sign --prune run exit 1. That includes --check --prune in CI, even when the file isn't a bundle. That is a reasonable choice, since it fails loudly rather than silently. A sentence in use-signed-excerpts.md would tell users the directory should contain only bundles. Note that the "malformed bundle … exit 2" line in that doc is about excerpts sync, not sign, so it doesn't conflict with this.

Code quality, performance, security

  • Both new try blocks are narrow, catch one specific exception type, and have comments explaining why. That fits the CLAUDE.md guidance on try/except.
  • No performance changes.
  • No security concerns: loads stay in safe or round-trip mode, and nothing is written outside signed_excerpts_dir.

Test coverage

The three new tests match the commit. A test for gap 1 (a list-valued bundle for a cited reference) would be the one worth adding.

Overall

I still consider this ready to merge. Gaps 1–3 are the same kind of robustness fix as this commit and would each take a few lines. They could go in this PR or a follow-up.

Not run

uv and the project's dependencies (ruamel.yaml, pydantic) aren't installed in this runner, so I couldn't run pytest, mypy or ruff. This review comes from reading the code.

_read_bundle reports a file that is not UTF-8, not valid YAML, or not a
mapping as a BundleReadError naming it, and every read of an existing
bundle (including the _bundle_path sibling checks in the prune pass) goes
through it, so a stray file is reported instead of crashing the run.
Docs say signed_excerpts_dir should hold only bundles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 45s —— View job


PR review (after 09a58ba)

  • Read the new commit and the code around it
  • Check which earlier review points it addresses
  • Review for new problems
  • Post feedback

The commit deals with every point from the last review by sending all bundle reads through one checked loader, _read_bundle. I found no new bugs. The PR is ready to merge. Only one cosmetic point is left.

Earlier points

# Point Status
1 A bundle that is valid YAML but not a mapping crashed _merge ✅ _read_bundle raises BundleReadError for anything that isn't a dict or None, and _update_bundle turns that into a SignFailure. Tested with the list-valued case at the usual stem.
2 The _bundle_path call in the uncited pass wasn't guarded ✅ It now sits inside the try. _bundle_path reads through _stored_reference_id → _read_bundle, so a bad sibling is also reported rather than raised. Tested with the .yml twin.
3 Non-UTF-8 files ✅ UnicodeDecodeError is caught next to YAMLError. Tested with a Latin-1 café.
4 Failure message didn't name the file ✅ The message now always includes path.name, with the prefix nothing written: or skipped:
5 Exit behaviour wasn't documented ✅ use-signed-excerpts.md now says to keep only bundles in signed_excerpts_dir

What I checked

  • Round-trip loads still pass the mapping check. _update_bundle passes the round-trip yaml to _read_bundle. That loader returns a CommentedMap, which is a dict subclass, so the isinstance(data, dict) check accepts it. Comment and order preservation is unaffected.
  • Empty file. It loads as None. _stored_reference_id returns None and the uncited pass skips the file. In the main path, existing or CommentedMap(...) starts a new bundle, the same as before.
  • Duplicate keys. DuplicateKeyError in ruamel is a MarkedYAMLError, which is a YAMLError subclass, so it is caught too.
  • The .yml test case. PMID_9.yaml is visited first, and _bundle_path matches it before it ever reads the .yml file. The .yml file is then visited on its own, raises, and is reported. The test does check the sibling path it means to cover.
  • The try block. It is still narrow and catches only a project-specific exception. The one except in _read_bundle is commented as covering user-controlled files. Both follow the CLAUDE.md guidance.
  • Doctest. The one on _read_bundle gives the fully qualified exception name on the last line, which doctest accepts.

Minor (cosmetic, not blocking)

  • CLI wording. At cli/excerpts.py:222 a failure with no quote text is printed as NOT signed: skipped: broken.yaml is not a bundle: …. That doubles the prefix, and a stray file wasn't something being signed in the first place. Printing these as problem: … would read better, either when reference_id is empty or for BundleReadError failures in general.
  • A broken file blocks a cited reference. If the bundle at the usual stem is unreadable, the cited reference gets nothing written and the command exits 1. I think that is right, since overwriting a file the user may want to recover would be worse. The doc line only mentions --prune, though. It could add that a broken bundle for a cited reference also stops that reference from being signed.

Performance and security

  • Performance: no change apart from one extra isinstance check per read.
  • Security: loads stay in safe or round-trip mode. Nothing is written outside signed_excerpts_dir. A bad file is now reported, never overwritten.

Test coverage

The three cases in the new parametrized test (not a mapping, not UTF-8, malformed sibling) match the three earlier gaps. Coverage of the signer is thorough.

Overall

Ready to merge. Across the five review rounds, the privacy guarantees (no caching of file: text or local full text), the attestation model, and the merge, prune and cap behaviour have held up, and each fix has a test.

Not run

uv and the project's dependencies aren't installed in this runner, so I couldn't run pytest, mypy or ruff. This review comes from reading the code.

@caufieldjh
caufieldjh merged commit cc580a4 into main Nov 17, 2026
5 checks passed
@caufieldjh
caufieldjh deleted the caufieldjh/local-full-text-signing branch November 17, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant