Skip to content

The repo gate stops when ttok counts nothing, instead of passing every file - #1283

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
wakamex:ttok-gate
Oct 2, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
wakamex:ttok-gate

Conversation

@wakamex

@wakamex wakamex commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

gates/repo.ts reads ttok's stdout with Number(...), so a ttok that prints nothing counts as 0 tokens and every capped file passes. That's how main went over the comp.ts cap without anyone seeing it: #1269 measured 63,821 on its branch, but five merges had grown main by 429 tokens in the meantime, and the squash-merge put comp.ts at 64,250. It's 64,251 today, and the gate still reported 49/49 on main.

ttok on the machine running gates/repo.ts main before this PR main with this PR
working (pipx install ttok) 48 / 49, bend2/comp.ts: 64251 > 64000 ttok same
prints nothing 49 / 49, every file passes stops: ttok counted nothing for README.md (pipx install ttok), exit 1
exits nonzero 49 / 49 stops with the same message, exit 1
not installed crashes on a null stdout stops with the same message, exit 1

Token counts are ttok over bend2/comp.ts at each merge commit; it gives 64,172 at d7af6bf, the figure recorded there.

The change only touches ttok(): it throws when ttok is missing, exits nonzero, or prints anything but a positive count. Caps and the allow list are untouched.

Heads-up: once this lands, the repo gate fails on main until comp.ts loses about 250 tokens, so that's the next thing.

…y file

ttok() read ttok's stdout as a number, so a ttok that printed nothing
read as 0 tokens and every capped file passed; a missing ttok threw on a
null stdout only by accident. Main has been over comp.ts's 64000 cap
since bendlang#1269 (64250 at fb6f32a, 64251 now) with the gate reporting
49/49 on a machine whose ttok printed nothing. A ttok that is missing,
exits nonzero or prints no positive count now stops the gate with its
file and how to install ttok.

With a working ttok, main gives 48/49 (bend2/comp.ts: 64251 > 64000);
with a ttok that prints nothing, exits 3, or is not on the PATH, the
gate exits 1 naming the first capped file it could not count.
@wakamex

wakamex commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

This closes the fail-open hole, but the overshoot itself came from #1269 being checked against a stale base. Today the gate runs on whatever branch the author has locally, and nothing reruns it on what main becomes after the merge: #1269 passed at 63,821 on its branch, five other merges had added 429 tokens to main in the meantime, and the squash-merge landed at 64,250 with no check in between.

The fix is to check each PR combined with current main right before it lands, not just its own branch. GitHub can do that if the gate runs there instead of on someone's machine. The repo gate only needs git, bun and ttok, so unlike the test and perf gates (which need Metal and the minis) it can run on GitHub's own Linux machines. It takes two pieces:

  1. A workflow file that runs the gate and reports a pass/fail check on the PR. The merge_group trigger is what lets it run on the merge queue's combined branch (below):
# .github/workflows/repo-gate.yml
name: repo-gate
on:
  pull_request:
  merge_group:
jobs:
  repo-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: oven-sh/setup-bun@v2
      - run: pipx install ttok
      - run: bun gates/repo.ts
  1. A repo setting that a repo admin turns on for main, under Settings > Rules > Rulesets:
    • "Require status checks to pass", with repo-gate added, so a PR can't merge while that check is failing or missing.
    • "Require merge queue" (merge queue docs).

With the queue on, nobody merges directly. "Merge when ready" puts the PR in the queue, GitHub builds a temporary branch of current main plus every PR queued ahead plus this one, and runs the check on that. If it passes, the PR merges; if not, it's dropped from the queue and main is untouched. For #1269 that branch would have been main with the five newer merges plus #1269, at 64,250 tokens, so it would have failed instead of landing.

The simpler setting is "Require branches to be up to date before merging" instead of the queue: a PR that's behind main has to be updated and rechecked before it can merge. That gives the same guarantee, but with 10+ merges a day everyone keeps rebasing and waiting on reruns, which the queue does for them.

Bend had exactly this kind of setup (a checks workflow with a merge_group trigger) until c36597a replaced the Bend 1 tree, so this would be bringing one job back, plus one allow-list line for the workflow file. Happy to send the workflow as a PR if you want it; the ruleset needs a repo admin.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

I will set up the workflow for us running on the cluster, probably tomorrow. This way non-mergeable PRs wont even be able to merge as you suggested. The rhythm is very fast. Thanks for pointing and for the PRs @wakamex

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.

2 participants