Daniel Doubrovkine bio photo

Daniel Doubrovkine

aka dB., @Microsoft, ex-@ShopifyEng, @OpenSearchProj, @awscloud, former CTO @artsy, +@vestris, NYC

Email Twitter LinkedIn Github Strava
Creative Commons License

A blog post about work-stealing for CI caught my attention. Instead of splitting the tests into shards before the jobs start, put every test file in one queue and let each worker take a batch, then another, until the queue is empty. A fast worker takes more batches, a slow one takes fewer, and nobody waits for the unluckiest shard. Their specbandit implementation keeps that queue in Redis, which every worker must be able to reach. This didn’t seem possible on GitHub-hosted runners without running a database somewhere else since GitHub Actions jobs can’t reach each other, runners accept no inbound connections, and a job’s outputs only become visible after it ends.

Where there’s a will, there’s a way. We just need a TCP tunnel that can be shared. Here’s how it works.

A coordinator job runs Valkey and opens a Pinggy TCP tunnel, uploads the tunnel's address as a workflow artifact, and the workers download it, connect through the tunnel with an OIDC token, and steal batches.

A first job of the workflow starts Valkey in a container and exposes it through a free Pinggy TCP tunnel. It uploads the tunnel’s address as a workflow artifact, and the worker jobs download it, prove with a GitHub OIDC token that they belong to the same run, and steal work until the queue is empty. The queue lives exactly as long as the workflow, and there’s nothing to host, pay for, or secure. I packaged it into bored-ci.

Demo

On Posebook’s 1,253 examples across eight workers, bored-ci finished the whole workflow in a median of 133 seconds, 2.3× faster than parallel_tests-ci (304 seconds) and 3.8× faster than running the specs serially (504 seconds).

Posebook on eight workers, median of three runs: parallel_tests-ci, slowest worker 85.17s of RSpec and 304s of workflow; bored-ci, 67.84s and 133s.

The tests themselves aren’t much faster. The gain is in everything around them: in one parallel_tests-ci run, two shards took about 6 minutes each to run 1 minute of specs because their runners were slow to set up. With a queue, a slow runner just takes fewer batches.

How to Use It

Add a coordinator job and a matrix of workers to .github/workflows/test.yml:

name: Test
on: [push, pull_request]

permissions:
  contents: read
  id-token: write

jobs:
  coordinator:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dblock/bored-ci/coordinator@v0
        with:
          list: find spec -name '*_spec.rb'
          workers: 8

  worker:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        worker: [1, 2, 3, 4, 5, 6, 7, 8]
    steps:
      - uses: actions/checkout@v7
      - uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - uses: dblock/bored-ci/worker@v0
        with:
          run: bundle exec rspec

What It Does

  • Batches shrink as the queue empties so the workers finish together, or, with batch: time, are sized by how long each file took before.
  • Timings are saved in the Actions cache, and later runs restore those of their branch, then of the pull request’s base, then of the default branch, and put the slowest files first.
  • Failed tests can be retried one at a time, and those that then pass are reported as flaky.
  • The tasks of a worker that dies go back to the queue.
  • serve: rspec and serve: minitest load the app once per worker instead of once per batch.
  • There are recipes for RSpec, Minitest, Jest, pytest, and Go.
  • The tunnel can be Pinggy or your own bore server.
  • The CLI writes the workflow with npx bored-ci init, previews how the workers would split the tests with list, runs the whole thing on your machine with run, and summarizes a workflow run with status.

It’s easy to adapt bored-ci to other frameworks. The list command prints one task per line and run gets a batch of them as arguments, so anything that can run a list of files works, and a runner that should start only once can speak the small serve protocol, which reads each batch on standard input and replies with the failed tasks.