What does a CI check on a diagram prove when the diagram passes? A freshness check asks only whether the PNG is newer than its source: three diagrams here passed two checks while they printed 794 videos for a corpus of 1,468.
This post is for people who keep generated figures next to data that grows. It follows one fix in ai-engineering-book-lab, the repo behind the book From Copilot to Colleague. You get the defect, the gate rules in code, and the tests that make the gate able to fail.
The defect: 794 printed, 1,468 in the corpus
Three diagrams quote the size of the video corpus. The script docstring says: "All three were drawn when the corpus held 794 notes and were never revisited." The fix landed on 18 November 2026 in ac32f1b, subject "diagrams: three diagrams said 794 videos; the corpus holds 1,468".
The three files are 04-theme-corpus-map (a bar chart per theme), 02-autoresearch-machine (the pipeline) and maps/02-methodology-deep-dive. The test file calls the printed size "46% wrong". The workflow names a second fault: "the chart's biggest bar named a theme that had fallen to fourth."
Why two checks passed a wrong diagram
scripts/check_diagram_sync.py and scripts/sync-diagrams.sh --check both reported the diagrams clean. The docstring gives the reason: both "ask only whether the PNG is newer than its .excalidraw source." The workflow comment puts it in four words: "Freshness is not truth."
The freshness check had its own fault before this one. A comment in .github/workflows/diagrams-check.yml says the old step used stat -f %m. That is BSD syntax, and GNU coreutils reads it as file system.
Every call errored on ubuntu-latest, the error was swallowed, and the step printed "0 stale, 0 missing-source" each day. The comment says the workflow did not enforce this until 2026-11-15, when the logic moved to scripts/check_diagram_sync.py. The commit list for that day holds 3d3935d: "diagrams: make the gate able to fail, and re-render the figure it found".
How the script derives the counts
diagrams/_update_corpus_counts.py reads 99_Meta/Corpus Stats.md. It parses the - Total notes: N line and the - Name: N lines under ## Theme counts. It rewrites the counts, bar widths and colours in the theme map (04-theme-corpus-map), and the corpus-size text in the other two, by element id. It does not render PNGs, so you run two commands:
python3 diagrams/_update_corpus_counts.py
scripts/sync-diagrams.shThe script's docstring says a second run against an unchanged corpus writes nothing. One parser bug shows in the tests: the theme parser did not stop at the next heading, and the "Frequent speakers" list "parsed as twelve extra themes". The parser now splits at the next ## heading.
The verdict: labels and colours fail at once, rank and lag fail past 5%
CI runs python3 diagrams/_update_corpus_counts.py --check. In this mode the script edits copies in a temporary directory and writes nothing to the repo. The verdict function runs four checks in order (excerpt):
if problems:
return False, f"{len(problems)} structural problem(s)"
if not changes:
return True, "in sync"
if printed is None:
return False, "headline count unreadable"
behind = abs(total - printed) / total
if behind > tolerance:
return False, f"{behind:.1%} behind, tolerance {tolerance:.0%}"A structural problem is a row with another theme's chapter label, a bar in another act's colour, a theme missing from or extra on the chart, or a ranking out of order. A wrong chapter label, a wrong colour, or a missing or extra theme fails at any tolerance. A ranking swap fails only when the lower row's count is more than the tolerance above the upper row's.
The default tolerance is 0.05. The help text says why it is not zero: "a gate that failed on every new note would be routed around within a week."
The near-tie that would have cried wolf
On 18 November 2026, the same day as the fix above, 1846b5b changed the ranking rule: "diagrams: the truth gate would have cried wolf on a near-tie". The docstring of structural_problems says the first version "compared change labels, and so called any row swap structural". Evals & Reliability and Agent Architecture sat four notes apart. The test comment gives 838 and 834.
The docstring says four more talks would have reordered the chart, "failed the gate on an unrelated corpus PR, and opened an issue a night". The scheduled run opens an issue on failure. The rule now is:
if below > above * (1 + tolerance):The rule reads both counts from the stats file, not from the chart. As a worked example, take the 838 notes that the test comment gives for Evals & Reliability. Then Agent Architecture must pass 879.9 (838 × 1.05) before the swap counts as structural. The live stats file has since moved on, so the threshold today is different.
The test test_a_near_tie_swap_is_lag_not_structure nudges Agent Architecture to three more than Evals & Reliability and expects no problems. The test test_a_real_rank_change_is_structural sets one theme to three times the top row's count and expects a failure.
What the tests hold
scripts/test_update_corpus_counts.py calls itself "Negative controls". Its cases check that a mislabelled row, a miscoloured bar and an unknown theme each fail. An eleventh theme stops the run with a "10 rows" error instead of losing a row. The smallest bar keeps a 4 px floor but prints its real count.
The tests above are for the gate script. The README says the _gen_*.py figure scripts "are not linted and have no tests".
What is not measured
- No file in the repo shows the output of a
--checkrun, before or after the fix. The messages above come from the code. - No file records how many corpus PRs the first ranking rule would have failed. "An issue a night" is the docstring's forecast.
- The 5% tolerance is a choice in the code, not a measured value.
- This script checks three diagrams. The post does not cover other figures in the repo.
How this post was made: an AI agent drafted it from the sources listed for this post (the ai-engineering-book-lab script, tests, workflow, README and git log), a second agent reviewed it, and Timur merged it.
