Skip to content

Speed up validate-all: batch reference validation in one LRV process - #1522

Merged
cmungall merged 1 commit into
mainfrom
feat/batch-reference-validation
Jun 18, 2026
Merged

cmungall merged 1 commit into
mainfrom
feat/batch-reference-validation

Conversation

@cmungall

Copy link
Copy Markdown
Member

Why

The full validate-all (run on infra PRs + the weekly job) was ~80 min, dominated by
reference validation spawning one linkml-reference-validator process per file (~2,670×),
each re-parsing the schema and rebuilding the Validator — almost all process/import startup,
not actual work.

What

Now that linkml-reference-validator 0.2.1rc1 supports multi-file validate data
(linkml/linkml-reference-validator#49), validate references in a single batched process:

  • run_reference_validator.sh accepts many data files: it strips
    full_text_unavailable supporting_text across all of them in one pass (temp copies
    alongside originals so file: refs still resolve) and makes a single
    linkml-reference-validator validate data F1..FN call. Backward compatible with
    single-file use (just validate / validate-changed).
  • validate-all runs references as one batch step (errors block, label-mismatch
    warnings advisory) and drops --references from the per-file best-practices call.
  • Pins linkml-reference-validator==0.2.1rc1.

Impact

Measured locally on cached files: 12 files in 2.7 s (one process) vs 12.3 s per-file
(~4.5×)
, widening with file count (schema parsed once). This should take the ~60-min
reference portion of the full validate-all down to a few minutes. This PR's own CI runs
the full validate-all (it touches infra paths), so its runtime is the real measure.

Note: if CI is still slow, the likely remaining factor is NCBI fetches for references not in
the committed publications/ cache — that cost is identical for per-file and batch and is a
separate cache-completeness matter.

@ai4c-agent

ai4c-agent Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cmungall's task in 3m 29s —— View job


PR Review: Batch Reference Validation

  • Gather context and understand changes
  • Review scripts/run_reference_validator.sh changes
  • Review project.justfile changes
  • Review pyproject.toml and uv.lock dependency pin
  • Check for correctness, edge cases, and security
  • Post final review

This is an infrastructure/tooling PR (no gene annotations changed), so the GO term / PMID / annotation review checklist does not apply. Reviewing for code correctness, robustness, and maintainability.


Summary

Clean, well-motivated change. The core idea — single-process batch validation instead of ~2,670 process spawns — is sound and the implementation handles the key subtleties (temp files alongside originals for file: ref resolution, cleanup on exit, skip-if-no-stripping-needed).

Approved — no critical or important issues found.

Findings

🔵 SUGGESTION: validate-references-all recipe still loops per-file

project.justfile:419-425 — The standalone validate-references-all recipe still runs one LRV process per file in a for loop. Now that the script supports multi-file invocation, this could be a one-liner:

validate-references-all:
    {{ref_validator}} validate data genes/*/*/*-ai-review.yaml --schema {{schema_path}} --target-class GeneReview --config {{ref_validator_config}}

Not blocking since validate-all (the critical path) is already batched, but anyone running just validate-references-all directly would still see the old per-file overhead.


🔵 SUGGESTION: ruamel.yaml typ='safe' sorts keys by default

scripts/run_reference_validator.sh:69 — The old code used PyYAML's yaml.dump(..., sort_keys=False) to preserve key order. The new code uses YAML(typ='safe') from ruamel.yaml, which sorts keys on dump by default. Since these are temp files used only for validation and then deleted, this is harmless in practice — but worth noting if someone debugs a validation failure by inspecting the temp file and wonders why key order differs.


🔵 SUGGESTION: No explicit ruamel.yaml dependency in pyproject.toml

The inline Python script imports from ruamel.yaml import YAML, but ruamel.yaml is only a transitive dependency (pulled in by linkml-reference-validator and others). It's present in the lock file today, but if a future dependency change drops it transitively, this script would break silently. Consider adding ruamel-yaml as an explicit dependency, or keeping the old import yaml (PyYAML) approach since PyYAML is a direct dependency.


Code Quality Notes

  • Temp file cleanup (run_reference_validator.sh:63): The trap correctly reads $cleanup_list and removes each temp file plus the bookkeeping files. Solid.
  • File argument parsing (run_reference_validator.sh:49): The while [[ "$1" != -* ]] heuristic to separate data files from options is reasonable given that all gene review paths match genes/*/*/*-ai-review.yaml (never starts with -).
  • strip() return value (run_reference_validator.sh:75-89): Tracking whether changes occurred to skip unnecessary temp file creation is a nice optimization.
  • Backward compatibility: Single-file invocation (used by just validate and validate-changed) still works — the script treats a single positional arg the same as many.
  • --no-references flag (project.justfile:623): Confirmed this flag exists in the CLI (src/ai_gene_review/cli.py:723-726). Clean separation of reference validation (batch) from best-practices validation (per-file).
  • Dependency pin (pyproject.toml): linkml-reference-validator==0.2.1rc1 — pinning an RC is pragmatic here since multi-file validate data is needed and the stable release isn't out yet. The lock file diff is clean.

Verdict

No critical or important issues. Three minor suggestions, all nice-to-haves. The approach is well-designed and the implementation is correct. ✅ Approved.

@ai4c-agent ai4c-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infrastructure PR — no gene annotation changes. Code review found no critical or important issues. Three minor suggestions (batch the standalone validate-references-all recipe, note ruamel.yaml key sorting in temp files, consider explicit ruamel-yaml dependency). Well-designed batching approach with correct temp file handling, cleanup, and backward compatibility.

@cmungall
cmungall force-pushed the feat/batch-reference-validation branch from 9333d4f to 7ec7c49 Compare June 17, 2026 18:35
@ai4c-agent

ai4c-agent Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cmungall's task in 1m 52s —— View job


PR Review: Batch Reference Validation (Infrastructure)

  • Gather context and understand PR changes
  • Review scripts/run_reference_validator.sh changes
  • Review project.justfile changes
  • Review pyproject.toml and uv.lock dependency pin
  • Check for correctness, edge cases, and robustness
  • Post final review

This is an infrastructure/tooling PR — no gene annotations changed. The GO term / PMID / annotation review checklist does not apply.

  • Schema validation passes — N/A (infra change)
  • All PMIDs verified as real — N/A
  • Supporting text matches publication content — N/A
  • GO terms correct and specific — N/A
  • Review actions well-justified — N/A
  • Core functions accurately identified — N/A
  • No over-annotation issues missed — N/A

Verdict: Approved

Clean, well-motivated change. Batching ~2,670 LRV invocations into a single process is the right approach, and the implementation handles the key subtleties correctly.

Findings

No critical or important issues found.

🔵 SUGGESTION: validate-references-all recipe still loops per-file

project.justfile:419-425 — The standalone validate-references-all recipe still spawns one LRV process per file. Now that the wrapper script and LRV both support multi-file invocation, this could be a one-liner:

validate-references-all:
    {{ref_validator}} validate data genes/*/*/*-ai-review.yaml --schema {{schema_path}} --target-class GeneReview --config {{ref_validator_config}}

Not blocking since validate-all (the CI critical path) is already batched, but anyone running just validate-references-all directly would still see the old per-file overhead.

Fix this →


🔵 SUGGESTION: No explicit ruamel-yaml dependency

scripts/run_reference_validator.sh uses PyYAML (import yaml) — fine, it's a direct dependency. But worth noting that the inline script previously also used PyYAML, so nothing changed here. (The previous reviewer's note about ruamel.yaml appears to be a misread — the script uses yaml.safe_load / yaml.dump, not ruamel.yaml.) No action needed.


Code Quality Notes

  • Temp file placement (line 88): tempfile.mkstemp(..., dir=d) places temps alongside originals so relative file: references resolve correctly. Good design.
  • Cleanup (line 64): The trap reads $tmp_list and removes each temp file plus the list itself. Handles both success and failure paths.
  • Argument parsing (line 49): while [[ "$1" != -* ]] to separate data files from options is sound — gene review paths never start with -.
  • ARG_MAX safety: With ~2,670 files at ~80 chars each (~215KB total), well under the 4MB ARG_MAX on this system.
  • Backward compatibility: Single-file invocation (just validate / validate-changed) still works — the script treats one positional arg the same as many.
  • --no-references flag (line 623): Confirmed this flag exists (cli.py:723-726) and properly skips reference validation in the per-file best-practices pass.
  • Dependency pin: linkml-reference-validator==0.2.1rc1 — pinning an RC is pragmatic while multi-file validate data isn't in a stable release yet. uv.lock diff is clean (also pulls pypdf as a new transitive dep).

@ai4c-agent ai4c-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infrastructure PR — no gene annotation changes. Code review found no critical or important issues. One minor suggestion (batch the standalone validate-references-all recipe to match the new validate-all pattern). Well-designed batching approach with correct temp file handling, cleanup, backward compatibility, and ARG_MAX headroom for ~2,670 files.

…rectly)

Bumps linkml-reference-validator to 0.2.1rc1 (multi-file 'validate data') and runs
references as one batched process instead of one per file.

To let the validator read the data files directly (no parser workaround), the
corpus is made valid under LRV's strict YAML parser:
- Quote unquoted CURIE scalars in flow-style lists (e.g.
  'additional_reference_ids: [PMID:123]' -> '["PMID:123"]') across 29 files; a
  ':'-bearing plain scalar in flow context is ambiguous and only PyYAML accepts it.
- Fix genes/ARATH/GIP1: duplicate top-level 'status' key (DRAFT + a stray COMPLETE);
  PyYAML silently kept the last, ruamel errors. Kept the operative value (COMPLETE).
- Add tests/test_gene_yaml_strict.py to keep every gene-review YAML valid under the
  strict parser (guards against reintroducing lenient-only YAML; catches dup keys).

run_reference_validator.sh now passes each file to LRV unchanged, writing a stripped
temp copy ONLY for files carrying full_text_unavailable entries (its sole, project-
specific preprocessing). validate-all calls it once over the whole glob (errors block,
label warnings advisory) and drops --references from the per-file best-practices call.

Measured ~4.5x on cached files; takes the ~60-min reference portion of the full
validate-all down to a few minutes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cmungall
cmungall force-pushed the feat/batch-reference-validation branch from 7ec7c49 to bb16c8b Compare June 17, 2026 19:11
@ai4c-agent

ai4c-agent Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cmungall's task in 3m 7s —— View job


PR Review: Batch Reference Validation

  • Gather context and understand all changes
  • Review infrastructure changes (scripts/run_reference_validator.sh, project.justfile, pyproject.toml)
  • Review gene YAML changes across all 30 files
  • Review new test file (tests/test_gene_yaml_strict.py)
  • Check schema conformance and correctness
  • Post final review with verdict

This is an infrastructure/tooling PR — no gene annotation content changed. The GO term / PMID / annotation review checklist applies only to the YAML quoting/dedup fixes below.

  • Schema validation passes — infra change; YAML fixes are syntactic only
  • All PMIDs verified as real — no PMIDs added/removed/changed
  • Supporting text matches publication content — no supporting text changed
  • GO terms correct and specific — no GO terms added/removed/changed
  • Review actions well-justified — no review actions changed
  • Core functions accurately identified — no core functions changed
  • No over-annotation issues missed — N/A

Verdict: Approved

Well-designed change. Batching ~2,670 LRV invocations into a single process is the right architecture fix, and the implementation handles the key subtleties correctly (temp files alongside originals for file: ref resolution, cleanup on exit, skip-if-unchanged optimization). The gene YAML edits are all mechanical quoting fixes driven by the strict YAML parser requirement — no annotation content changed.

Findings

No critical or important issues found.

Gene YAML changes (30 files) — all mechanical, all correct

Every gene YAML change falls into exactly two categories:

  1. Quoting CURIEs in flow sequences (122 instances across 28 files): additional_reference_ids: [PMID:123] → additional_reference_ids: ["PMID:123"] and supporting_entities: [WB:WBGene00007490] → supporting_entities: ["WB:WBGene00007490"]. This is required because a bare colon inside a YAML flow sequence ([...]) is ambiguous per the YAML spec — PyYAML silently accepts it but ruamel's strict parser (used by linkml-reference-validator) rejects it. No annotation content was altered.

  2. GIP1 duplicate key fix (genes/ARATH/GIP1/GIP1-ai-review.yaml): The file had status: DRAFT at line 4 and status: COMPLETE at the end. PyYAML silently kept the last value; the strict parser errors on duplicate keys. The fix removes the trailing duplicate and sets the single status to COMPLETE (the value that was effectively in use). Correct.

Infrastructure changes

scripts/run_reference_validator.sh — Clean multi-file extension. Key design decisions are sound:

  • Temp files placed alongside originals via tempfile.mkstemp(dir=d) so file: references resolve ✓
  • trap cleanup reads from $cleanup_list, handles both success and failure ✓
  • strip() returns changed boolean to avoid unnecessary temp file creation ✓
  • Uses PyYAML (import yaml), which is a direct dependency ✓
  • sort_keys=False in yaml.dump() preserves key order in temp files ✓

project.justfile — validate-all now runs references as one batch step (line 619) and passes --no-references to the per-file best-practices pass (line 623). Clean separation. The --no-references flag is confirmed to exist at cli.py:723-726.

tests/test_gene_yaml_strict.py — Good guard test. Parses all gene review YAMLs with ruamel's strict parser to catch the exact class of issues fixed here (unquoted CURIEs in flow contexts, duplicate keys). Prevents regressions.

pyproject.toml / uv.lock — Bump linkml-reference-validator from 0.2.0rc1 to 0.2.1rc1. Pinning an RC is pragmatic since multi-file validate data isn't in a stable release yet. Lock file diff is clean (also pulls pypdf as a new transitive dep of LRV 0.2.1rc1).


🔵 SUGGESTION: validate-references-all recipe still loops per-file

project.justfile:419-425 — The standalone validate-references-all recipe still spawns one LRV process per file in a for loop. Now that the wrapper script and LRV both support multi-file invocation, this could be a one-liner:

validate-references-all:
    {{ref_validator}} validate data genes/*/*/*-ai-review.yaml --schema {{schema_path}} --target-class GeneReview --config {{ref_validator_config}}

Not blocking since validate-all (the CI critical path) is already batched, but anyone running just validate-references-all directly would still see the old per-file overhead.

Fix this →


@ai4c-agent ai4c-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infrastructure PR — no gene annotation content changed. All 30 gene YAML edits are mechanical (quoting CURIEs in flow sequences for strict YAML compliance, one duplicate-key fix). Script, justfile, and test changes are clean and well-designed. One minor suggestion (batch the standalone validate-references-all recipe). Approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant