Skip to content

CI: a ledger or allowlist count that rises above the base branch's fails the PR - #1135

Merged
GLinnik21 merged 3 commits into
mainfrom
ci/ledger-ratchet
Oct 29, 2026
Merged

GLinnik21 merged 3 commits into
mainfrom
ci/ledger-ratchet

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

The allowlists and Sans-IO ledgers under ci/allow/ are meant to only shrink, but every existing guard compared numbers inside the same tree. A PR could add an entry, bump the file's # count: header and raise its pin in tests/test_harness.py in one diff, and every check stayed green. This PR adds the comparison with the base branch.

ci/check-ledger-ratchet.py (a new step in ci/check-python-steps.txt, so it runs in make check and in CI's host-python job):

  • Base: the merge-base of HEAD with origin/$GITHUB_BASE_REF on a pull request, else with origin/main. PLX_LEDGER_BASE=<rev> overrides. With no base at all it prints one skip line. A GITHUB_BASE_REF whose branch is missing is an error (exit 2), not a skip, so the check cannot skip on the runs it exists for. host-python checks out with fetch-depth: 0 (.github/workflows/ci.yml:415), and a test asserts it.
  • What it counts: real entry lines (non-blank, not #), never the # count: header. Each family directory (ci/allow/{workers,globals,forks,fxlanes}/) is one total, so an entry may move between area files. Each top-level ci/allow/*.txt counts on its own. Both pin tables, PINNED_LEDGER_TOTALS and PINNED_ALLOWLIST_COUNTS, are read with ast, never imported. A table that vanishes or stops being a literal is exit 2.
  • Fail rule: any counter the base has that is higher in HEAD fails, named as name: base → head. A lower or equal count passes, so a one-for-one rename (like Playback: a new play never blocks the UI on the previous player's Unload; a hung Unload fails typed after 10 s #1116's mod.rs::sink → mod.rs::raw_sink) passes.
  • New lists: a counter the base lacks (a new top-level file, family directory or pin key) is a new gate's own list. It is named in the ok line and not compared. No existing gate reads a file name that did not exist, so a new list cannot excuse a site of an existing rule. A new area file inside an existing family still counts toward that family.
  • No label. The failure message says that the lists only shrink, that the fix is to remove the entry by fixing the site, and that an exception is the owner's call, made by merging past the check. It also says an agent stops and explains instead of raising a count.

What it would have caught. The review replayed the 164 first-parent commits on main since 2026-09-07 that touched ci/allow or the harness. Six were new gates seeding their own list from zero, and they pass under the new-list rule. Four were single entries added to an existing list: #121 (statics.txt 7 → 9), #178 (statics.txt 9 → 10), #182 (wall.txt 2 → 3) and #260 (libm.txt 5 → 6). Those are what this check now stops unless the owner merges past it. Run against #1134's own base, it fails on #1134's one-time coverage expansion, as it should:

PINNED_LEDGER_TOTALS["forks"]: 58 → 75
PINNED_LEDGER_TOTALS["globals"]: 57 → 114
ci/allow/forks/: 58 → 75
ci/allow/globals/: 57 → 114

Prose that described growth as the routine path now says the ratchet fails it:

  • the test_allowlist_counts_match_the_pinned_table assertion message, which told an agent to "raise the number in PINNED_ALLOWLIST_COUNTS in the same change";
  • both pin tables' lead-in comments;
  • docs/module-layers.md's re-layering steps;
  • ci/check-dump-consumers.py, ci/allow/dump.txt and gfx/src/dump.rs;
  • ci/check-statics.sh and its failure message.

AGENTS.md, docs/sans-io.md and docs/sans-io-guide.md each gain the one fact.

Tests: ci/test_ledger_ratchet.py builds fixture repositories. It covers a rise, a fall, a rename, a move inside a family, a move across families, a header bump, pin rises and falls, new lists, a new area file in an existing family, base resolution (override, GITHUB_BASE_REF, origin/main, merge-base rather than the tip) and the exit-2 paths. It also checks the real tree: the entry counts agree with every header check-deps.sh enforces, and the CI job has full history.

On the committed tree, merged with main decb0aa:

python3 ci/test_ledger_ratchet.py   Ran 35 tests … OK
python3 ci/check-ledger-ratchet.py  ledger-ratchet: ok: no count above decb0aafa (merge-base of HEAD and origin/main); 43 ledger files, 237 entries, 20 pins
python3 ci/test_ci_split.py         OK
bash ci/check-deps.sh               check-deps: all gates green

Not covered: ci/module-cycle-baseline.json and tests/demo_library/pending.json, which are shrink-only through their own checks. No workflow file changes, so no make build-bench table.

No issue: the owner asked for this enforcement directly.

🤖 Generated with Claude Code

GLinnik21 and others added 3 commits October 29, 2026 18:12
The allowlists and ledgers under ci/allow/ are meant to only shrink, but every check on them
compared a number with another number in the SAME tree: check-deps.sh tested a file's `# count:`
header against its lines, and tests/test_harness.py tested the headers against
PINNED_LEDGER_TOTALS / PINNED_ALLOWLIST_COUNTS with assertLessEqual. One diff could add an entry,
raise the header and raise the pin, and stay green.

ci/check-ledger-ratchet.py compares with the base instead. It counts real entry lines (check-deps.sh's
own rule: not blank, not a comment; the header is never read), one total per family directory
(workers/, globals/, forks/, fxlanes/, so an entry may move between a family's area files) and one per
top-level ci/allow/*.txt, and it reads both pin tables of tests/test_harness.py with ast. A file, family
or pin key that is new counts up from 0. Any count above the base's fails, naming `name: base -> head`;
a lower or equal count passes, so a one-for-one rename such as #1116's still lands.

The base is PLX_LEDGER_BASE (the tests' override), else the merge-base of HEAD and
origin/$GITHUB_BASE_REF (an error, not a skip, when that ref is missing), else of HEAD and origin/main,
else the check skips and says so. The head is the working tree; the base is read with git ls-tree and
git show. ci.yml's host-python job, which runs the step, already checks out with fetch-depth: 0, and
the new test pins that. An exception is the owner's call, made by merging past the check; the message
tells an agent to stop and explain in the PR instead.

ci/test_ledger_ratchet.py runs the script against fixture repositories: a family count rising, falling,
a same-count rename, an entry moving inside a family, a new file, a header bumped over unchanged
entries, header and pin raised with a new entry, a pin rising, falling and new, and no base; plus the
base resolution (merge-base, not the tip of main) and the real pin tables. Replayed over the last 120
first-parent commits of main it flags only #971, the commit that created the ledgers.

AGENTS.md, docs/sans-io.md and docs/sans-io-guide.md say so, and the sentence in docs/sans-io.md that
presented the pins as the guard against a ledger and its count growing together now names the ratchet.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… that fits every list

A review of the ratchet found three faults.

A counter the base does not have was counted up from 0. A top-level ci/allow/*.txt file, a family
directory or a pin key that is new is a NEW gate's own list, not an exception added to an existing
rule: no existing gate reads a file name that did not exist (check-deps.sh's allowed() keys by file
name, its ledger engine globs the four families by name, and the Python gates read fixed paths), so
a new list cannot excuse a site of an existing rule, and failing it would fail every PR that adds a
gate. Such counters are now skipped and named in the ok line (`; new, not compared: ci/allow/foo.txt
(3)`). A new AREA file inside a family the base has still counts toward that family's total, a list
that exists at the base with zero entries still fails on its first entry, and a pin table the base
has and the head lost is still exit 2.

The failure message told every list to "move the work behind an effect", which is wrong for wall.txt,
statics.txt, dump.txt and the like. It now says to remove the entry by fixing the site so the rule
passes (for a Sans-IO ledger, move the work behind an effect, docs/sans-io-guide.md "The ledgers"),
and keeps the owner-exception and agent-stops sentences.

Prose that described growth as the routine path now says the ratchet fails a PR that grows the list,
so a new entry is the owner's call: the lead-in comments above PINNED_ALLOWLIST_COUNTS and
PINNED_LEDGER_TOTALS and the assertion message of test_allowlist_counts_match_the_pinned_table (which
said to raise the pin), docs/module-layers.md items 5 and the split paragraph, check-dump-consumers.py,
ci/allow/dump.txt's header comment (its `# count:` is unchanged), gfx/src/dump.rs, and check-statics.sh
with its failure message. The module docstring and the check-python-steps.txt comment no longer say a
new file counts from 0.

ci/test_ledger_ratchet.py: a new top-level file, a new family directory and a new pin key now pass and
are named; a new area file in an existing family that raises its total, an entry added to a list that
was empty, and a raised count that arrives with a new list all still fail.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit b763b41 into main Oct 29, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the ci/ledger-ratchet branch October 29, 2026 18:28
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