Skip to content

Flaky tests read the issues once a run, and the watch reads only its own run - #2997

Merged
davidmckayv merged 1 commit into
mainfrom
ci/flaky-tests-api-budget
Dec 5, 2026
Merged

davidmckayv merged 1 commit into
mainfrom
ci/flaky-tests-api-budget

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

Why

The backend's Flaky tests workflow ran out the repository's Actions token for the hour. Its run 47482972426 got "API rate limit exceeded for installation" while scanning hours of runs, and that held up Staging's deploy. The workflow is disabled in both repos until this lands. This PR changes OpenBot's copy so it can't happen here; CopilotKit/openbot-backend has the twin PR.

What changes

Test steps: one request per run, and an error costs nothing.

  • changes reads the open flaky-test issues once per run, with one request (bun scripts/flaky-tests.ts quarantine), and passes the list to every test job as an output.
  • Each test job's flaky-tests-quarantine step only writes that list to a file. Test jobs make no request and hold no token, so they no longer need issues: read.
  • Any API error, including a rate limit or no answer within 10 s, sets nothing aside with a ::warning::. The step still exits 0.

Watcher: reads only the run that woke it. It reads only github.event.workflow_run (watchRun). There is no time-window scan and no history pagination. The clean-run count stays in the issue's state block.

  • It runs only for merge-queue and main runs. A pull request's run skips the job at no cost. A pull request's own change may be what fails, and the queue runs the same tests on main.
  • Requests:
    • one or two pages of the run's jobs;
    • notes from at most 12 of the test jobs that have any annotation;
    • only when there are notes: the issues once, at most 3 owners, and the writes.
  • Hard limit: 25 requests per watch.
  • When the token runs low: if fewer than 300 requests are left in the token's hour, it stops, leaving them for other workflows.
  • It never fails: a rate limit, an API error or a spent budget is a ::warning::, and the watch exits 0.
  • Concurrency: one job-level group, flaky-tests, with cancel-in-progress: false, so runs don't pile up. It checks out only the two scripts it runs.

What one CI run costs in API requests (GITHUB_TOKEN)

GitHub's rate limit for GITHUB_TOKEN is "1,000 requests per hour per repository", or 15,000 for an Enterprise Cloud account's resources. x-ratelimit-remaining shows what is left in the hour. Source: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api

Who Pull request run Queue or main run
changes (the list of tests set aside) 1 1
Test jobs (5 suite shards, 7 real-browser jobs, changed tests) 0 0
Watcher, no notes (no test flaked or set aside) 0 (skipped) 1
Watcher, 3 tests set aside running in 3 jobs 0 8 (jobs 1, notes 3, issues 1, writes 3)
Watcher, at most 0 25 (hard limit)

Run volume (measured 2026-12-05, last 24 hours): 269 CI runs, of which 149 pull request, 64 merge queue and 56 main. The busiest hour had 39 runs, 14 of them queue or main.

At the busiest hour:

  • Typical: 39 + 14 × 1 = 53 requests per hour.
  • With 3 tests set aside: 39 + 14 × 8 = 151 per hour.
  • Worst case, every queue and main run hitting the limit: 39 + 14 × 25 = 389 per hour.

All three are under the 1,000. The watcher also stops at 300 remaining, so it never drains the last of the hour.

Before this PR, a sweep scanned every run of the last hours. On the backend it ran past its 10 minutes and spent the hour.

Regression tests

scripts/flaky-tests.test.ts runs against fakes of GitHub's API with the same response shapes, including the 403 GitHub sends once a token's hour is spent.

  • A refused read:
    • A read of the tests set aside that GitHub refuses for its rate limit makes one request, warns, writes "nothing set aside", and exits 0.
    • The test step then passes.
  • The watcher's request count:
    • A run that left no note costs one request.
    • A run of 150 jobs, every one annotated and every test job with notes, stays within 25 requests: 2 pages of jobs, at most 12 notes read, the issues once, and the rest stops the watch with a warning.
  • A token low on requests: with fewer than 300 left, the watch stops at its first request.
  • The watcher never fails: run as CI runs it, with a rate-limited API, it warns and exits 0.
  • ci.yml: only changes reads the issues, and every test job takes the list from it.

All of these fail on main, which has #2992's version.

Run locally, one file at a time:

  • scripts/flaky-tests.test.ts (19 pass)
  • api/client-boundary.test.ts
  • scripts/ci-run-tests.test.ts
  • tests/upstream-upgrade-checks.test.ts
  • scripts/ci-changes.test.ts
  • scripts/stop-on-failure.test.ts
  • scripts/ci-budgets.test.ts
  • scripts/workflow-concurrency.test.ts

biome format and lint pass. actionlint reports nothing new. zizmor has no findings.

The workflow stays disabled; it is re-enabled after merge.

Changelog

none

…own run

The backend's Flaky tests workflow spent the repository's token for the hour, scanning hours of
runs, and held up a deploy. Here:

- ci.yml's `changes` reads the open flaky-test issues once a run, in one request, and hands the
  list to every test job; the test jobs make no request and hold no token. Any API error, a rate
  limit included, sets nothing aside with a warning and never fails a step.
- The watch reads only the run that woke it (the workflow_run event's): its jobs, and the notes of
  at most 12 test jobs, then the issues and the writes only when there are notes. At most 25
  requests, it stops when the token's hour has under 300 left, and it never fails. Pull requests'
  runs skip it; one job-level concurrency group keeps runs from piling up.
@davidmckayv davidmckayv added the full-ci Run the slow image builds on this PR label Dec 5, 2026
@davidmckayv
davidmckayv added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit 3015398 Dec 5, 2026
67 of 86 checks passed
@davidmckayv
davidmckayv deleted the ci/flaky-tests-api-budget branch December 5, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the slow image builds on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant