> **Page index:** https://km.oslo.systems/llms.txt lists every page on this site, with a link to its Markdown version.

# Unblock a stuck deployment

Get new deployments running again when an older workflow run is stuck and holds the deploy job's concurrency group.

The golden path deploy jobs run with `cancel-in-progress: false`, so only one deploy per environment runs at a time and later runs wait their turn. If a run gets stuck, every later run waits behind it. This can happen to any deploy job, dev or prod. Most often the cause is a fault at GitHub, not your workflow.

> [!TIP]
>
> **Need help?**
>
> Ask in [`#utviklerflyt-support`](<https://km.oslo.systems/help/contact-us/index.md>) at any point.

## Before you begin

- Write access to the application repository. Methods 4 and 5 need permission to push a branch.
- The [`gh`](<https://km.oslo.systems/set-up-your-machine/gh/index.md>) CLI, logged in with the `repo` scope. Check with `gh auth status`.

## Preface: Find the stuck run

1. Open **your repository \> Actions** and select the deployment workflow.
2. Find the oldest run with status **Waiting**, or a run that has shown the same status for much longer than a deploy takes. Newer runs behind it show **Pending**.
3. Note the run ID from the URL, `https://github.com/OWNER/REPO/actions/runs/RUN_ID`.
4. Note the resolved concurrency group of the stuck job: `dev.concurrencyGroup` or `prod.concurrencyGroup` from `gp-init`. For a single-application repository this is the environment name, for example `pirates-prod`; for a monorepo it includes the app name, for example `pirates-prod-my-app`. Use the actual resolved value rather than constructing it. For prod, it's the same as the GitHub environment name shown on the run.

You can also list waiting runs from the terminal:

repo-app/

```
gh run list --status waiting
```

## End the stuck run

The methods below are ordered by effort. Start with the first one, and stop as soon as the stuck run shows **Cancelled** or completes. Go to the next method only when the current one fails. If you need deployments running right away, go straight to method 5.

| Method | Move on when you see |
| --- | --- |
| [1\. Approve or reject](<#method-1-approve-or-reject>) | No **Review deployments** button, or “There was a problem approving one of the gates” |
| [2\. Cancel in GitHub](<#method-2-cancel-in-github>) | The run doesn't change to **Cancelled** |
| [3\. Force-cancel with the API](<#method-3-force-cancel-with-the-api>) | `409` “Cannot cancel a workflow run that has not been queued yet” |
| [4\. Cancel through the concurrency group](<#method-4-cancel-through-the-concurrency-group>) | The stuck run still shows as waiting a few minutes after the new run started |
| [5\. Bypass the run and contact GitHub](<#method-5-bypass-the-run-and-contact-github>) | Includes a workaround that unblocks deployments |

### Method 1: Approve or reject

This method applies only to jobs with `environment:`, which in the golden path workflows is the prod deploy job. If the run has no **Review deployments** button, try method 2.

1. Open the run and select **Review deployments**.
2. Approve the deployment to let it run, or reject it to end it.

If approving fails with “There was a problem approving one of the gates” or “No pending deployment requests to approve or reject”, the run is stuck at GitHub. Try method 2.

### Method 2: Cancel in GitHub

Open the run and select **Cancel workflow**. If the status doesn't change to **Cancelled** within a minute, try method 3.

### Method 3: Force-cancel with the API

Force-cancel skips the checks a normal cancel waits for. Use the run ID, not a job ID. A job ID gives `404 Not Found`.

```
gh api -X POST repos/OWNER/REPO/actions/runs/RUN_ID/force-cancel
```

If GitHub returns `409` “Cannot cancel a workflow run that has not been queued yet”, the run is missing an internal record, which a fault at GitHub can cause. Cancel, approve and reject all depend on that record, so none of them work. Try method 4.

### Method 4: Cancel through the concurrency group

A new run in the same concurrency group with `cancel-in-progress: true` cancels the job that holds the group. This cancel doesn't depend on the record that the stuck run is missing.

> [!WARNING]
>
> **Check that no other deploy is running in the group**
>
> `cancel-in-progress: true` cancels whatever holds the group. If a healthy deploy holds it instead of the stuck run, you cancel that deploy partway through.

1. Create a branch named `release-concurrency-group`.
2. Add this workflow to the branch. Replace `pirates-prod-my-app` with the group name from step 4 of the preface. For a single-application repository, that's the environment name, for example `pirates-prod`.

repo-app/.github/workflows/release-concurrency-group.yml

```
name: Release concurrency group
on:
  push:
    branches: [release-concurrency-group]
jobs:
  release:
    runs-on: ubuntu-latest
    concurrency:
      group: pirates-prod-my-app # (1)!
      cancel-in-progress: true
    steps:
      - run: echo "Released the concurrency group"
```

1. Must match the stuck job's group exactly. Don't add an `environment:` key, or this job waits for review too.
2. Push the branch. The push starts the run.
3. Within a minute, check that the stuck run shows **Cancelled**, and that the new run succeeds.
4. Delete the branch.

If the stuck run still shows as waiting a few minutes later, cancel the new run and try method 5.

### Method 5: Bypass the run and contact GitHub

This method doesn't end the stuck run. It gives the deploy job a temporary group name so new deployments can run, while GitHub removes the stuck run.

1. Add a suffix to the `group` of the stuck deploy job. Change only `concurrency.group`. Leave `environment.name` unchanged, because the AWS role trusts the environment name.

repo-app/.github/workflows/my-app\_deployment.yml

```
deploy-prod:
  concurrency:
    # TEMP: run RUN_ID is stuck at GitHub and holds the original group. Revert when GitHub removes it.
    group: ${{ fromJSON(needs.gp-init.outputs.config).prod.concurrencyGroup }}-tmp
    cancel-in-progress: false
  environment:
    name: ${{ fromJSON(needs.gp-init.outputs.config).prod.concurrencyGroup }}
```

1. Before starting deployments in the temporary group, pause new deployments and cancel superseded runs that still use the original group, including runs that haven't reached the deploy job yet. Confirm that no deploy other than the stuck job remains active or queued in the original group.
2. Merge the change, resume deployments with the temporary group, and start a new deployment.
3. [Contact GitHub Support](<https://support.github.com/contact>). Select **Oslo kommune** under **Organization**, then **Actions \> Stuck workflow**. Include the run URL, the methods you tried and the error messages you got.
4. When GitHub has removed the stuck run, pause new deployments again. Let active deployments in `-tmp` finish and cancel remaining runs that use that group, including runs that haven't reached the deploy job yet. Then remove the `-tmp` suffix and resume deployments.

> [!NOTE]
>
> **Waiting runs expire after 30 days**
>
> A run waiting for an environment review ends on its own after 30 days, which also frees the group.

## Verify

Start a new deployment, or push to `main`. Check that it starts without waiting behind another run:

repo-app/

```
gh run list --workflow my-app_deployment.yml --limit 3
```

The latest run should show `in_progress` or `completed`, not `waiting` or `pending`.
