# How to cancel a stuck deployment without taking your app offline

Gregale · Updated 2026-12-05

Cancel an in-flight Gregale deployment by ID, verify the previous release still has traffic, and know when to abort or roll back instead.

If a Gregale deployment is stuck before it goes live, cancel the **candidate deployment ID**, not the app or its serving revision. Use `gregale release cancel DEPLOYMENT_ID --app APP`. Check traffic before and after: if the previous revision is at 100%, it should stay there. If the candidate is already live, cancellation is the wrong control, even when it has 0% traffic.

| What Gregale shows                                                                    | What to do                                                                                                                                                    |
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Your terminal timed out, but the deployment is still progressing                      | [Reconnect to the same deployment](https://gregale.dev/articles/resume-deployment-after-cli-timeout) with `gregale release wait`. A disconnected waiter does not stop the build. |
| The candidate is pending, building, imaging, or snapshotting, and you want to stop it | Cancel its exact deployment ID. Do not delete or restart the app.                                                                                             |
| The candidate is live at 0% and no rollout is active                                  | Leave it at 0% and do not promote it. A ready revision is still live even if it is not serving ordinary requests.                                             |
| An active canary is rolling out                                                       | [Abort the rollout](https://gregale.dev/docs/rollouts.md) and confirm traffic returned to the intended predecessor.                                                                 |
| A bad release has already taken over traffic                                          | Roll back to a verified previous revision. If the candidate is already failed or cancelled, inspect that terminal result instead of cancelling again.         |

## Check the candidate and the serving revision

Use the same workspace and app as the original deploy. Read the exact ID from the deploy receipt, not from the top of the release list. A newer deployment may have appeared while you were looking.

```bash
g() { gregale --non-interactive --json "$@"; }

g release get "$CANDIDATE" | jq '{id, status, rollout_state, traffic_percent}'
gregale release traffic status "$APP"
```

If the candidate is still in progress, cancel it:

```bash
gregale release cancel "$CANDIDATE" --app "$APP"
g release get "$CANDIDATE" | jq -e --arg id "$CANDIDATE" '
  .id == $id and .status == "cancelled"'
gregale release traffic status "$APP"
```

The deployment can become live between inspection and cancellation. If Gregale returns `deployment_cancel_live_forbidden` or `deployment_cancel_not_cancellable`, re-read the same ID and check traffic again. Do not substitute a different ID. A timed-out cancel call also calls for a fresh status check, not an assumption that the request failed.

For an active canary, first identify the candidate and the predecessor from the rollout, then use the guarded abort:

```bash
gregale rollouts recover "$APP" --action abort \
  --deployment "$CANDIDATE" --expected-predecessor "$PREVIOUS" \
  --reason "stop candidate rollout"
```

For a completed rollout, confirm the known-good release is still available and the bad candidate is the current serving release. Pin both IDs so a newer release cannot be rolled back by mistake:

```bash
gregale rollback "$APP" --to "$PREVIOUS" --expected-current "$CANDIDATE" --wait
```

If the current release has changed, stop and reassess traffic rather than automatically retrying against the new release. After either action, check traffic in the intended environment and exercise a meaningful route on the normal app URL if you can access it. A single successful response does not rule out split traffic.

Neither cancellation nor traffic rollback reverses changes already committed to a database, queue, object store, or external API. If a release command or migration ran, check its effects separately before retrying.

## Rehearse on a disposable app

[Download the starter](https://gregale.dev/examples/cancel-stuck-deployment.zip). It contains two tiny Docker builds. The baseline serves `{"revision":"baseline"}` at `/version`. The candidate returns a different marker and has a bounded build delay so there is time to cancel. Use Bash, `curl`, `jq`, OpenSSL, the [Gregale CLI](https://gregale.dev/docs/install.md), and an exported `FAAS_TOKEN` for a test workspace with app-create and deploy access. The guard creates a new internal app and refuses an existing slug.

Run this from the extracted starter directory:

```bash
set -euo pipefail
export GREGALE_TOKEN="$FAAS_TOKEN"
export GREGALE_API_URL=https://api.gregale.dev FAAS_API=https://api.gregale.dev
APP="demo-cancel-$(openssl rand -hex 8)"
bash create-app.sh "$APP" >/dev/null
g() { gregale --non-interactive --json "$@"; }

BASELINE="$(cd baseline && g deploy --name "$APP" --source=worktree --no-wait --yes |
  jq -er '.id')"
g release wait "$BASELINE" --app "$APP" --timeout 5m |
  jq -e --arg id "$BASELINE" '.id == $id and .status == "live"'

verify_baseline() {
  g release verify "$BASELINE" --app "$APP" --path /version |
    jq -e --arg id "$BASELINE" '
      .verified and .deployment_id == $id and .http_status == 200
      and (.body | fromjson) == {revision: "baseline"}'
}
verify_baseline
bash verify-traffic.sh "$APP" "$BASELINE"
```

Continue only if the traffic check passes. Submit and cancel the candidate in the same shell. The `--no-wait` flag returns a receipt without waiting for readiness; `--no-traffic` keeps a candidate from replacing the baseline if it happens to finish first.

```bash
CANDIDATE="$(cd candidate && g deploy --name "$APP" --source=worktree \
  --no-traffic --no-wait --yes | jq -er '.id')"
test "$CANDIDATE" != "$BASELINE"
g release get "$CANDIDATE" | jq -e --arg id "$CANDIDATE" '
  .id == $id and (.status | IN("pending", "building", "imaging", "snapshotting"))'
gregale release cancel "$CANDIDATE" --app "$APP"
g release get "$CANDIDATE" | jq -e --arg id "$CANDIDATE" '
  .id == $id and .status == "cancelled"'

bash verify-traffic.sh "$APP" "$BASELINE"
verify_baseline
```

The two checks answer different questions: the traffic check requires exactly 100% on the original release and no traffic on any other live release in this single-environment drill, and the owner-authorized probe should return the original marker from that exact release. The probe does not test the public app URL, custom domains, or uninterrupted availability between samples. On a customer-facing app, [verify the stable URL separately](https://gregale.dev/articles/verify-production-deployment). Delete only the disposable app you created when you finish.

## What we verified on Gregale

We ran both Docker builds from this starter on one disposable internal app. The baseline
owned 100% of traffic before the second deployment. We cancelled the exact
candidate ID while it was building and observed its terminal `cancelled`
state. The traffic listing still gave the baseline 100%, and an
owner-authorized request to the exact baseline revision returned HTTP 200 and
the same `{"revision":"baseline"}` response as before.

The candidate was submitted with `--no-traffic` for this drill. The downloadable traffic assertion was added afterward and tested against representative CLI output. The hosted test
did not measure continuous availability, probe a public hostname, or test a
canary abort or rollback.

## Questions

### Can I cancel a deployment without stopping my app?

Use gregale release cancel with the exact pending, building, imaging, or snapshotting deployment ID. Check that the previous release still holds its traffic allocation after cancellation.

### Can I cancel a live deployment at 0% traffic?

No. Live means the release is ready, not necessarily receiving normal requests. Leave a staged release at 0%, abort an active canary, or roll back a completed rollout.

### Does cancelling a deployment undo database migrations?

No. Cancellation or traffic rollback does not undo changes already committed to a database or external service. Check those effects separately before retrying.

Canonical URL: https://gregale.dev/articles/cancel-stuck-deployment

