Raft's CI practices: keeping CI cheap and green
This is how the Raft team runs CI with Stamp. Agents open most of our pull requests, so agents keep CI under control too. This page is our practice: what to measure, what to run where, and what to do when the base branch goes red. Every command is a Stamp command an agent can run.
Find what costs most
Start from numbers, not guesses. Ask Stamp where the minutes went:
stamp ci report --repo OWNER/REPO # the last 7 days, against the 7 before
stamp ci report --repo OWNER/REPO --window 14dIt is read from what Stamp recorded of every run, so it costs no GitHub quota. Pull request runs and post-merge runs are shown apart. Read it top-down:
- Top workflows and jobs by minutes: where the money goes.
- Runners and cost: minutes and dollars per runner label, at the list prices of runnerdb, which Stamp refreshes daily (the report names the source and date, e.g.
prices: runnerdb 2026-11-18). A few minutes on macOS can cost as much as hours on Linux. - Skip candidates: jobs that run on almost every pull request run and almost never fail for real. They are the first to move to after merge.
- Flaky: jobs that failed and then passed on the same commit. Fix them or quarantine them; each one costs a rerun.
- Waste: superseded and manual cancels, fail-fast cancels and reruns. Many superseded minutes mean pushes come faster than CI finishes: push less often, or cancel older runs sooner.
- Base red: minutes spent on reruns and cancels on the default branch.
- Slowest queued: runs that waited for a runner rather than ran. Read the 1ST JOB columns too: a run can start at once and still wait minutes for its first job.
- Δ: the change against the window before, so you can see whether a CI change worked. It shows
-until Stamp has recorded the whole window before; the last lines of the report say so.
See CI report for what each number means.
Reading one week: an example
Here is how one week of a large monorepo's report reads. The figures are relative and only describe that week; yours will differ.
- Pull request runs against post-merge runs. Post-merge had about 60% as many runs as pull requests but more than twice the minutes and the cost: the full suite already runs after merge, so that is where most of the money is.
- Workflows and jobs. One workflow,
Test, is almost all of it. On pull requests, one job,unit-fast(8 minutes median, on every push), is about 40% of pull request minutes on its own. After merge, the sevenunit-servershards are about 40% of post-merge minutes. Those are the jobs worth making faster or narrower. - Skip candidates. Two:
changesandcut-prep-guard, together well under 1% of the minutes. Check what a candidate does before you move it:changesis the path filter that decides which other jobs run, so it stays. A candidate is worth moving when it is also high in the jobs list. - Flaky. On pull requests, at most 8 per job. After merge, five
…-gatejobs ofTesteach failed and then passed on the same commit 72 to 77 times. That is the first thing to fix. - Waste. After merge, reruns and runs on a red base together were about 30% of post-merge minutes. Pull request waste was under 10% of pull request minutes, mostly superseded runs. So the expensive habit that week was re-running a red base, not pushing too often.
- Queue time. The queue was 0s everywhere: runs started at once. The wait was before the first job: post-merge
Testreached its first job in 11m45s at p95, and the slowest queued runs were all post-mergeTestruns, up to 27 minutes. - Against the week before. Δ was
-everywhere: Stamp started recording on 11-12, so the week before was not covered. From 11-26 a 7-day report compares two full weeks; run it again after each change and check that Δ goes down.
What we took from it: keep the base green and fix the flaky gates first, then make unit-fast and the unit-server shards cheaper. Moving skip candidates would have saved little that week.
What we look for every week
One agent per repository reads the report once a week, on the same day, and after every CI change. People read the same report on the repository's CI page (https://stamp.build/github/OWNER/REPO/ci). Reading it is not the work: each finding below becomes a task with an owner, or a line saying why nothing changes.
- The same workflow on pull requests and after merge. Compare its failure rate in the two blocks. When it fails much more after merge (one week of ours: 3.2% on pull requests, 8.1% after merge), pull requests let through breaks their own checks could have caught, and the base pays for them in reruns (base red). Don't answer by running the full suite on every pull request. List the post-merge breaks of the week and group them by which pull request check would have caught each. That week, about a fifth needed only a check that already existed and wasn't triggered: a repository-wide test not in the always-run list, a manifest check that ran only when CI scripts changed, a docs change that didn't trigger the test reading those docs. Fix those first; they cost almost nothing per pull request.
- Jobs that wait instead of work. A job with many minutes, a 0% failure rate and a median close to a fixed wait is usually holding a runner while it waits for a deploy or another workflow. Make the wait cost nothing: start the work from the event it waits for (
workflow_run,deployment_status), or poll from a scheduled run. - Post-merge jobs that run on every merge. Path filters are not only for pull requests. A desktop or mobile build that runs on every merge to the base, whatever changed, belongs behind the same path filter as on pull requests, with a full run at release time.
- What made pull requests wait. PR LATENCY gives last push to all green (p50 and p90) and its ten slowest pull requests, each naming the workflow and job that finished last. If one small gate is that job again and again, it is waiting for a runner or for another run, not working: read its 1ST JOB columns and the slowest queued runs.
- Approval to merge. When a slow one is mostly green to merge, CI was not the wait: look at auto-merge, a merge hold or a person.
- Costly test files that never failed. Not a list to delete from. They are the first files to split, to run only when their code changes on pull requests, or to make faster; the report says how much each costs per week so you can tell whether it is worth it. It needs the test report artifact.
- Flaky by date. Many gate jobs flaky the same number of times on the same day is one incident (one red base, rerun many times), not many flaky tests. Count incidents, then look at what is left.
- Δ after a change. A CI change is done when the next report shows the number moved. If it didn't, say so and undo the change or try the next thing.
To drill into one run the report points at, use the run commands:
stamp run list --repo OWNER/REPO --workflow Test --branch main --limit 20
stamp run view RUN_ID --repo OWNER/REPO # jobs, how long each took, which failed
stamp run view RUN_ID --repo OWNER/REPO --job JOB_ID --logThe cheapest win is almost always not running everything on every push, rather than making one test faster.
Run only what a pull request needs
- On a pull request, run the checks that cover what it changes: path-filtered jobs, the package's own tests, lint for the files it touched.
- Run the full suite once the change is on the protected branch (Post-merge CI).
- Don't dispatch the full suite by hand for an ordinary pull request (
stamp workflow runexists for the cases a person asked for, not as a routine check).
When the base goes red after a merge
Stamp tells the agents whose pull requests merged since the last passing run, and comments once on each of them (Post-merge CI). That is a list of suspects, not a verdict.
- Read the failure.
stamp run view RUN_ID --repo OWNER/REPO --log-failedshows the failed jobs and their errors. Find the failing test file and what it exercises. If it looks flaky, re-run only the failed jobs:stamp run rerun RUN_ID -R OWNER/REPO --failed(from server-v0.1.413 that is also what a plainstamp run rerundoes on a failed run;--allreruns every job, which costs a whole run). It is the cheapest check, and a passing re-run turns the branch green again (and lifts a merge hold) with no fix pull request. - Match it to a change. Compare that file and the code it covers with each suspect's diff. If it isn't yours, say so with the evidence, so the real author is reached quickly.
- Fix forward or revert. Revert when the cause is clear and the revert is clean. Fix forward when reverting would undo something already applied, such as a database migration that has run. During a merge hold, GitHub's own revert pull request (its title starts with
Revert ") merges without thefix-redlabel. - Keep the test's intent. Never loosen an assertion or a guard to make a test pass. Change the setup so the guard sees a legitimate path.
A worked example. A pull request retired a feature flag for two-step sign-in, making the second step always required. After it merged, an account-cleanup test failed: it turned two-step sign-in on for a person and then used a test helper that signs in with the password alone. The helper now correctly refused. The fix did not relax the helper; it added a test helper that completes a real second step, and the test used that.
Hold merges while the base is red
When the base is red, every new merge makes the failure harder to read and every later release waits. Turn on the merge hold for the branch: while the named workflow is red, only pull requests carrying the fix label (fix-red) merge, and other auto-merges wait and land by themselves once the branch is green.
An agent never changes the hold itself; it asks an owner or admin once with an admin ops request (CLI 0.28.0 or later):
# merge-hold.yaml
repository: OWNER/REPO
reason: "Stop merges piling onto a red main"
steps:
- merge_hold: {branch: main, workflows: [Test]}stamp request admin-ops --plan merge-hold.yaml --dry-run # what the approval page will show
stamp request admin-ops --plan merge-hold.yaml # sends it; an owner or admin approves onceOnce it is on, label the fix when you open it:
stamp pr edit N -R OWNER/REPO --add-label fix-redUse the label only for a pull request that actually fixes the red run. Stamp checks the next run after such a merge and tells you if the branch is still red.
Ask for settings you don't own
Repository settings, environments, rulesets and the merge hold belong to people with admin rights. Don't ask a person to click through GitHub for you: file a request they approve once on its own page (Permission requests), for example stamp request admin-ops for settings, or the prepared request when a workflow guard refuses your push (Allow one push).
Run the after-merge-only checks yourself
Some checks run only on the protected branch, not on pull requests: whole-repository lint, file-size or module-shape limits, tests against a real database. Each pull request passes on its own and the branch still goes red when they combine. When your change touches one of those areas, run that check locally before you merge.
Stamp tracks the test workflows that also run on pull requests, and every workflow the branch's merge hold names, whether or not it runs on pull requests. Any other workflow that runs only on the base branch is not recorded: its state is unknown, so it neither holds merges nor tells the suspect pull requests when it fails. Name it in the merge hold, or watch it yourself.
Next
- How merges, auto-merge and post-merge CI work: Review and merge.
- What each kind of request allows: Permission requests.