Sub topic 10
Controlling matrix runs with fail-fast and max-parallel
This chapter assumes you can read a workflow file and already know how strategy.matrix expands into jobs, including include and exclude. It covers the two settings that control how those jobs run together: fail-fast and max-parallel. It also covers how they interact with caching.
What the two settings control
A matrix creates many jobs from one job definition. By default, GitHub starts as many of them as runner capacity allows. If one fails, GitHub cancels the rest. Two keys under strategy change this behavior:
| Setting | Default | Effect |
|---|---|---|
| `fail-fast` | `true` | When any matrix job fails, GitHub cancels all in-progress and queued jobs from the same matrix. |
| `max-parallel` | Not set (as many as possible) | Caps how many matrix jobs from this job definition run at the same time. |
Neither setting changes which combinations exist. They only change when jobs run and what happens after a failure.
Default behavior: fail-fast is on
Here is a plain matrix with no failure controls:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm testThis expands to six jobs. Because fail-fast defaults to true, a failure in ubuntu-latest with Node 18 cancels every job still running or waiting. Cancelled jobs show as cancelled in the run summary, not as failed. Only the job that failed first is the real failure.
This default suits many projects. If any configuration is broken, the pull request cannot merge, and cancelling the rest frees runners and shortens the feedback loop. The cost is lost information. You see one failure, fix it, push, and may only then discover that Windows fails for a different reason.
Turning fail-fast off
Set fail-fast: false when you want the full picture of which configurations fail:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm testEvery job now runs to completion regardless of the others. The workflow run is still marked failed if any job failed. Only the cancellation behavior changes.
Choose fail-fast: false when:
- You are supporting several runtime versions and want to know exactly which ones break.
- Failures are likely to be configuration-specific, such as a Windows path bug.
- Jobs are cheap enough that finishing them costs little.
Keep the default when jobs are slow or expensive and any single failure already blocks the change.
The value can be an expression. A common pattern is to fail fast on pull requests, where feedback speed matters, and run everything on pushes to the main branch:
strategy:
fail-fast: ${{ github.event_name == 'pull_request' }}
matrix:
node: [18, 20, 22]Limiting concurrency with max-parallel
By default, GitHub runs as many matrix jobs at once as it can. Your plan's concurrency limits and runner availability decide the actual number. Set max-parallel to lower it:
strategy:
max-parallel: 2
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20, 22]With six jobs and max-parallel: 2, GitHub starts two jobs. Each time one finishes, the next queued job starts. Total wall-clock time grows, so you should have a reason to set it. Typical reasons are:
- A job talks to a shared external resource, such as a staging database or a rate-limited API, that cannot handle six simultaneous clients.
- You want to stay within a limited pool of self-hosted runners without starving other workflows.
- You deploy to environments one after another and want ordering pressure. Setting
max-parallel: 1runs jobs strictly one at a time, though the order is not a guaranteed contract you should rely on.
max-parallel is an upper bound, not a guarantee. If your account has fewer free runners than the value you set, fewer jobs run.
Combining the settings with include and exclude
The two controls work on the final expanded job list, after exclude and include are applied. This example comes from the same matrix pattern used earlier in the tutorial:
strategy:
fail-fast: false
max-parallel: 2
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20, 22]
exclude:
- os: windows-latest
node: 18
include:
- os: ubuntu-latest
node: 22
experimental: trueThe matrix starts with six combinations. The exclude entry removes Windows with Node 18, leaving five. The include entry matches the existing Ubuntu with Node 22 combination, so it adds the experimental variable to that job instead of creating a new one. The result is five jobs, at most two running at a time, and none cancelled when another fails.
Allowing specific jobs to fail
Sometimes fail-fast: false is too broad. You may want most configurations to block a merge but let one, such as a prerelease Node version, fail without consequences. Use continue-on-error at the job level, driven by a matrix variable:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: true
matrix:
node: [20, 22]
experimental: [false]
include:
- node: 24
experimental: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm testThis produces three jobs. The Node 24 job is marked experimental. If it fails, the workflow run can still pass, and it does not trigger cancellation of the other jobs. If a Node 20 or 22 job fails, the run fails and fail-fast cancels the rest.
The job-level continue-on-error is different from the step-level one. At the step level it lets a job continue past a failing step. At the job level it controls how the job's result counts toward the run.
How failure control affects caching
Cancellation and caching interact in ways that are easy to miss. The actions/cache action saves its cache in a post-job step. That step runs only when the job succeeded. A job that fails or is cancelled by fail-fast does not save its cache.
Two practical consequences follow:
- With
fail-fast: true, a failing run can cancel jobs before they save caches. The next run starts cold for those combinations, even though the cache keys are valid. - With
fail-fast: false, passing jobs finish and save their caches even when a sibling fails. Later runs benefit.
max-parallel matters when matrix jobs share a restore-keys prefix. If jobs run strictly in sequence, a later job can restore a cache that an earlier job saved in the same run. When all jobs start at once, none of them can see a cache that a sibling saves later, because caches are only available after the saving job finishes.
The per-combination keys from the previous chapter still apply. Each job reads and writes its own entry, so concurrent jobs do not overwrite each other.
Decision flow
Common mistakes
- Expecting max-parallel to reduce cost. It lowers peak concurrency but runs the same total number of jobs. Billed minutes stay roughly the same.
- Reading cancelled jobs as failures. Under fail-fast, only one job is the real failure. Open that job's log. Do not investigate the cancelled ones.
- Leaving fail-fast on while debugging flaky tests. A flaky failure in one job hides whether other configurations would also fail.
- Setting
continue-on-error: truefor the whole job. This hides real failures in every configuration. Drive it from a matrix variable so only chosen combinations are exempt. - Forgetting the matrix size limit. A workflow run can generate at most 256 matrix jobs.
max-paralleldoes not raise this limit.
Summary of when to use each setting
- Keep
fail-fast: truefor fast feedback when any failure blocks the change. - Use
fail-fast: falseto collect the complete set of failing configurations. - Use
max-parallelto protect shared resources or limited runner pools. - Use
continue-on-errorwith a matrix variable to exempt only specific experimental combinations. - Remember that failed and cancelled jobs do not save caches, so failure policy affects how warm your caches stay.
Exercise
A workflow has strategy: { matrix: { os: [ubuntu-latest, windows-latest], node: [18, 20, 22] } } with no other strategy keys. The Ubuntu with Node 18 job fails while the other five jobs are still running. What happens to the other five jobs, and what two changes would let them finish without removing any job from the matrix?
Show answer
Because fail-fast defaults to true, GitHub cancels the five in-progress or queued jobs, and they appear as cancelled. Setting fail-fast: false lets them run to completion, and the run is still marked failed because one job failed. Alternatively, set job-level continue-on-error: ${{ matrix.experimental }} and mark Ubuntu with Node 18 as experimental through include, so its failure does not fail the run or cancel the others. Neither change needs max-parallel, which only limits concurrency.
Exercise
You set max-parallel: 1 on a six-job matrix hoping to cut your Actions bill. Why does this not work, and what is a legitimate reason to use it?
Show answer
max-parallel changes only how many jobs run at once. All six jobs still run, so total billed minutes stay about the same, and the run takes longer. A legitimate reason is protecting a shared resource, such as a staging database or rate-limited service, that cannot handle simultaneous clients, or avoiding exhaustion of a small pool of self-hosted runners.