Skip to content

CI watch makes four API requests a run, and stops green when GitHub refuses - #2996

Merged
davidmckayv merged 1 commit into
mainfrom
ci/watch-api-calls
Dec 5, 2026
Merged

davidmckayv merged 1 commit into
mainfrom
ci/watch-api-calls

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

What this changes

CI watch now makes 4 API requests per run in the merge queue or on main, down from about 21. When GitHub refuses a request, it stops with a warning and a green run.

Why: the Actions token gets 1,000 API requests an hour, and every workflow in the repository shares them. The backend hit the limit on 4-5 December. CI watch runs after every run of CI and Desktop. Since #2988, it held each job to its median by reading the jobs of the last 15 runs on every steady run: about 21 requests per run (the run's jobs, an earlier failed run of the same commit, the run list, 15 runs' jobs, the issues, and an update to each open over-budget issue).

Per run, before and after:

Before After
A run in the merge queue or on main about 21 4
A PR's run 2 2
A job newly over budget 3 3, once
Closing stale issues 2 each, all at once (about 90 the first time) 2 each, at most 5 per run

At the busiest hour of the last 24 (46 watched runs, 15 of them steady):

  • before: about 377 requests from CI watch alone
  • after: about 122

How:

  • Where the times live: each workflow's recent times are in a CI budget record: <workflow> issue. The body has a table people read (median, budget, last five times per job) and the same times as data in an HTML comment that CI watch reads back. Each run adds its own jobs' times, so it never re-reads history.
  • Issues: a job already over budget with its issue open costs no request. The record shows its current times.
  • Closing: an issue closes only when its job is measured back under budget. A job whose issue is open but that never runs on main or in the queue is closed too, once the record has seen at least three runs.
  • Refusals: any API error now gives a warning, CI watch stopped, and exit 0. A budget breach still turns the run red.
  • Two runs at once: two CI watch runs finishing together can each update the record, and the later write drops the earlier run's time. One time out of five is lost now and then, which doesn't move a median.

Where it runs

scripts/ci-watch.ts and scripts/ci-budget.ts, which only GitHub Actions runs. No workflow, app, server or API change.

Changelog

none

Proof

  • scripts/ci-watch-requests.test.ts runs scripts/ci-watch.ts as CI runs it, with the workflow_run event, against a stand-in for gh api (scripts/ci-watch.fixtures/fake-gh.ts). The stand-in answers from this repository's real merge-queue and PR runs and logs every request.
    • A steady run with seven earlier runs available makes exactly 4 requests, reads only its own run's jobs, and writes its time into the record. It stays red for the jobs still over budget, with no extra request.
    • No record yet: it starts one and closes nothing it hasn't measured.
    • Twelve stale issues: it closes 5, in 14 requests.
    • A job newly over budget: 3 requests, once.
    • A PR run: 2 requests or fewer.
    • A rate-limited API: a warning, exit 0, after 1 request.
    • Against main's ci-watch.ts, the same test fails 5 of 6: 11 requests where 4 are allowed, 15 where 5 are, and exit 1 on a rate limit.
  • bun test on ci-watch-requests, ci-budget, ci-watch, ci-budgets, ci-changes, workflow-concurrency and flaky-tests: 236 pass.
  • A live dry run on merge-queue run 47482244024 reads the run and the open issues and would start the record.
  • biome format and lint clean; tsc clean on the changed files.

…efuses

The Actions token has 1,000 API requests an hour for the whole repository,
and CI watch runs after every run of CI. Holding jobs to their median meant
reading the jobs of the last fifteen runs on every run in the merge queue or
on main: about twenty requests each, a few hundred an hour at the busiest.

Each workflow's recent times now live in its `CI budget record: <workflow>`
issue, a table a person reads with the times CI watch reads back. A run adds
its own jobs' times to it, so it reads only the run it watches: its jobs, an
earlier failed run of its commit, the open ci-budget issues, and the record's
update. A job newly over budget opens its issue once; an issue already open
costs nothing more; stale issues close five at a time.

A request GitHub refuses or fails (a rate limit, an outage) now ends CI watch
with a warning and a green run: it reports on CI, it is not CI.
@davidmckayv
davidmckayv added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit 06362e9 Dec 5, 2026
29 checks passed
@davidmckayv
davidmckayv deleted the ci/watch-api-calls branch December 5, 2026 06:04
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