ci(risk tier): grade on the glaeda-route App's budget; create risk labels only when missing
risk evidence now does its reads on the manaflow-glaeda-route App's budget, the way merge freeze already does, and creates the risk labels only when one is missing.
Why. Every workflow shares one GITHUB_TOKEN installation budget. On 2026-10-26 the janitor read 4514 of 5000 left at 07:18Z and 0 at 07:52Z, and the budget ran out again before 08:48Z. That second drain failed the nightly-next promotion request (tick run 40294661953). Before this change, each risk evidence run (24 to 35 an hour) spent about eight GITHUB_TOKEN calls:
- the files, the pull request and the compare;
- four
gh label createcalls, each answering 422 because the label already exists; - a
gh pr viewfor the labels; - for high-risk PRs, also the comments, reviews and label events.
What changes (main's copy, which is the one GitHub runs for pull_request_target):
- Token mint: a
Mint the glaeda-route tokenstep asks for contents, issues and pull-requests, all read-only. It is continue-on-error, like merge-freeze.yml. - Grade: runs with
GH_TOKEN=$READ_TOKEN. If the mint failed or the App's read is refused, it grades again on GITHUB_TOKEN. Output and summary go to temp files first, so a failed first attempt leaves no half verdict. - Label:
- The labels read goes on the App, with GITHUB_TOKEN as the fallback.
- Removes and adds stay on GITHUB_TOKEN. Its label events start no workflow, so the step doesn't grade itself again.
- The four labels are created only when
--add-labelfails, then the add is tried again.
- Result: in the usual run (tier unchanged), GITHUB_TOKEN calls go from about 8 to 0.
Not changed:
- No permission, environment, trigger or concurrency change.
- The gate logic and
ENFORCE_FROMare untouched. - No supply-chain or permissions test is loosened.
Tests: tests/test_ci_workflow_run_api_budget.py (wired in ci-guards) has a new RiskTierCalls class. It runs both steps as written, with a recording gh and a stand-in risk_tier.py, and checks:
- reads use the App token;
- a refused App read falls back with exactly one verdict;
- an unchanged label costs only one App read;
- a tier change makes two writes on GITHUB_TOKEN and creates no label;
- a missing label is created and then added.
Also ran locally: test_ci_fork_runner_routing, test_ci_required_checks_have_no_path_filters, test_ci_pr_media_privacy, test_ci_production_secrets_protected_env, test_ci_workflow_permissions_are_job_scoped, test_ci_signing_secrets_need_release_environment and test_ci_self_hosted_guard.sh. All pass.
Overlap:
- cmux#25203 (gt-quota, same lane) touches this step too. Its risk-tier part will be dropped in favour of this PR.
- cmux#25301 changes feat-cmux-next's copy of risk-tier.yml, which pull_request_target never runs. See the comment at the top of main's copy.
Risk: low. If the App token is missing or refused, every path falls back to today's GITHUB_TOKEN behaviour. Only a missing label costs more than today: four creates plus a second add, once.
Agent session: agent session
🤖 Generated with Claude Code
![View with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v3-3x.png)
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
- New Features
- Pull requests can now be labeled with low, normal, or high risk tiers. A separate label marks high-risk pull requests reviewed by a maintainer.
- Improvements
- Risk grading and label checks can fall back to the workflow’s standard token when an optional app token is unavailable or a read fails. Labels are created only when needed.
- Tests
- Added coverage for token fallback, risk-label updates, and missing-label handling.