DEV Community

kanta13jp1
kanta13jp1

Posted on

Why GitHub Actions Concurrency Drops Your Third Queued Run (And How to Dispatch Serially)

One running slot and one pending slot

When developers automate deployments or batch publishing with GitHub Actions workflow_dispatch, adding a shared concurrency group looks like an easy way to prevent race conditions. A common assumption is that setting cancel-in-progress: false turns the concurrency group into an unbounded FIFO queue where every triggered run waits politely for its turn. In practice, GitHub Actions maintains at most one active run and one pending run per concurrency group.

If job #1 is currently executing and you fire jobs #2, #3, and #4 in rapid succession with different payload inputs, job #3 cancels pending job #2, and job #4 cancels pending job #3. Only job #1 and the final dispatch ever execute to completion. The middle payloads vanish with a cancelled state before running a single step. For CI checks tied only to the latest commit, superseding stale commits is desirable. For parameterized batch workflows where every dispatch carries a distinct document or migration target, silent middle-run cancellation causes missing outputs that are tedious to audit later.

Building a deterministic serial dispatcher

When every parameterized dispatch must execute without modifying the underlying workflow concurrency policy, move the queue responsibility to the caller. Before triggering gh workflow run, snapshot the recent run IDs for that workflow. Dispatch one item, wait until a previously unseen databaseId appears, and poll that single run until status equals completed and conclusion equals success. Only then advance to the next item in your list.

In practice, waiting 20 to 30 seconds per lightweight workflow run finishes a 13-item batch in roughly five to six minutes with zero cancelled items and deterministic console output. Compared to dumping 13 dispatches concurrently and spending twenty minutes cross-checking which 11 runs got dropped, serial client-side dispatch is both faster end-to-end and trivial to trace.

Pair serial orchestration with idempotency keys

A serial dispatcher prevents concurrency-group drops, while idempotent workers protect against client interruptions. Derive a deterministic slug or content hash per item before calling the remote API or database insert. If your local runner times out on item nine, re-running the full batch checks existing records first, skips items one through eight cleanly, and publishes only the remaining work. Separating single-run concurrency safety on the server from ordered queue execution on the client keeps parameterized automation reliable under burst loads.

Top comments (1)

Collapse
 
hritik_chaudhary_5db0056f profile image
Hritik Chaudhary •

Worth adding that this is documented behaviour: a concurrency group holds one running and one pending run, and a new pending run replaces the old one. cancel-in-progress only changes what happens to the running one.

Two ways to keep the order without much caller-side code. One: pass the whole list as a single input and run it as a matrix with max-parallel: 1 and fail-fast: false, so one bad item does not skip the rest. Two: keep your polling loop but set run-name from an input (run-name: batch-${{ inputs.slug }}) and match on that name instead of the first unseen databaseId. If someone else dispatches the same workflow while your loop is waiting, the unseen-ID trick can latch onto their run.