How can I reduce the time from pull request to merge?

Measure where a pull request waits, then shorten each wait: CI queue and run time, flaky failures and reruns, review, merge queue churn, and post-merge deploy gates. Faster CI shortens every other stage because each push, retry, and merge queue entry runs it again.

Last updated 2026-11-16

To reduce the time from pull request to merge, measure where each pull request waits and fix the largest wait first. Pull request to merge time is the sum of five parts: waiting for CI (queue time plus run time), flaky failures and reruns, waiting for review, merge queue and rebase churn, and post-merge deploy gates. CI is usually the part to fix first, because a pull request runs CI on every push, every retry, and again in the merge queue. Cutting CI time shortens every other stage.

This matters more as coding agents open more pull requests. Each agent-authored change goes through the same CI and the same reviewers, so every minute of CI wait and every flaky rerun is multiplied by the number of pull requests your team produces.

Break pull request to merge time into parts

Before changing anything, record these timestamps for a sample of recent merged pull requests:

StageStartsEnds
CI queue timeA push or pull request event firesThe first job starts running
CI run timeThe first job startsAll required checks report
RerunsA required check failsThe same check passes on a later attempt
Review waitRequired checks pass or review is requestedThe required approvals are in
Merge queue and rebase churnThe pull request is approvedThe commit lands on the default branch
Post-merge deploy gatesThe commit lands on the default branchThe change is running in production

Look at p50 and p95 for each stage, not just the average. A pull request that waits through three CI runs because of one flaky test looks like a review problem in an average, but it's a CI problem.

The sections below cover the fix for each stage.

Cut CI queue time

Queue time is the time between a pull request event and a job actually running. It comes from runner capacity, slow runner provisioning, and accidental serialization in the workflow.

There are two ways to remove capacity queues with Depot, and they're different products:

  • Depot CI runs your GitHub Actions YAML workflows on Depot's own orchestrator and compute. Depot schedules each job, resolves dependencies between jobs, and starts it in a pre-warmed sandbox. The docs list commit to running job in 2-3 seconds.
  • Depot GitHub Actions runners keep GitHub Actions in charge of scheduling and give each job a faster, single-tenant runner. Depot runners have no concurrency limits, so a burst of ready jobs fans out instead of waiting for a fixed pool. Switching is a change to the runs-on label.

Depot CI vs. Depot GitHub Actions runners covers how to choose between them and how to use both in one organization.

Capacity isn't the only source of queue time. A job also waits on a needs dependency, a concurrency group held by another run, or an environment approval. The queue time guide explains how to tell these apart.

Cut CI run time

Once a job is running, run time comes from slow machines, cold caches, and a long critical path of sequential work.

Start jobs with a warm cache. Depot CI includes Depot Cache with no configuration. Depot GitHub Actions runners are integrated into the same cache orchestration system, so actions/cache and other GitHub Actions cache calls use it without workflow changes. Build tools such as Bazel, Go, Turborepo, Nx, sccache, Pants, and Gradle can also use Depot Cache as a remote cache, so only the parts of the codebase that changed are rebuilt and retested.

Use bigger machines for the critical path. Depot CI sandboxes range from 2 CPUs and 8 GB of memory to 64 CPUs and 256 GB on x86_64 and Arm64. Depot GitHub Actions runners come in Linux, macOS, and Windows sizes listed in runner types. Pick the size for the job that finishes last, not every job.

Split slow test suites by timing. Sharding a suite across a matrix only helps if the shards finish at about the same time. Depot splits tests by historical timing from JUnit reports, on both Depot CI and Depot GitHub Actions runners. Each run's reports feed the next split.

Cut setup before adding shards. Every job, shard, and retry pays for checkout, toolchain installs, dependency installs, and service startup again. Sharding shortens the wall clock but multiplies that setup. Use a shallow or sparse checkout, a prebuilt CI image for tools that rarely change, a cache of the installed environment instead of only the downloads, and readiness checks instead of fixed sleeps. Then compare setup time to test time per shard to see whether more shards still help.

Check that your caches still hit. A cache stops working without turning CI red when a cache key or build input changes on every run, such as a timestamp, an absolute path, or an unpinned tool version. Compare the inputs of a run that hit the cache with one that missed. When matrix jobs all compile the same code, build it once and share the output with the shards.

Build container images remotely with a persistent cache. If a pull request builds a Docker image, replacing docker build with depot build runs the build on a remote BuildKit builder with a persistent layer cache shared across your team and CI. In GitHub Actions, use depot/build-push-action, which takes the same inputs as docker/build-push-action.

Two Dockerfile and workflow patterns slow image builds down on every pull request:

  • Recursive chown -R or chmod -R at the end of a stage. It rewrites every file it touches into a new layer. Use COPY --chown, or set ownership in the RUN that creates the files.
  • Several jobs building the same image. If every end-to-end job builds or loads the same test image, build it once in an earlier job and have the other jobs use the result.

Don't pay a penalty for parallelism. Depot CI and Depot GitHub Actions runners both track usage by the second with no one-minute minimum per job, so splitting work into more, shorter jobs doesn't round each one up to a full minute.

Run less CI on every pull request

The fastest CI run is the one that never starts. As agents and bots push more often, runs that don't need to happen take up more of the queue.

  • Don't test the same commit three times. If the full suite runs on the pull request, again in the merge queue, and again on the default branch, run a fast, targeted suite on the pull request and keep the full matrix for the merge queue. The merge queue run is the one that proves the code is safe to merge.
  • Give agent and bot branches a lighter suite. Coding agent branches (such as claude/* or codex/*) and dependency bot branches push often, and bots like Renovate rebase every time something merges. On pull_request workflows, branches filters match the target branch, not the source branch, so select these branches with a job condition on github.head_ref instead. For example, add if: ${{ !startsWith(github.head_ref, 'codex/') && !startsWith(github.head_ref, 'renovate/') }} to the full test job and the opposite condition to a targeted job. Leave the full matrix to the merge queue.
  • Cancel superseded runs. A concurrency group with cancel-in-progress: true stops the run for an old push when a new one arrives.
  • Skip suites a change can't affect. Path filters (on.pull_request.paths) keep docs-only changes from running the full test suite.
  • Watch for fan-out. A workflow that dispatches another workflow per item can turn one commit into hundreds of runs. Compare runs per commit to your normal count.
  • Don't make the merge queue rerun. Anything that writes to the default branch on every merge, such as a timestamp file, changes the base for every queued entry and forces them to test again.

Depot CI supports concurrency, job if conditions with startsWith(), and path filters, as listed in the Depot CI compatibility reference.

Fail fast

A failing run costs the pull request a full CI cycle, and a run that fails slowly costs the most.

  • Set timeout-minutes on every job, at two or three times its normal duration. Without one, a hung GitHub Actions job runs for up to 6 hours. Depot CI supports job and step timeouts.
  • Check cheap preconditions first. If an expensive job depends on credentials, a package mirror, or a network dependency, add a step that checks it in seconds before the slow part starts. A broken credential then fails the run immediately instead of several minutes into it.

Stop paying for flaky failures

A flaky test costs a full CI run each time it fails, plus the time it takes someone to notice and click rerun. On a pull request that also goes through a merge queue, one flaky test can fail the pull request and the queue entry.

Fix it in this order:

  1. Report test results from every run. Add depot/test-report-action after your test step with if: ${{ !cancelled() }}, so failed runs upload their JUnit XML. It works on Depot CI and on Depot GitHub Actions runners.
  2. Find tests that pass and fail on the same commit. The Test Results Analytics page has a Possibly flaky tests card for exactly this, based on Depot CI attempts (analytics for runner jobs are more limited), plus Most frequent test failures and the slowest tests by P95 duration.
  3. Rerun only what failed. In Depot CI, depot ci retry <run-id> --failed retries failed and cancelled jobs and their downstream jobs instead of the whole workflow.
  4. Debug the failing attempt directly. depot ci diagnose --run <run-id> groups failures and returns a diagnosis with the evidence lines behind it. depot ci ssh <run-id> --job test opens a shell in a running sandbox, and depot ci run --workflow .depot/workflows/ci.yml --job test --ssh-after-step <n> pauses the job after step <n> so you can inspect it before the next step runs. See Debug with SSH.
  5. Retry infrastructure steps, not tests. Depot CI supports a retry: key on run: steps. Use it for dependency installs and registry calls that fail on network errors. Retrying a test step hides the flake you need to fix.

The flaky tests guide covers this loop in more detail.

Here's a Depot CI workflow that applies these fixes. It runs on pull requests and merge queue entries, retries only the install step, and uploads test results even when tests fail:

name: CI

on:
  pull_request:
  merge_group:

jobs:
  test:
    runs-on: depot-ubuntu-24.04-8
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
        retry: 3
      - name: Run tests
        run: |
          mkdir -p test-results
          npx vitest run \
            --reporter=default \
            --reporter=junit \
            --outputFile.junit=test-results/junit.xml
      - name: Report tests
        uses: depot/test-report-action@v1
        if: ${{ !cancelled() }}
        with:
          path: test-results/

Shorten review wait

Review wait is the time between a pull request being ready and the required approvals arriving. Faster CI doesn't remove it, but it stops reviewers from waiting on CI before they start.

  • Keep pull requests small. A reviewer can approve a focused change in one pass. Large diffs get deferred.
  • Route reviews automatically. Use a CODEOWNERS file so the right reviewers are requested when the pull request opens, instead of after someone notices it's unassigned.
  • Agree on a review target. A team norm such as "first review within a few working hours" gives reviewers a clear expectation. Track review wait p95 against it.
  • Only request review once checks pass. A reviewer who opens a red pull request either waits or reviews code that is about to change.
  • Validate agent changes before they open a pull request. With Depot CI, a coding agent can run depot ci run --workflow .depot/workflows/ci.yml against its uncommitted changes, read the logs, fix the code, and rerun until CI passes. The pull request arrives green instead of going through several push and fix cycles in front of a reviewer. The coding agents guide sets up that loop.

Reduce merge queue and rebase churn

A merge queue tests each pull request against the latest default branch plus the pull requests ahead of it, which removes "rebase and wait for CI again" from the author's day. It also runs CI one more time for every queued pull request, so queue throughput depends on how fast and how reliable that CI run is.

If you use GitHub's merge queue, workflows need the merge_group trigger so required checks run on queue entries. Depot CI supports on.merge_group merge queue triggers, as listed in the Depot CI compatibility reference. Depot CI reports its jobs as GitHub checks, so you can make them required in your branch protection rules. Set each required Depot CI check's expected source to Any source, as the GitHub checks docs describe. Depot GitHub Actions runners run any GitHub Actions job, including merge_group workflows, with only the runs-on label changed.

To keep the queue moving:

  • Make queue CI fast. Every queue entry pays the full CI time. Everything in the CI sections above applies twice.
  • Fix flaky tests before enabling the queue. A flaky failure ejects the entry and every entry built on it.
  • Run only required checks on merge_group. Slow optional jobs, such as long end-to-end suites that aren't required, can run after merge instead.
  • Avoid long-lived branches. The longer a branch lives, the more conflicts it collects. Merging small changes often keeps rebases trivial.

Shorten post-merge deploy gates

The work isn't done when the pull request merges. If a change waits hours for a deploy window, an approval, or a rebuild, users don't see it.

  • Build once and promote. Build the container image on the pull request or the merge commit, then promote the same image through staging and production instead of rebuilding it. The build once and promote guide shows how.
  • Use a fast image build for the one you can't skip. depot build and depot/build-push-action reuse your team's layer cache, so the build after merge reuses layers from the pull request build.
  • Keep approvals where they add value. Environment protection rules and wait timers are deliberate gates. Keep them for production, and remove the ones that only exist out of habit on lower environments.
  • Deploy automatically after merge. If every merge to the default branch is releasable, a push workflow on that branch can deploy it without a human in the loop.

Keep watching it

Workflows drift. A runner size bumped after an out-of-memory error, a cache key that stopped matching, or a new workflow for bot branches each adds a little time to every pull request, and nobody notices until merges feel slow. Have an agent check your CI on a schedule instead of waiting for complaints. For example:

Every weekday morning, review yesterday's CI for our repositories.

1. For merged pull requests, report p50 and p95 for CI queue time, CI run
   time, reruns, review wait, and merge queue time. Compare to last week.
2. List the workflows and jobs that add the most time to the critical path,
   with one example run link each.
3. Flag commits whose full suite ran more than once (pull request, merge
   queue, default branch) and branches whose runs could use a lighter suite.
4. Flag jobs with no timeout, failures that happen on the same early step
   every time, and tests that fail and pass on the same commit.
5. Flag caches whose hit rate dropped and the input that changed.

Post a short summary. If nothing changed, say so in one line.

Where to start

  1. Measure the five stages on recent merged pull requests and find the largest p95.
  2. If it's CI queue or run time, move your slowest workflow to Depot CI with depot ci migrate, or change its runs-on label to a Depot GitHub Actions runner.
  3. Cut duplicate runs and give agent and bot branches a lighter suite.
  4. Turn on test reporting and fix the tests in Possibly flaky tests before adding a merge queue.
  5. Then work on review norms and deploy gates, which depend on people and policy more than tooling.

Start building with Depot
in minutes