# Promote and roll back

> Moving an environment to another deploy: instantly, with a health check, gradually, or backwards.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://run.docs.sypnia.com/deploys/promote-and-rollback/

For agents: Promote and rollback in Run: run promote <deploy> --env, run rollback [--to <deploy>]; target must be ready (built, resources created, health check); edge mapping switched in seconds; in-flight requests finish on old deploy; releases recorded with reason; gradual releases (--gradual 10%, sticky per visitor, promote --continue) with Telemetry comparison; auto_rollback watches error rate 10 min; rollbacks do not undo migrations, stored files or sent e-mails.

Releasing never rebuilds anything: it changes which deploy an environment points to.

## Commands

```bash
npx @sypnia/run promote dpl_7h3k --env production   # send production to this deploy
npx @sypnia/run rollback                            # production back to the deploy before the current one
npx @sypnia/run rollback --to dpl_5a1q              # to a specific deploy
```

## How a release happens

1. The target deploy must be `ready`: built, with its resources created, and answering its health check at its own address.
2. The edge router's mapping for the environment changes to the target deploy. CloudFront applies it within seconds worldwide.
3. Requests already in progress finish on the deploy that started them.
4. The release is recorded: who, when, from which deploy to which, and why (`--reason`).

## Gradual releases

`--gradual 10%` sends a share of new visitors to the new deploy and keeps the rest on the old one, sticky per visitor. `run promote --continue` moves the rest; `run rollback` sends everyone back. While a gradual release is on, Sypnia Telemetry compares errors and latency of both deploys.

## Automatic rollback

With `release.auto_rollback` on, Run watches the new deploy's error rate for ten minutes after the release, through Sypnia Telemetry or the platform's own logs, and moves production back if it rises past the threshold you set. The rollback is recorded and you are notified.

## What a rollback does not undo

Database migrations, files written to storage and e-mails sent are outside the deploy. Keep migrations backward compatible for one release, so the previous deploy still works with the new schema.
