Skip to content

CI fails when it grows slower or starts more jobs than its written budget - #2988

Merged
davidmckayv merged 1 commit into
mainfrom
ci/time-budget
Dec 5, 2026
Merged

davidmckayv merged 1 commit into
mainfrom
ci/time-budget

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

What this changes

CI now fails when it grows slower or starts more jobs than a written budget, so it cannot creep back unnoticed.

The budget (.github/ci-budgets.json, limits), set from the run after #2986 (whole run 8.1 min, slowest job 6.1, unit shards 3-6, WebKit 4-5, desktop setup window 4.3):

Budget Why
Slowest job 8 min the slowest unit shard plus a couple of minutes
Whole CI run 11 min 8 min of jobs, plus changes, verify and a runner's wait
Jobs one PR push can start 82 today's count, every workflow, matrices expanded
Any job's timeout-minutes 30 the hard stop; no job a PR starts may be allowed longer

Desktop's installer builds (13-17 min on Windows and Mac) aren't in this round's targets. They name their own limits, with the reason, so they're held where they are today. Two jobs are lowered to fit the 30-minute limit: Desktop upgrade (60 → 30, takes about 3 min) and Model lock (60 → 30, takes 1-7 min).

On every PR (scripts/ci-budget.test.ts, which runs in the unit suite): the jobs a push to a PR can start are counted from the workflow files as GitHub would start them on a PR from this repository. The count uses GitHub's own expression parser (@actions/expressions, already a dev dependency). A job that is off on every PR is left out. A job that depends on what the run finds is counted, along with every leg of its matrix. A called workflow counts its jobs. The test fails if any of these happens:

  • the count goes over 82
  • a job's time limit goes over 30
  • a job's budget goes over 8, or a run's over 11
  • a matrix known only at run time has no cap

On real runs (ci-watch): after each run in the merge queue or on main, where timings are steady, each job is held to its budget by its median over its last five runs there, not by any single run.

  • A job that has crept: its median goes over. It opens or reopens its ci-budget issue (or updates the body of the open one, with no comment spam), and CI watch fails until the job is back under budget. Then the issue is closed.
  • One slow run: doesn't move the median, so it fails nothing.
  • A PR's own runs: never held to time budgets. They're held to the job count instead, read from the PR's own .github folder as data (sparse checkout, never run). This catches a matrix that grows at run time past its cap.

This replaces the per-run rule, which opened an issue whenever any one run of any job went over, PR runs included. That rule left about 60 ci-budget issues open, so they were all ignored. The first steady run after merge closes the ones that aren't over budget by median.

No Slack and no email: the signal is a red CI watch run and the issue.

What to expect after merge

The median window still holds the merge queue's runs from before #2986 (WebKit 12.5, desktop setup window 10.9, whole run 14.9). CI watch will be red, with those three issues current, until about three merge-queue runs after #2986 have landed. Then it clears by itself.

Where it runs

GitHub Actions and its scripts only: ci-watch.yml, two timeout-minutes, .github/ci-budgets.json and scripts/. No app, server, API, database or release-policy change.

Changelog

none

Proof

  • scripts/ci-budget.test.ts (12 tests), on real data:
    • this repository's workflows pass
    • a fixture workflow over every limit fails with exactly what is over (13 jobs against 10, a 45-minute time limit, an uncapped run-time matrix, a budget over the slowest job)
    • eight real merge-queue runs from 5 December: WebKit's slowest shard ran 14.2, 12.5, 12.4, 15.8 and 10.2 min. That's flagged against 8 (median 12.5). Against the old budget of 15, the one 15.8 run is not flagged, though the old per-run rule filed it.
    • real PR runs are never timed
    • a job needs three runs before it counts
  • bun test on ci-budget, ci-budgets, ci-watch, workflow-concurrency, ci-runners, ci-changes, ci-run-tests: 240 pass.
  • Dry runs of ci-watch.ts --dry-run against live runs: merge-queue run 47476732864 would update the WebKit, desktop-setup-window and whole-run issues and close 44 stale ones. PR run 47471673283: 34 jobs started, within the 55 CI allows.
  • biome format and lint clean; tsc clean on the changed scripts; zizmor: no findings. actionlint: no new findings. Its one finding is the existing custom runner label openbot-ubuntu-16core in desktop-upgrade.yml.

How the leaders do it (searched 2026-12-04)

  • TeamCity fails a build on a duration condition, against a fixed value or the last good build, separate from its hard timeout: build failure conditions.
  • Datadog CI Visibility alerts on a pipeline's or job's duration by an aggregate over a window (median, p75 to p99), per pipeline, rather than one run: CI monitors, pipeline alerts.
  • Netflix runs a regular job that detects build-time regressions and notifies the owning team. Develocity notes that daily data is noisy and longer windows are better: Develocity.
  • GitLab: a long job holds back the pipeline's failure, so check budgets early: pipeline efficiency.
  • Open source: I found nothing maintained that does per-job budgets, a failing check and issues. The closest, workflow-timer, compares whole-workflow time in a PR comment, has 9 stars and no releases. So this extends the CI watch we already have.

…dget

.github/ci-budgets.json now carries the repository's limits: at most 82 jobs
for one push to a pull request, no job allowed past 30 minutes, no job's
budget over 8 minutes, no run's over 11. A test fails a pull request that
goes over any of them, counted from the workflow files as GitHub would start
them on a pull request.

CI watch holds each job to its budget by its median over its last five runs
in the merge queue and on main, where timings are steady, instead of by any
single run: one slow run no longer opens an issue, a job that has crept stays
over, keeps its ci-budget issue current and fails CI watch until it is back
under, when the issue is closed. A pull request's run that starts more jobs
than its workflow files allow does the same.
@davidmckayv
davidmckayv added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit c27d555 Dec 5, 2026
96 of 100 checks passed
@davidmckayv
davidmckayv deleted the ci/time-budget branch December 5, 2026 05:15
davidgilmoursp pushed a commit to davidgilmoursp/OpenBot that referenced this pull request Dec 5, 2026
… branch older than the limits (CopilotKit#3009)

Two fixes from openbot-backend CopilotKit#1249 and CopilotKit#1250, the same code here.

A job over budget in the merge queue or on main failed CI watch, which marks
main's commit not green; Staging's pick of green main (the backend's
scripts/staging-green.ts, which reads this repository too) then skipped every
commit until the job was fast again, though every real check passed. It now
keeps its ci-budget issue and prints a `CI over budget` warning, and CI watch
stays green. A pull request still fails the budget test and the job count.

On a pull request's run CI watch reads that branch's own
.github/ci-budgets.json. A branch cut before the file had `limits` (CopilotKit#2988)
crashed it ("undefined is not an object (evaluating 'file.limits[key]')"). Its
job count is now skipped, with a note.
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