Dispatch ↔ Deploy FIFO cross-wait deadlock: dispatches block deploys, deploys block dispatches #8
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
queue
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
romaine-life/pipeline-templates#8
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Observed today
In the
apirepo, 3 dispatches and 2 deploys were all stuck for 30+ minutes — every one of them stalled in its wait-step, none making progress. Had to kill all of them and re-run the chain manually.State at the time (run ids are api/main):
Why it deadlocks
Each side's FIFO guard counts the other side as blocking, symmetrically:
dispatch.yml/fifo-wait:deploy.yml/wait-for-dispatches:Both sides treat the other as "anything in progress blocks me". Neither uses ordering. So once a deploy and a dispatch are both in progress, each one's guard stays true forever.
Minimal repro
repository_dispatchat the api.workflow_runtriggers the Deploy workflow.Wait for Dispatches, a second host publishes a package → new dispatch fires.Any concurrent dispatch+deploy at the same time hits this — doesn't even need a third event; the first two are enough if neither clears on its own.
Fix options
1. Symmetric ordering: deploys only wait for dispatches with an earlier
databaseId(recommended)databaseIdis a monotonic global counter across GH Actions runs in a repo, so the ordering is total. Change the deploy guard to:Now a deploy only waits on dispatches that started before it; dispatches still wait on earlier dispatches + all deploys. The cycle can't form because at most one side blocks the other in any given temporal order.
Counter-check: if the deploy runs first and a dispatch starts later, the deploy doesn't wait, finishes, and the dispatch proceeds. If the dispatch starts first, the deploy waits, the dispatch finishes, and the deploy proceeds. Either way acyclic.
Pros: one-line change, preserves intent (deploys serialize behind ongoing dispatches).
Cons: a deploy that started a second before a dispatch will jump ahead of it — but that matches real-world ordering already, since the deploy's underlying Phase 1 build preceded the dispatch trigger anyway.
2. Single queue via GH Actions concurrency groups
Replace both custom wait loops with
concurrency: group: api-deploy, cancel-in-progress: false. The downside: cancel-in-progress=false queues serially but doesn't give any visibility;cancel-in-progress=truewould kill running work. And deploys-triggered-by-workflow_run and dispatches would need the same group key to actually serialize together.3. Fold deploy.yml into dispatch.yml
Have the
workflow_run-triggered path call the same job chain via workflow_call. One queue, one wait. Bigger change but removes the duplication entirely.Recommendation
Option 1. One-line edit to
deploy.yml(and whichever shared template hosts it). Consider also changing the dispatch'sDEPLOYScount to use the same ordering — today it blocks on any deploy even if the deploy started after it, which is correct today but worth auditing.Notes
api/package.json+ lockfile to the latest published versions (the stuck dispatches were trying to do this but never got past their wait step), push a commit, let the single fresh Phase 1 build → Deploy chain run alone.Interim state: automated triggers disabled in api (commit api@67cffff). Running Claude-driven CI — deploys + dispatches fire via workflow_dispatch only until this is redesigned.
Revisit plan: replace both custom wait loops with native GH Actions concurrency groups. 4 lines total, two of which we already use for tofu:
```yaml
api/.github/workflows/tofu.yml already has this pattern:
concurrency:
group: tofu-${{ github.ref }}
cancel-in-progress: false
```
Same block with `group: api-deploy` in both deploy.yml and dispatch.yml gives a single queue across the two workflows — no custom wait scripts, no emergent deadlock. Likely lands with the AKS migration work in api#14 since we'll be rewriting deploys anyway.
Root-cause retrospective worth noting for posterity: the custom wait scripts were solving a problem the platform already solved. Two workflows each using "any in-progress run of the other kind" as a veto forms an emergent cycle; a concurrency group is a proper mutex and can't deadlock. Somewhere along the way we optimized for queue-position log visibility and cross-workflow coordination and walked past the native primitive that was already in the adjacent file.