# Measure CI Pipeline Reliability from First Attempts

> A workflow that ends green 89% of the time can still fail 8.6% of runs for no code reason and queue for eight minutes in a bad week. Export runs and jobs with gh api, classify each run by its first attempt, and turn percentile and red-main thresholds into owned work items.

- Author: [Shashank Rawlani](https://shashank.rawlani.com)

- Published: 2026-11-20T13:30:00.000Z

- Updated: 2026-11-20T13:30:00.000Z

- Category: Automation Tutorials

- Canonical source: https://automationtester.in/blog/automation-tutorials/measure-ci-pipeline-reliability

- Tags: ci-cd, github-actions, ci-reliability, flaky-tests, gh-cli, metrics

**Quick answer:** Measure CI reliability from the first attempt of every run, not from its final colour. Export four weeks of workflow runs and their jobs (with `filter=all`, so earlier attempts are kept), then compute per segment: first-attempt pass rate, the share of failures that passed on a rerun of the same commit, time to signal at p50 and p95, queue time at p95 per runner label and week, and the length of each red-main episode. Give each number a threshold and an owner before you look at the data, and treat a breach as a work item, not a dashboard colour.

A pull-request workflow finishes green 89.1% of the time over four weeks. The self-hosted runner pool's average queue time across the same period is 72 seconds. Both numbers look healthy, and both hide the problems. In that window 8.6% of pull-request runs failed on the first attempt and then passed when someone pressed re-run, with no code change. For one week the same runner pool had a p95 queue time of 499 seconds. And main stayed red for 16.7 hours after a break landed at 17:40 UTC.

Those figures come from this article's lab: a generated four-week export shaped like the GitHub REST API's workflow-run and job responses, with known faults planted in it. The script never touches the network, so it reproduces the same output, and it reads a real export unchanged.

This is the last of eight parts on CI test infrastructure for GitHub Actions. Each earlier part fixed one cause of slow or untrustworthy CI; this one measures the whole pipeline and says which fix a bad number points to.

## Six numbers, each attached to a decision

A metric earns its place only if a bad value tells someone what to do. Each of these comes from fields the API already returns.

| Metric | Computed from | A breach means |
| --- | --- | --- |
| First-attempt pass rate | Jobs with `run_attempt: 1` | Authors are waiting on red runs; read the failure table before anything else |
| False-failure rate | Runs whose attempt 1 failed and whose latest attempt passed | The pipeline fails without the code being wrong; find the step and its owner |
| Unresolved failures | Failed attempt 1, never rerun | Unknown; the false-failure rate is a floor until these are classified |
| Time to signal, p50 and p95 | Run `created_at` to the last attempt-1 job's `completed_at` | The feedback budget for that stage is blown |
| Queue time, p95 per label and week | Job `created_at` to `started_at` | Runner or shared-dependency capacity, not test speed |
| Red-main episodes | First failed attempt on main to the next green of that commit or a newer one | Recovery is slow; check whether evidence or ownership was missing |

Final pass rate is missing on purpose. A run that went green on its third attempt counts as a success there, which hides exactly the cost this review exists to expose. The lab prints it beside the first-attempt figure so the gap shows.

## A passing rerun is evidence the code was not at fault

The false-failure rate rests on one documented guarantee. GitHub's re-run documentation says a re-run uses the same `GITHUB_SHA` and `GITHUB_REF` as the original event. So when attempt 1 fails and attempt 2 passes, the commit under test did not change between them. Something else did: a runner, a container pull, a shared environment, the order tests ran in.

That makes the measure honest in one direction only. It counts failures that someone reran. A failure nobody reran stays unclassified, which is why the lab reports unresolved failures separately instead of assuming they were real. Treat the false-failure rate as a lower bound.

The same page explains the job data you will see. Re-running failed jobs also re-runs the jobs that depend on them, while the rest keep their previous outputs. A run can be re-run at most 50 times and only within 30 days, so older data is final.

One blind spot no run-level export can fill: with `retries` set, Playwright labels a test that failed and then passed as flaky, and the job fails for it only if `failOnFlakyTests` is on. Count those at the test level, as in [gating CI on Playwright flake rate](/blog/automation-tutorials/fail-ci-flaky-playwright-tests-evidence) and [comparing JUnit XML across runs](/blog/tools-reviews/find-flaky-tests-across-junit-xml-runs), and keep this review for what the pipeline itself does.

## Export once, compute offline

Pull the data with `gh api`, save it, and compute from files, so every change to the analysis runs against identical input. The listing endpoint accepts the workflow file name in place of its numeric ID.

```
mkdir -p export/jobs
gh api --paginate --slurp \
  "repos/OWNER/REPO/actions/workflows/ci.yml/runs?created=2026-10-12..2026-11-08&status=completed&exclude_pull_requests=true&per_page=100" \
  > export/runs.json

# The created filter caps a search at 1,000 runs. A count of exactly 1000 means the window was cut short.
jq '[.[].workflow_runs[]] | length' export/runs.json

jq -r '.[].workflow_runs[].id' export/runs.json | while read -r id; do
  gh api --paginate --slurp "repos/OWNER/REPO/actions/runs/$id/jobs?filter=all&per_page=100" \
    > "export/jobs/$id.json"
done
```

What each flag is for:

- `--paginate` keeps requesting pages until none remain, and `--slurp` wraps every page in one outer JSON array, which is the shape the script reads.

- `per_page` defaults to 30 and tops out at 100 on both endpoints.

- The listing returns at most 1,000 results per search when you filter by `created`, `branch`, `event`, `status`, `actor`, `head_sha` or `check_suite_id`. A repository with more than 1,000 runs in the window needs one export per week.

- `filter=all` on the jobs endpoint returns jobs from every attempt. The default, `latest`, returns only the most recent execution, which erases the failed first attempt you are trying to count.

`gh run list` looks like a shortcut and is not one. It fetches 20 runs unless you pass `--limit`, and its JSON fields include `attempt` but no jobs, so it can tell you a run was retried and never why.

This is a run from the lab's export after a rerun. The run object carries the latest attempt's conclusion, so it says `success`; the first attempt's failure survives only in the jobs file.

```
{
  "id": 9100000362,
  "name": "ci",
  "head_branch": "feature/132",
  "head_sha": "de5ea2c2b02d50e419e7567e7ffa0a12144306b1",
  "event": "pull_request",
  "status": "completed",
  "conclusion": "success",
  "run_attempt": 2,
  "created_at": "2026-11-06T12:22:07Z",
  "run_started_at": "2026-11-06T13:07:50Z",
  "updated_at": "2026-11-06T13:16:51Z"
}
```

```
attempt  job          conclusion  created_at            started_at            completed_at          failed step
1        lint         success     2026-11-06T12:22:09Z  2026-11-06T12:22:15Z  2026-11-06T12:23:24Z
1        unit         success     2026-11-06T12:22:09Z  2026-11-06T12:22:24Z  2026-11-06T12:24:59Z
1        integration  success     2026-11-06T12:22:11Z  2026-11-06T12:22:50Z  2026-11-06T12:28:17Z
1        e2e          failure     2026-11-06T12:25:01Z  2026-11-06T12:25:31Z  2026-11-06T12:30:38Z  Run Playwright
2        e2e          success     2026-11-06T13:07:53Z  2026-11-06T13:08:04Z  2026-11-06T13:16:49Z
```

Only `e2e` ran again, because only it failed. The author got a red signal at 12:30, about eight and a half minutes after pushing, and a green one 46 minutes later. A final-status dashboard records this run as a clean pass.

The lab's generator, a seeded Node 26 script, plants a known set of faults so the review has a right answer: an end-to-end step that fails about 7% of first attempts and usually passes on retry, a service container that occasionally fails to start, unit failures from real bugs on about one pull request in nine, a self-hosted pool that loses capacity for the week of 26 October, and two real breaks on main, one of them pushed late in the day.

## Classify every run by what its first attempt did

The core of the review is one pass over the runs. For each run it finds the first failing step of attempt 1, then decides the outcome from what happened afterwards.

```
const all = JSON.parse(readFileSync("export/runs.json", "utf8")).flatMap((p) => p.workflow_runs);
// A run cancelled by a newer push (cancel-in-progress) says nothing about reliability.
const runs = all.filter((r) => !["cancelled", "skipped"].includes(r.conclusion));
const FAILED = ["failure", "timed_out"];

const rows = runs.map((run) => {
  const jobs = jobsOf(run.id);
  const first = jobs.filter((j) => j.run_attempt === 1);
  const firstFailed = first.filter((j) => FAILED.includes(j.conclusion));
  const failedStep = firstFailed.length
    ? firstFailed[0].steps.find((s) => s.conclusion === "failure")?.name ?? "(no step)"
    : null;
  const ended = (js) => Math.max(...js.map((j) => t(j.completed_at)));
  const firstEnd = ended(first);
  const latest = jobs.filter((j) => j.run_attempt === run.run_attempt);
  // Only count work that actually executed after attempt 1 finished.
  const rerunMin = jobs
    .filter((j) => j.run_attempt > 1 && j.conclusion !== "skipped" && t(j.started_at) > firstEnd)
    .reduce((m, j) => m + (t(j.completed_at) - t(j.started_at)) / 60000, 0);
  let outcome = "passed";
  if (firstFailed.length) {
    if (run.run_attempt === 1) outcome = "not rerun";
    else outcome = run.conclusion === "success" ? "passed on rerun" : "failed again";
  }
  return {
    run, segment: `${run.name}/${run.event}`, event: run.event, jobs, failedStep, outcome, rerunMin,
    signalMin: (firstEnd - t(run.created_at)) / 60000,
    firstEnd, latestEnd: ended(latest),
  };
});
```

Three choices in that code change the numbers. Cancelled runs are dropped: a run superseded by a newer push never had a chance to give a signal, and counting it as a failure punishes the concurrency settings that save minutes. `timed_out` counts as a failure, since the author got nothing. And the segment is workflow plus event, because a pull-request run and a push to main have different budgets and owners.

The failing step's name is what turns a count into an owner. A small map does it:

```
const OWNER = { "Set up job": "platform", "Start services": "platform", "Run Playwright": "e2e-owners" };
const ownerOf = (step) => OWNER[step] ?? "service-team";
```

Name your steps so this works. A step called `Run tests` that also starts containers and seeds data cannot be attributed to anyone, and the review falls back to whoever owns the repository.

## Percentiles per week, because averages hide the bad week

GitHub's built-in Actions performance metrics report average run time, average queue time and failure rate, aggregated by UTC day, excluding skipped runs and runs that used zero minutes, with custom ranges of up to 100 days. They are useful for a first look. An average over a month cannot show a week where one runner pool was short of machines.

The lab makes the point with its own data. Across all four weeks, the mean queue time for jobs on the self-hosted `arc-linux` label is 72 seconds, comfortably inside a two-minute threshold. In the week of 26 October the p95 for the same label was 499 seconds, and it pushed that week's pull-request time to signal from about 14 minutes to 20.4.

```
// Nearest-rank percentile: the smallest value with at least p% of values at or below it.
const pct = (xs, p) => {
  if (!xs.length) return NaN;
  const s = [...xs].sort((a, b) => a - b);
  return s[Math.max(0, Math.ceil((p / 100) * s.length) - 1)];
};
```

Nearest-rank always returns a value that really occurred, so an action item traces to a specific job. Interpolating methods differ slightly on small samples; pick one and never compare figures computed with different methods.

## Red main is a list of episodes, not a mean

A "mean time to recover" for main sounds like a DORA metric, and it is not one. DORA's metrics describe deployments to production, and in 2023 DORA renamed mean time to recover to failed deployment recovery time, because the old definition did not separate failures caused by a change from failures caused by something external, such as a data centre outage. That distinction is worth borrowing for CI. A red main fixed by re-running the same commit was not a break, and it needs a different owner from one fixed by a new commit.

```
const main = rows.filter((r) => r.event === "push" && r.run.head_branch === "main")
  .sort((a, b) => a.firstEnd - b.firstEnd);
// Green means a run of this SHA or a newer one passed: an older SHA going green proves nothing.
const greens = main.flatMap((r) => {
  if (!r.failedStep) return [{ at: r.firstEnd, created: t(r.run.created_at), r }];
  if (r.run.conclusion === "success") return [{ at: r.latestEnd, created: t(r.run.created_at), r }];
  return [];
}).sort((a, b) => a.at - b.at);
```

The condition on `created` matters because runs on main overlap. Without it, an older commit's rerun finishing green a minute after a newer commit failed would close the episode, although the newer commit is still broken.

The lab found eight episodes. Their mean is 3.0 hours, which describes none of them: five lasted under 1.3 hours and were fixed by a rerun, and one lasted 16.7 hours because the break landed at 17:40 UTC and nobody pushed a fix until the next morning. Wall-clock recovery counts the night. Decide whether your threshold is in clock hours or working hours, write that down, and report the list of episodes rather than one figure.

## The weekly review, run against the lab export

```
node generate-export.mjs
node reliability.mjs
```

```
wrote 376 runs in 4 pages, 1566 jobs
== Segments (4 weeks, first attempt unless stated)
segment            runs  pass1%  final%  rerun%  falseFail%  unresolved  signal p50/p95 min  rerun min
ci/pull_request     267    80.5    89.1    12.7         8.6          18         13.0 / 17.8      243.6
ci/push             109    88.1    93.6     6.4         5.5           6         13.3 / 18.1       51.1

== Weekly trend (pull_request)
2026-10-12  runs  69  pass1  81.2%  falseFail 13.0% (9)  signal p95  13.9 min
2026-10-19  runs  64  pass1  71.9%  falseFail 10.9% (7)  signal p95  14.3 min
2026-10-26  runs  64  pass1  84.4%  falseFail  1.6% (1)  signal p95  20.4 min
2026-11-02  runs  70  pass1  84.3%  falseFail  8.6% (6)  signal p95  14.7 min

== Queue time by runner label and week (job created_at -> started_at)
arc-linux  2026-10-12        jobs  207  p50   35s  p95   58s
arc-linux  2026-10-19        jobs  176  p50   31s  p95   56s
arc-linux  2026-10-26        jobs  180  p50  176s  p95  499s
arc-linux  2026-11-02        jobs  192  p50   35s  p95   57s
ubuntu-latest  2026-10-12    jobs  204  p50   11s  p95   19s
ubuntu-latest  2026-10-19    jobs  182  p50   11s  p95   19s
ubuntu-latest  2026-10-26    jobs  183  p50   11s  p95   19s
ubuntu-latest  2026-11-02    jobs  197  p50   12s  p95   19s

== First-attempt failures by step, outcome and owner
  23  Run Playwright         passed on rerun  owner: e2e-owners
  20  Run unit tests         not rerun        owner: service-team
  11  Run unit tests         failed again     owner: service-team
   4  Start services         passed on rerun  owner: platform
   3  Run Playwright         not rerun        owner: e2e-owners
   2  Set up job             passed on rerun  owner: platform
   1  Run Playwright         failed again     owner: e2e-owners
   1  Start services         not rerun        owner: platform

== Red main episodes (first failed attempt -> next green attempt on main)
2026-10-14T09:47Z    2.5 h  Run unit tests   newer commit     owner: service-team
2026-10-15T04:29Z    0.8 h  Run Playwright   rerun, same SHA  owner: e2e-owners
2026-10-26T09:13Z    0.6 h  Run Playwright   rerun, same SHA  owner: e2e-owners
2026-10-28T05:42Z    0.7 h  Start services   newer commit     owner: platform
2026-10-29T06:25Z    1.2 h  Run Playwright   rerun, same SHA  owner: e2e-owners
2026-11-03T06:41Z    0.6 h  Run Playwright   rerun, same SHA  owner: e2e-owners
2026-11-04T17:40Z   16.7 h  Run unit tests   newer commit     owner: service-team
2026-11-06T11:39Z    0.8 h  Run Playwright   rerun, same SHA  owner: e2e-owners

== Action items
- ci/pull_request: time-to-signal p95 17.8 min > budget 15
- ci/pull_request: false failures 8.6% > 5%
- ci/push: false failures 5.5% > 5%
- queue arc-linux week 2026-10-26: p95 499s > 120s
- red main 2026-11-04: 16.7 h > 4 h (service-team)
```

Read the action items against the tables above them, not on their own:

- The pull-request time-to-signal breach and the queue breach are one problem. Signal p95 sat near 14 minutes in three weeks and jumped only in the week the `arc-linux` pool was short. Making tests faster would not have fixed it.

- The false failures belong mostly to one step. 23 of the 29 runs that passed on rerun failed in `Run Playwright`. That is a work item for the end-to-end owners, and most of the 244 rerun minutes on pull requests are its price.

- The 20 unit failures nobody reran are most likely real bugs caught where they should be. They lower the pass rate without being a reliability problem, which is why pass rate alone cannot drive action.

- The weekly false-failure counts run from 1 to 9. Single-digit counts swing that much by chance, so judge the rate over the four-week window and use the weekly line only to see where a trend starts.

## Thresholds that start work, and what they cost

The thresholds live at the top of the script, so they are reviewed like code:

```
const THRESHOLDS = {
  signalP95Min: { pull_request: 15, push: 20 }, // budget per segment
  queueP95Sec: 120,                              // per runner label, per week
  falseFailurePct: 5,                            // attempt-1 failures that passed on rerun
  redMainHours: 4,                               // any single red-main episode
};
```

None of these values is a standard. The time-to-signal budget comes from what each stage may cost an author, and the queue limit from how much of that budget you will spend waiting for a machine. The other two are judgement calls: start where current data yields one or two items a week, and tighten as they get fixed.

Two costs come with any threshold. A low count crosses a percentage line by accident: main's 5.5% is 6 of 109 runs, and one fewer rerun would have cleared it. Add a minimum event count before a rate may raise an item. And once a number becomes a target, people learn to move the number. DORA's own guide lists setting metrics as a goal as the first common pitfall. A team told to cut its rerun rate can stop rerunning and leave failures unresolved, which this review would show as a growing unresolved column.

## Where the numbers mislead, and the check for each

### A month that quietly stops at 1,000 runs

The listing caps filtered searches at 1,000 results, and the export looks complete either way. If the run count is exactly 1000, split the `created` range by week and export again.

### Every rerun looks like a first-time pass

Jobs fetched without `filter=all` contain only the latest attempt, so the false-failure rate comes out as zero. Check that some job in the export has `run_attempt` greater than 1 whenever a run does.

### Two workflows averaged into one

A nightly workflow with a 40-minute budget mixed into pull-request numbers drags the p95 over every threshold. Segment by workflow and event; a `merge_group` run gets its own segment because its event differs.

### A renamed step moves its failures to the wrong owner

The owner map matches step names exactly, so renaming `Run Playwright` to `E2E tests` silently hands its failures to the default owner. Before each review, list the failed-step names that are not keys in the map; any name on that list is either new or renamed, and needs an owner before its numbers mean anything.

## Apply this now

Today, export the last 28 days of your busiest workflow with the commands above, confirm the run count is under 1,000, and run the review. Open the action item with the clearest owner as an issue, with the run IDs behind the number attached so the owner can open the failing attempts directly. Commit the thresholds and owner map beside the workflow and repeat the export weekly. Keep the saved export and the output as evidence: re-running the analysis must reproduce the issue's figures.

## The eight parts, placed on one review

Each earlier part of this series is the fix for one line of the review's output:

- [Part 1, test placement by feedback cost](/blog/automation-tutorials/ci-test-pyramid-feedback-cost), sets the time-to-signal budget each segment is measured against.

- [Part 2, test data collisions](/blog/automation-tutorials/eliminate-ci-test-data-collisions), is the first thing to rule out when a test step fails and then passes on rerun under parallel load.

- [Part 3, CI-only failures](/blog/automation-tutorials/debug-ci-only-failures-environment-evidence), covers failures that persist on rerun in CI but never reproduce locally.

- [Part 4, dependency caching and drift](/blog/automation-tutorials/ci-cache-dependencies-without-hiding-drift), shows up as time-to-signal swings on cache misses and failures that start when a cache key changes.

- [Part 5, parallelism and dependency capacity](/blog/automation-tutorials/control-ci-parallelism-dependency-capacity), owns queue-time breaches and setup-step failures against shared services.

- [Part 6, artifacts that explain failures](/blog/automation-tutorials/retain-ci-artifacts-explain-failures), shortens red-main episodes, because the owner can diagnose from evidence instead of a rerun.

- [Part 7, OIDC and least privilege](/blog/automation-tutorials/secure-ci-oidc-least-privilege), explains a failure that repeats on every attempt: a trust condition that rejects the run's claims is configuration with a platform owner, and no rerun clears it.

## Questions about measuring CI reliability

### Is the rerun rate the same as the flaky rate?

No. The rerun rate counts every run with more than one attempt, including reruns of real failures that failed again. In the lab, 34 pull-request runs were rerun and 23 of them passed; the other 11 failed again. Only a pass on rerun is evidence of a false failure.

### What token does the export need?

The documentation says anyone with read access to the repository can use both endpoints, and that classic personal access tokens and OAuth app tokens need the `repo` scope for a private repository. Running `gh` as a user with read access is enough.

### How much history is enough?

Enough that each rate rests on more events than your minimum count. Four weeks gave this lab 109 runs on main, which is thin for a 5% threshold. A lower-traffic repository should widen the window rather than lower the bar.

## Primary references

- [GitHub REST API endpoints for workflow runs](https://docs.github.com/en/rest/actions/workflow-runs): run fields (`run_attempt`, `conclusion`, `created_at`, `run_started_at`, `previous_attempt_url`), the 1,000-result cap under filters, `per_page` limits, `exclude_pull_requests`, and the workflow file name accepted as `workflow_id`

- [GitHub REST API endpoints for workflow jobs](https://docs.github.com/en/rest/actions/workflow-jobs): job timestamps, step conclusions, labels and runner fields, and `filter=all` versus the default `latest`

- [Re-running workflows and jobs](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/re-run-workflows-and-jobs): same `GITHUB_SHA` and `GITHUB_REF` on re-run, dependent jobs re-run with failed ones, the 30-day window and 50-re-run limit

- [About GitHub Actions metrics](https://docs.github.com/en/actions/concepts/metrics): built-in performance metrics report averages for run time, queue time and failure rate

- [Viewing GitHub Actions metrics](https://docs.github.com/en/actions/how-tos/administer/view-metrics): UTC-day aggregation, exclusion of skipped and zero-minute runs, custom ranges up to 100 days

- [Understanding the search syntax](https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax): the `YYYY-MM-DD..YYYY-MM-DD` range used by the `created` filter

- [gh api manual](https://cli.github.com/manual/gh_api): `--paginate` and `--slurp` behaviour

- [gh run list manual](https://cli.github.com/manual/gh_run_list): default limit of 20 and the available JSON fields

- [DORA's software delivery performance metrics guide](https://dora.dev/guides/dora-metrics/): the five current metrics defined around deployments, and setting metrics as a goal as a pitfall

- [A history of DORA's software delivery metrics](https://dora.dev/insights/dora-metrics-history/): the 2023 rename of MTTR to failed deployment recovery time, separating change-caused failures from external ones

- [Playwright test retries](https://playwright.dev/docs/test-retries): the passed, flaky and failed categories

- [Playwright TestConfig `failOnFlakyTests`](https://playwright.dev/docs/api/class-testconfig): exiting with an error when any test is marked flaky, added in v1.52

## Continue reading on AutomationTester.in

- [Preview a GitHub Actions Matrix Before include Adds the Wrong Jobs](https://automationtester.in/blog/tools-reviews/preview-github-actions-matrix-include-exclude)
- [Gate an MCP Server and Client on the Official Conformance Suite](https://automationtester.in/blog/ai-in-testing/mcp-conformance-framework-ci)
- [Make JUnit Failures Useful in CI](https://automationtester.in/blog/automation-tutorials/junit-failure-reports-useful-ci)
- [Write k6 Thresholds That Fail CI for the Right Reasons](https://automationtester.in/blog/automation-tutorials/k6-thresholds-fail-ci-right-reasons)
- [Understand Appium 3 Drivers, Plugins, and Boundaries](https://automationtester.in/blog/automation-tutorials/appium-drivers-plugins-test-boundaries)

Source: [Measure CI Pipeline Reliability from First Attempts](https://automationtester.in/blog/automation-tutorials/measure-ci-pipeline-reliability) by Shashank Rawlani.
