DEV Community

Mohamed Gado
Mohamed Gado

Posted on Originally published at mohamedgado.com

Why GitHub shows a red X on commits whose deploys succeeded: cancel-in-progress

A GitHub Actions run cancelled by concurrency: cancel-in-progress: true puts a red X on its commit, the same mark a failed run gets. For three days most commits on my site's main branch showed that X, and none of the deploys had failed. Every Cloudflare build in that window succeeded (30 of 30). The X came from deploy runs that were "cancelled after 1s". The fix was to keep the debounce and stop cancelling runs: a run that has been superseded exits with code 0 and shows green.

Does a cancelled GitHub Actions run count as a failure?

On the commit, yes. The checks icon next to a commit in the commit list rolls every check run for that SHA into one mark. A cancelled conclusion is not success, so the roll-up is a red X, and from the commit list you can't tell it apart from a broken build. You have to open the run to see the word "cancelled".

That matters if anyone reads the commit list as a health signal, and I do. A wall of red X's on a site that was deploying fine is noise that hides a real failure the day one happens.

The workflow that produced it

My site deploys through one GitHub Actions workflow that calls a Cloudflare Workers Builds deploy hook. I push in bursts (five commits in ten minutes is normal), and I didn't want five builds. So the workflow waited three minutes and relied on concurrency to drop the waiting runs when a newer push arrived:

concurrency:
  group: production
  cancel-in-progress: true

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      DEBOUNCE_SECONDS: 180
      HOOK: ${{ secrets.CF_DEPLOY_HOOK }}
    steps:
      - name: Wait for the push burst to settle
        run: sleep "$DEBOUNCE_SECONDS"
      - name: Trigger the Cloudflare Workers Builds deploy hook for main
        run: curl -fsS -X POST "$HOOK"
Enter fullscreen mode Exit fullscreen mode

The debounce worked: a burst became one deploy. But every commit in the burst except the last one got a cancelled run, and with it a red X.

A habit made it worse. To skip the three-minute wait, sessions ran gh workflow run deploy.yml right after a push. The dispatched run joined the same concurrency group and cancelled the push run in the same second. The dispatch run deployed fine, but it doesn't show on the commit, so the only check left on the commit was the cancelled one.

How I traced it

I checked the layers in order, from the symptom toward the deploy:

  1. Actions run conclusions for the deploy workflow: no failure at all, only cancelled and success.
  2. Cloudflare's builds API: every build in the window succeeded.
  3. Pairing timestamps: each cancelled push run had a workflow_dispatch run that started in the same second, or a newer push run.

So the red X's didn't come from any failure. The workflow's own design created them.

The fix: debounce without cancelling

The run still waits, but it no longer depends on being cancelled. After the wait it asks GitHub which commit main points at. If that is not its own commit, a newer push has arrived and that push's run will deploy, so this run exits 0:

jobs:
  deploy:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    env:
      DEBOUNCE_SECONDS: ${{ github.event_name == 'workflow_dispatch' && 0 || 180 }}
      HOOK: ${{ secrets.CF_DEPLOY_HOOK }}
      GH_TOKEN: ${{ github.token }}
    steps:
      - name: Wait for the push burst to settle
        run: sleep "$DEBOUNCE_SECONDS"
      - name: Trigger the Cloudflare Workers Builds deploy hook for main
        run: |
          if [ "$GITHUB_EVENT_NAME" = "push" ]; then
            HEAD=$(gh api "repos/$GITHUB_REPOSITORY/commits/main" --jq .sha)
            if [ "$HEAD" != "$GITHUB_SHA" ]; then
              echo "::notice::Superseded: main is at ${HEAD:0:7}, its own run deploys it."
              exit 0
            fi
          fi
          curl -fsS -X POST "$HOOK"
Enter fullscreen mode Exit fullscreen mode

The concurrency block is gone. Three things changed:

  • A superseded run is green. It ends with a notice that names the newer commit, so the run log still explains why it didn't deploy.
  • Only the head deploys. Only one SHA can be the head of main, so a burst still collapses into one deploy: the run for the last push.
  • A manual dispatch skips the wait. DEBOUNCE_SECONDS is 0 for workflow_dispatch, so nobody has a reason to dispatch right after a push. After a push, you wait about four minutes and the push run deploys.

gh is preinstalled on GitHub-hosted runners and reads GH_TOKEN, and the default github.token with contents: read can read the commit. No extra secret is needed.

The cost

The wait is billed Actions time. On a private repo that is about four minutes per push, out of the 2,000 free minutes a month. cancel-in-progress hid that cost because cancelled runs stop early. If minutes get tight, lower DEBOUNCE_SECONDS. You get less collapsing, and the commits stay green.

Pin it with a test

A workflow file is easy to "simplify" back into the old shape, because cancel-in-progress looks like the obvious tool for this. A test that reads the YAML keeps it from coming back:

test('bursts become one deploy without cancelling: a superseded run exits green', () => {
  assert.doesNotMatch(workflow, /cancel-in-progress:\s*true/)
  assert.match(workflow, /commits\/main/)
  assert.match(workflow, /"\$HEAD" != "\$GITHUB_SHA"[\s\S]*exit 0/)
})

test('a manual dispatch deploys at once, so nobody dispatches to skip the wait', () => {
  assert.match(workflow, /github\.event_name == 'workflow_dispatch' && 0 \|\| \d+/)
})
Enter fullscreen mode Exit fullscreen mode

When cancel-in-progress is still right

For pull request checks, cancel-in-progress is a good default: nobody cares about a cancelled lint run on a commit that a newer push replaced, and it saves minutes. The trouble starts on a branch where people read the commit list as a deploy log. There, a cancelled run looks like a failed one, and a debounce that exits 0 gives you the same single deploy with a commit list that stays green.

Takeaways

  • A cancelled run shows as a red X on its commit. If commit checks are your health signal, don't let runs be cancelled routinely.
  • Debounce by waiting and then checking whether your commit is still the head of the branch, not by cancelling.
  • Before you chase a red X, open the run. "Cancelled after 1s" means a concurrency group cancelled it, not that a build broke.

Top comments (0)