Sub topic 4
A Decision Framework for Where a Check Belongs
This chapter gives you a repeatable process for placing a check on pull requests, at merge time, or in a nightly build. It assumes you know what a CI pipeline and a status check are. It also assumes you can tell lint, unit tests, integration tests, and end-to-end tests apart, and that you have read the earlier chapters on feedback speed versus confidence and on check categories.
Why a framework helps
Teams often place checks by habit. Someone adds a slow test to every pull request, developers start waiting 40 minutes for feedback, and then someone moves the test to nightly "just for now." Neither decision looked at data.
A framework replaces that guesswork with a short list of questions. You answer them for each check, and the answers point to a stage. Two people who use the same framework on the same check should land on the same stage.
The three stages
Each stage has a different job.
| Stage | Trigger | Job | Typical time budget |
|---|---|---|---|
| Pull request | `pull_request` | Fast feedback to the author while the change is fresh | Under 10 minutes |
| Merge | `merge_group`, `push` to `main` | Confirm the combined result is safe to ship | 10 to 30 minutes |
| Nightly | `schedule` | Cover slow, broad, or costly checks | Up to hours |
The time budgets are starting points, not rules. Your team's tolerance for waiting sets the real numbers.
The five questions
Ask these in order. Stop at the first question that gives a clear answer.
- How long does the check take? Measure the median and the 95th percentile (p95) of recent runs, not your memory of it.
- How often does it fail for reasons unrelated to the change? This is the flake rate. A check with a high flake rate cannot block anyone.
- How well does it catch problems in the code that the author just changed? This is locality. Lint and unit tests are highly local. A full end-to-end suite is not.
- What does a miss cost? If a bug that this check would catch reaches
main, how bad is it and how hard is it to undo? - How much does a run cost? Count runner minutes, paid services, and shared resources such as a test database or a staging environment.
Question 1: runtime
Runtime sets the first boundary. If the check fits inside the pull request budget, it is a candidate for that stage. If it does not, it moves later unless question 4 says the risk is too high.
Use percentiles, because a check with a 4-minute median and a 25-minute p95 will frustrate developers on one run in twenty.
Question 2: reliability
A check must be trustworthy before it can block merges. If a check fails randomly 5% of the time, then with 40 pull requests a day, two of them will fail for no reason. Developers learn to rerun and ignore failures, and the check loses its value.
A flaky check does not belong in a required stage until you fix it or quarantine it. The chapter on flaky tests covers this in detail.
Question 3: locality
A check with high locality tells the author something about their own change. When it fails, the author knows what to look at. A check with low locality fails for reasons spread across many changes, so a failure on a pull request may not be the author's fault.
High locality favors pull requests. Low locality favors merge or nightly stages, where a failure is reported against a known commit on main.
Question 4: cost of a miss
Some failures are cheap to fix after the fact. A broken documentation link can be repaired in the next commit. Others are expensive: a broken database migration, a leaked secret, or a failure in the checkout flow.
When the cost of a miss is high, pull the check earlier, even if it is slow. When the cost is low, you can accept a delay.
Question 5: cost of a run
Cost matters most for checks that need paid or shared resources. Running a 90-minute end-to-end suite on every push to every pull request multiplies cost by the number of pushes. Running it once a night costs one run.
Turning answers into a placement
The following flowchart summarizes the decision.
Read the flow as a default, not a law. Two cases need extra thought.
- A slow check with a costly miss. The flow sends it to the merge stage. If even that is too slow, consider speeding it up with sharding, caching, or a smaller test subset on pull requests plus the full suite at merge.
- A fast check that is low-value. It may fit on pull requests, but fast does not mean useful. If it has never failed in six months, question whether it is needed at all.
Worked example
Suppose a Node.js service has these checks. The table shows measured data and the resulting placement.
| Check | p95 runtime | Flake rate | Locality | Miss cost | Placement |
|---|---|---|---|---|---|
| ESLint | 1 min | 0% | High | Low | Pull request |
| Unit tests | 4 min | 0.2% | High | Medium | Pull request |
| Integration tests | 18 min | 1% | Medium | High | Merge |
| Dependency vulnerability scan | 6 min | 0% | Low | Medium | Merge, plus nightly for new advisories |
| Full end-to-end suite | 95 min | 4% | Low | High | Nightly, with a smoke subset at merge |
Walk through the end-to-end suite. It takes 95 minutes, so it does not fit the pull request budget. A miss is costly, so the flow points to merge. But 95 minutes is far too long even for a merge queue, and the 4% flake rate means it cannot block. So the suite goes nightly. Because a miss is costly, you also carve out a small smoke subset that runs at merge time, after it proves reliable.
The first two placements translate directly into workflows. This pull request workflow runs only the fast checks:
name: pr
on:
pull_request:
branches: [main]
jobs:
fast-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
- run: npm testThis merge workflow runs the integration tests when the merge queue builds a candidate commit and after each push to main:
name: merge
on:
merge_group:
push:
branches: [main]
jobs:
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run test:integrationThe nightly workflow runs the end-to-end suite on a schedule, with a manual trigger for reruns:
name: nightly
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
jobs:
e2e:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run test:e2eCommon errors in placement
- Placing by name instead of by data. "Integration tests are slow, so they go nightly" ignores that yours may take three minutes. Measure first.
- Treating nightly as a dumping ground. A nightly failure that nobody owns teaches the team to ignore red builds. Every nightly check needs an owner, which a later chapter covers.
- Putting a flaky check in a required stage. It blocks innocent changes and trains people to click rerun.
- Duplicating the same check at every stage. Running unit tests on the pull request, in the merge queue, and on
maincosts three runs. Repeat a check only when the later run tests something different, such as the combined result of several merged pull requests. - Forgetting the merge queue changes what is tested. A pull request passes against its own branch. The merge queue tests the branch combined with the queued changes ahead of it. That is why merge-stage checks catch problems that pull request checks cannot.
Applying the framework to a new check
When someone proposes a new check, ask for the five answers before choosing a stage. A useful habit is to record them in the pull request that adds the check. For example:
- Runtime: p95 of 7 minutes over 20 runs.
- Flake rate: 0 failures out of 20 runs on unchanged code.
- Locality: fails only when the changed package is affected.
- Miss cost: a broken build artifact, which blocks the release.
- Run cost: no paid services.
This record makes the later review easy, because you can compare the original numbers with current ones. The final chapter on reviewing and moving checks builds on that habit.
Summary
Place each check by asking about runtime, reliability, locality, cost of a miss, and cost of a run. Reliability acts as a gate: a check that cannot be trusted does not block. Runtime and cost of a miss then decide between pull request, merge, and nightly. Record the answers so you can revisit them as the numbers change.
Exercise
A contract-test suite has a p95 runtime of 14 minutes and a flake rate of 0.5%. It checks the API your service shares with three other teams. A broken contract blocks those teams' deployments. Your pull request budget is 10 minutes. Where do you place it, and why? Name one way you could still give pull request authors some early signal.
Show answer
Place it at merge time (merge queue and push to main). It is reliable enough to block, but at 14 minutes it exceeds the pull request budget. A miss is costly because other teams are blocked, so nightly is too late. For early signal, run a faster subset on pull requests, such as contract tests only for the endpoints the change touches (using a path filter or change-based selection), and run the full suite at merge time.
Exercise
A team runs the same unit-test job on pull requests, in the merge queue, and on every push to main. Under what condition is the second and third run worth keeping, and what should you check if the extra runs never fail?
Show answer
The later runs are worth keeping only when they test something the pull request run did not, such as the combined result of several changes merged together. If they never fail, check whether the merge queue is actually combining changes (for example, whether queue throughput is low so candidates rarely differ from the pull request branch). If the results are always identical to the pull request run, drop the duplicate runs and keep only the stage with the added value.