Skip to content

Add weekly warm-reference-cache workflow - #1529

Merged
cmungall merged 1 commit into
mainfrom
feat/warm-cache-workflow
Jun 18, 2026
Merged

cmungall merged 1 commit into
mainfrom
feat/warm-cache-workflow

Conversation

@cmungall

Copy link
Copy Markdown
Member

Why

The warmed reference cache (PR #1527) keeps the full validate-all reference phase fast only as long as it stays complete. As genes/references are added, new entries go uncached and validate-all re-fetches them. This workflow keeps the cache continuously complete.

What

  • scripts/warm_reference_cache.py — runs linkml-reference-validator validate data over the whole corpus in chunks with full-text fetching on (the validator's default). References are read from the structured YAML fields (not a prose regex), so it cannot produce the malformed PMID_123).md junk the earlier ad-hoc warm did. Validation pass/fail is ignored — the goal is only to populate publications/.
  • just warm-references — recipe wrapping the script.
  • .github/workflows/warm-reference-cache.yaml — runs weekly (Mon 04:00 UTC) + workflow_dispatch. Warms, then skips if the cache is unchanged; otherwise commits publications/ and opens/updates a single PR (auto/warm-reference-cache), mirroring generate-pages's token/bot/force-push/PR pattern. Raw fetched PDFs (publications/files/) are gitignored.

Behavior

On a complete cache the warm is a clean no-op (verified locally: re-running the validator over already-cached genes makes zero tracked changes), so most weeks produce no PR. Only genuinely new/incomplete references trigger a cache-update PR — which needs no real review (cache data) and can be merged at leisure.

🤖 Generated with Claude Code

Keeps the committed reference cache (publications/) complete so the full
`just validate-all` reference phase stays cache-bound instead of re-fetching
references from PubMed/providers every run.

- scripts/warm_reference_cache.py: chunked `linkml-reference-validator validate
  data` over the whole corpus with full-text fetching on (the validator's
  default). References come from structured YAML fields, not a prose regex, so no
  malformed cache filenames are produced; raw PDFs (publications/files/) are
  gitignored.
- just warm-references: recipe wrapping the script.
- .github/workflows/warm-reference-cache.yaml: weekly (Mon 04:00 UTC) +
  workflow_dispatch; runs the warm, skips if the cache is unchanged, otherwise
  commits publications/ and opens/updates a PR (mirrors generate-pages's
  token/branch/PR pattern). On a complete cache the warm is a clean no-op.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ai4c-agent

ai4c-agent Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cmungall's task in 4m 25s —— View job


PR Review: Add weekly warm-reference-cache workflow (#1529)

  • Gather context and read changed files
  • Review workflow file (.github/workflows/warm-reference-cache.yaml)
  • Review Python script (scripts/warm_reference_cache.py)
  • Review justfile changes (project.justfile)
  • Post review summary

Review Results

Status: Changes requested — one critical bug, one related important issue, two minor suggestions.

Checklist (adapted for infrastructure PR)

  • Workflow structure follows existing generate-pages pattern
  • Python script is correct and handles errors appropriately
  • Config file (conf/reference_validator_config.yaml) exists
  • publications/files/ is properly gitignored
  • Justfile recipe is well-placed and documented
  • Change detection catches new untracked files

Findings

Severity File Issue
🔴 Critical warm-reference-cache.yaml:53 git diff --quiet misses new untracked PMID_*.md files — the workflow's primary use case. See inline comment for fix.
🟡 Important warm-reference-cache.yaml:65 git diff --name-only in metadata step has the same gap — CHANGED count will be wrong. See inline comment.
🔵 Suggestion warm-reference-cache.yaml:29 fetch-depth: 0 is unnecessary; fetch-depth: 1 would be faster. Inline comment.
🔵 Suggestion warm_reference_cache.py:48-49 Silencing stderr makes debugging hard if the validator crashes unexpectedly. Inline comment.

Summary

Well-structured PR that correctly mirrors the generate-pages bot pattern (PAT fallback, branch reuse, concurrency group, single-PR update). The Python script is clean and the chunked approach with progress/ETA is a nice touch. The only blocking issue is the git diff vs untracked files bug — once that's fixed, this is good to go.

Comment on lines +53 to +59
if git diff --quiet publications/; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "Reference cache already complete; nothing to commit."
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
git diff --stat publications/ | tail -1
fi

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.

🔴 CRITICAL: git diff --quiet only detects changes to tracked files. The primary purpose of this workflow is to cache new references (new PMID_*.md files that don't exist yet on main). These untracked files will be invisible to git diff, causing the workflow to report "nothing to commit" and skip the PR — exactly when it should act.

The metadata step at line 65 (git diff --name-only) has the same issue: the CHANGED count will miss new files.

Fix: use git status --porcelain which detects both modified tracked files and new untracked files:

Suggested change
if git diff --quiet publications/; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "Reference cache already complete; nothing to commit."
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
git diff --stat publications/ | tail -1
fi
git add publications/
if git diff --cached --quiet; then
git reset HEAD publications/ >/dev/null 2>&1
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "Reference cache already complete; nothing to commit."
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
git diff --cached --stat | tail -1
fi

This stages first, then checks the staging area with --cached. The later git add publications/ on line 86 becomes a no-op (already staged), and CHANGED on line 65 should also use git diff --cached --name-only to match.

An alternative without pre-staging:

if [ -z "$(git status --porcelain publications/)" ]; then

if: steps.check-changes.outputs.has_changes == 'true'
id: metadata
run: |
CHANGED=$(git diff --name-only publications/ | wc -l | tr -d ' ')

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.

🟡 IMPORTANT: Same issue as the check-changes step — git diff --name-only misses new untracked files. If you adopt the git add + --cached approach above, this becomes:

Suggested change
CHANGED=$(git diff --name-only publications/ | wc -l | tr -d ' ')
CHANGED=$(git diff --cached --name-only publications/ | wc -l | tr -d ' ')

- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0

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.

🔵 SUGGESTION: fetch-depth: 0 clones the full history. The warm script doesn't use git history — it only reads files from HEAD. The later git fetch origin "$BRANCH_NAME" only needs the remote ref tip. fetch-depth: 1 would be faster and lighter. (Consistent with generate-pages which also uses 0, so this is a minor point — just noting the optimization opportunity.)

Suggested change
fetch-depth: 0
fetch-depth: 1

Comment on lines +48 to +49
],
stdout=subprocess.DEVNULL,

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.

🔵 SUGGESTION: Both stdout and stderr are silenced. If the validator crashes or can't be found, the only signal is the progress counter stopping (the FileNotFoundError from subprocess.run would propagate, but a crash mid-validation would be invisible). Consider keeping stderr visible for diagnostics, or at least logging a warning if returncode != 0 for a whole chunk:

            result = subprocess.run(
                [...],
                stdout=subprocess.DEVNULL,
                check=False,
            )
            if result.returncode != 0:
                print(f"  (chunk {i//CHUNK + 1} had validation issues, returncode={result.returncode})", flush=True)

Not critical since validation failures are expected, but it would make debugging easier if something unexpected happens during the weekly run.

@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.

Review Summary

Clean, well-structured workflow that mirrors the existing generate-pages pattern. The Python script is simple and correct, and the justfile recipe fits naturally. However, there is one critical bug in the change-detection logic that would cause the workflow to silently skip its primary use case.

Checklist (adapted for infrastructure PR)

  • Workflow structure follows existing generate-pages pattern
  • Python script is correct and handles errors appropriately
  • Config file (conf/reference_validator_config.yaml) exists
  • publications/files/ is properly gitignored
  • Justfile recipe is well-placed and documented
  • Change detection catches new (untracked) files — 🔴 see inline comment

Key finding

🔴 git diff --quiet publications/ does not detect new untracked files. The whole point of this workflow is to cache new references that create new PMID_*.md files. These are untracked on main, so git diff reports no changes and the commit/PR step is skipped. The metadata step (git diff --name-only) has the same gap. See inline comment for suggested fix using git add + git diff --cached, or git status --porcelain.

Everything else looks good — the concurrency group, PAT fallback, branch reuse via force-with-lease, and single-PR-update pattern are all sound.

@cmungall
cmungall merged commit 2a980af into main Jun 18, 2026
31 checks passed
@cmungall
cmungall deleted the feat/warm-cache-workflow branch June 18, 2026 03:30
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