
# The life of a release

Every `agc ship` takes the same path: build, rehearse on a copy of production when there's something to check, ask a person if needed, switch traffic. Nothing in production changes before the migrate step. Shipped means exit 0 with `"outcome": "live"`.

```bash
agc ship
```

## Ask your agent

```text
Ship the change you just made, and tell me the outcome and the receipt link.
```

You'll hear "live" with a receipt link, or get an approval link to open if the release could lose data.

## How it works

```mermaid
flowchart LR
  A[agc ship: snapshot] --> B[building]
  B --> C[rehearsing on a fresh branch of production]
  C -->|a check fails| F[failed, production untouched]
  C --> D[deciding]
  D -->|needs a person| W[waiting_approval]
  W -->|approved| M[migrating]
  D -->|no person needed| M
  M --> R[releasing]
  R --> L[live + receipt]
```

Snapshot, build, rehearse, decide, then migrate and switch traffic. Any failure before migrating stops the release with production unchanged.

`agc ship` prints each stage as it goes:

| Stage (`data.state`) | What happens |
|---|---|
| snapshot (local) | agc packs the working tree (tracked and untracked files selected by Git, minus snapshot exclusions, never `.env*`) into a tar.gz named by its sha256 and uploads it. Over 64 MiB compressed fails locally with `ship.too_large` |
| `building` | Agent Cloud builds the image from the app's Dockerfile, or a detected Node or Python build. From here on the release is addressed by the image's digest |
| `rehearsing` | Agent Cloud forks a fresh, unmasked branch of production, applies the pending migrations and proves no existing row disappeared. Then it starts the new image against the branch and runs the smoke flows and invariants. An app with a worker is rehearsed twice: once calm, once while Agent Cloud kills the worker mid-job. The branch is dropped before anyone is asked |
| `deciding` | Agent Cloud decides whether a person must approve: a migration that drops or empties data, a removed or changed held check, a sign-in change, a removed worker, or any release under `watch` autonomy. Under `routine`, everything else goes on by itself |
| `previewed` | Only for the first release of an app nobody has claimed: it runs privately at the app's address until a person publishes it from the publish link |
| `waiting_approval` | A person approves at `/a/<id>` or, when the agent can ask in its session, by replying with the decision word. The approval expires after 24 hours |
| `migrating` | The pending migrations run on production, each in its own transaction |
| `releasing` | The new version starts; once it answers healthy, traffic switches and the public address is checked for the new release (`x-agc-release`). If that fails, the old route stays |
| `live` | Agent Cloud records the release and its receipt, updates held checks, and pushes the release as one commit to the app's GitHub repo |

**Rehearse first, then ask.** A release with checks, migrations or a worker is rehearsed before the decision. So a person only ever approves a release whose checks passed, and a failed rehearsal asks nobody. If another release goes live while one waits for approval, the waiting one is rehearsed again against the new production; if that fails, its outcome is `failed`.

**What the agent sees from a rehearsal.** Pass or fail per check, with its name and a fixed sentence: never rows, counts or response bodies, because the rehearsal runs on real data. To see why an invariant failed, run `agc check` on the mirror, whose data is masked.

**One release at a time.** A ship while another is building or rehearsing fails with `ship.locked`. A ship waiting for approval holds no lock: a ship of a different snapshot replaces it, and the waiting one fails with `ship.superseded`. An approval nobody decides within 24 hours fails with `ship.approval_expired`.

**The first ship** has no production data to fork, so the rehearsal runs on an empty database with the migrations applied. Once it passes, the release goes live on its own and records the default monthly budget (25) and `routine` autonomy, which a person changes later. It asks a person only under `watch` autonomy, on an organization's own AWS target, or for a data-losing migration after an import. For an app nobody has claimed yet, it ends at a private preview instead: exit 10, `"outcome": "preview"`, with `data.preview_url` and `data.publish_url`. Publishing signs the person up and puts that release live, and `agc wait <op>` then answers `live`.

## Reference

Exit codes `agc ship` returns:

| Exit | Outcome | Meaning |
|---|---|---|
| 0 | `live` | Shipped. Report the receipt |
| 1 | `failed` | Build, start or platform failure. `error.fix` says what to change |
| 10 | `waiting_approval` | A person must decide. `data.approval.url` is the link |
| 10 | `preview` | An unclaimed app's first release is running privately. Relay `data.relay`, then `agc wait <op>` |
| 11 | `failed` | A check failed in rehearsal (`ship.check_failed`) |
| 12 | `denied` | A person declined, or policy refused |
| 20 | (still running) | With `--no-wait` or after the follow timeout; resume with `agc wait <op>` |

## Errors

| `code` | Exit | Cause | Fix |
|---|---|---|---|
| `ship.check_failed` | 11 | An invariant or smoke flow failed on the branch of production | Run `agc check` on the mirror, fix the change, ship again |
| `ship.approval_required` | 10 | The release needs a person | Relay the link, or ask in session when `decision.in_session` is true |
| `ship.preview` | 10 | An unclaimed app's release is at its private preview; this is the expected first ship | Relay the preview and publish links word for word, then `agc wait <op>` |
| `ship.superseded` | 1 | A newer ship replaced this one while it waited | Follow the newer ship |
| `ship.approval_expired` | 1 | Nobody decided within 24 hours | Ship again; a new release asks again |
| `ship.too_large` | 1 | The snapshot is over 64 MiB compressed or 320 MiB raw | Ignore build outputs, or declare large inputs as `[[asset]]` |

A failed rehearsal, as the agent receives it:

```json
{
  "ok": false,
  "product": "agent.cloud",
  "command": "ship",
  "op": "op_…",
  "env": "prod",
  "outcome": "failed",
  "data": { "op": "op_…", "app": "camp-bookings", "version": "v4", "state": "failed", "release_url": "…", "checks": [ { "name": "never overbooked", "kind": "invariant", "ok": false, "detail": "…" } ] },
  "error": { "code": "ship.check_failed", "message": "…", "fix": "…", "retryable": false },
  "next": [
    { "cmd": "agc check", "why": "reproduce it on your mirror" },
    { "cmd": "agc ship", "why": "ship again once fixed" }
  ]
}
```

## Limits

| What | Limit |
|---|---|
| Snapshot | 64 MiB compressed, 320 MiB uncompressed |
| Approval lifetime | 24 hours |
| Releases in flight per app | 1 (a waiting approval doesn't count) |

## Agent notes

- Only a live release has a receipt. Every ship's answer, failed ones included, carries `data.release_url`, the release's page in the console; check for exit 0 and `"outcome": "live"`.
- `agc receipt <id>` shows an operation's receipt again, by its op id or its release record's id. It changes nothing.
- Every release migrates first, then switches traffic, so write migrations the old code survives (expand, migrate, contract in separate ships). To undo a release, ship a fix.
- Running the same `agc ship` again on unchanged code returns the same operation (`repeated: true`), not a second release. To ship identical code after a failure, change it or pass a new `--idempotency-key`.
- If your tool calls time out, use `agc ship --no-wait` (exit 20) and then `agc wait <op>`.

## Related

- [`agc ship`, end to end](/docs/ship/agc-ship-end-to-end.md)
- [Rehearsals](/docs/concepts/rehearsals.md)
- [Approvals](/docs/concepts/approvals.md)
- [Outcomes and receipts](/docs/concepts/operations-and-waiting.md#outcomes-and-receipts)
- [Safe schema changes](/docs/data/safe-schema-changes.md)

<!-- feedback:start -->
---
Wrong, outdated or unclear? Run `agc feedback docs "getting-started/the-life-of-a-release: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
