
# Operations and waiting

A ship is an operation: an `op_…` id that runs on Agent Cloud whether or not your session stays connected. It succeeded only when agc exits 0 with `"outcome": "live"`, the one result with a receipt. `agc wait <op>` re-attaches to it from any machine or session.

```bash
agc ship --no-wait
agc wait op_3f2a1c9b04
```

```json
{
  "ok": true,
  "product": "agent.cloud",
  "command": "ship",
  "data": { "op": "op_3f2a1c9b04", "app": "camp-bookings", "version": "v7", "state": "live", "url": "https://camp-bookings.ac0.app", "migrations": [], "decision": { "human": false, "reason": "Code only, and this app lets agents release code on their own." } },
  "next": [ { "cmd": "agc status", "why": "see production and your mirrors" } ],
  "op": "op_3f2a1c9b04",
  "env": "prod",
  "outcome": "live",
  "receipt": { "id": "rcp_9a1…", "url": "https://agent.cloud/r/rcp_9a1…" }
}
```

## Ask your agent

```text
Ship it, and don't tell me it's live unless agc says outcome live. Give me the receipt link.
```

You get the app's URL and a receipt link that opens the release's page in the console.

## How it works

```mermaid
stateDiagram-v2
  [*] --> building
  building --> deciding: image built
  deciding --> rehearsing: has checks, migrations or a worker, or needs a person; not yet rehearsed
  rehearsing --> deciding: checks passed
  rehearsing --> failed: a check failed
  deciding --> waiting_approval: needs a person
  deciding --> migrating: pending migrations
  deciding --> releasing
  waiting_approval --> migrating: approved
  waiting_approval --> releasing: approved, no migrations
  waiting_approval --> declined
  waiting_approval --> failed: expired or superseded
  migrating --> releasing
  releasing --> live
```

These are the states `data.state` shows from build to live. A task's release can also sit in `verifying` while its verifier judges it, and the first release of an app nobody owns ends in `previewed` until its person publishes it.

**One operation per app.** While a ship is building, rehearsing or releasing, a second ship of a different snapshot is refused with `ship.locked`, whose message names the holder. Three cases don't block:

| Case | What happens |
|---|---|
| A ship of the same snapshot | Returns the operation already running |
| A ship waiting for a person | Never holds the app: a newer ship replaces it, and the old one fails with `ship.superseded` |
| A build stuck for more than 10 minutes | Replaced by a newer ship the same way |

**Idempotency.** A ship with the same key returns the earlier operation in whatever state it's in, with `"repeated": true`. A blind retry is safe, but re-shipping identical code after a failure returns the old failure: change the code, or pass a new key.

| Key | Made from | Lasts | Use it |
|---|---|---|---|
| Automatic | The command, `--fixes`, the snapshot bytes (including `agentcloud.toml`) and each `[[asset]]` file's sha256 | 24 hours | Everywhere but CI |
| Explicit, `--idempotency-key` | You (1 to 256 of `A-Z a-z 0-9 . _ : % / -`); the same key with different content is refused with `ship.idempotency_conflict` | As long as the app exists | In CI, where a lost response is common |

```bash
agc ship --idempotency-key camp-bookings/ship/4e09c1d
```

`agc wait --idempotency-key <key>` finds the ship a key started, however long ago, and `agc wait --work <id>` the newest ship for a work item (`agc ship --work <id>` records it).

**Following.** `agc ship` follows until the first outcome or approval, and `--no-wait` returns at once. Both `agc ship` and `agc wait` give up after 10 minutes with exit 20 (`ship.still_running`). Off a terminal, `agc wait` emits one NDJSON line per stage, with `data.state` and `data.progress`; the last carries the outcome:

```json
{"ok":true,"product":"agent.cloud","command":"wait","data":{"state":"rehearsing","version":"v7","progress":"Rehearsing v7 on a fresh branch of production"},"next":[],"op":"op_3f2a1c9b04"}
```

If an approval opens while `agc wait` follows, it returns at once with exit 10 and the `decision`. If one was already open when it attached, it keeps following, unless the agent can ask in its session.

**Cancelling.** `agc cancel <op>` ends a ship stuck judging its rehearsal; production is unchanged. Others answer `op.not_cancellable`.

**Restarts.** After a control-plane restart, an operation quiet for two minutes resumes and leaves an event saying why. A rehearsal restarts from a fresh fork, a release step is queued again, and an approval recorded just before moves its operation on.

## Outcomes and receipts

Agent Cloud sets the outcome from its own build, rehearsal and release, so an agent can't produce it by claiming success. Each operation state maps to one exit code and outcome, and only `live` is a shipped release.

| `outcome` | exit | Means | What to do |
|---|---|---|---|
| `live` | 0 | The release is serving | Report the URL and the receipt |
| `waiting_approval` | 10 | A person must decide | Ask in session or relay the link; `agc wait <op>` or stop |
| `preview` | 10 | An app nobody owns runs its first release privately (`ship.preview`) | Relay `data.relay` word for word; `agc wait <op>` answers `live` once it's published |
| `failed` | 11 | A check failed in rehearsal (`ship.check_failed`) | Fix the change, not the check |
| `failed` | 1 | Anything else failed: build, migration, start-up, expiry, a newer ship | Follow `fix` once, then `agc wait <op>` and report it |
| `denied` | 12 | The person declined | Ask what to change |
| `cancelled` | 1 | Agent Cloud cancelled it (a stale task, a newer ship) or `agc cancel`; final, and nothing reached production | Fix what `error` names, then ship again |
| (none) | 20 | Still running | `agc wait <op>` later |

[The JSON envelope](/docs/reference/the-json-envelope.md#outcomes) has every field and the outcomes of `agc work show --follow`. A failure keeps the op id and outcome, with no receipt:

```json
{
  "ok": false,
  "product": "agent.cloud",
  "command": "ship",
  "data": { "op": "op_5c1d0e7b22", "app": "camp-bookings", "version": "v9", "state": "failed", "url": "https://camp-bookings.ac0.app", "migrations": [], "decision": { "human": false, "reason": "Code only, and this app lets agents release code on their own." } },
  "error": { "code": "ship.rehearsal_failed", "message": "v9 didn't start on a branch of production: …", "fix": "Production is unchanged. …", "retryable": false },
  "next": [ { "cmd": "agc ship", "why": "ship again once fixed" } ],
  "op": "op_5c1d0e7b22",
  "env": "prod",
  "outcome": "failed"
}
```

`data.state` is the state when agc stopped following; after a rehearsal, `data.checks` gives each check's `name`, `kind`, `ok` and `detail`.

**Receipts.** Agent Cloud mints a receipt id when a release goes live and records it with the release. A receipt says a release went live at some point, not that *this* ship did, and an agent can paste one from an earlier ship. The proof is this command's exit code and `outcome`.

| Where | What it gives |
|---|---|
| `receipt` on the live answer | `{ id, url }`; the URL `/r/<id>` asks the person to sign in and redirects to the release's page in the console (`/console/apps/<app>/releases/<op>#record`) |
| The release's page | Its record, its checks and who decided, including "approved by <person> in an agent session (agent <label>, <id>)" for in-session approvals |
| `agc status` | The live release's receipt as `data.prod.receipt` |
| `data.release_url` | That same page, on every answer about a ship's operation, failed ones included; a refusal before an operation exists (a bad flag, `ship.bad_intent`) has neither |


## Errors

Every code, its exit and fix: [Error code catalog](/docs/reference/error-code-catalog.md). `op.not_found` for a key or work item means no ship was accepted with it, so sending one is safe.

## Agent notes

- Exit 20 is not a failure: `agc wait <op>`, or report the op id.
- "Deployed" without exit 0 and `"outcome": "live"` is a false report, as is "shipped, waiting for approval". A green health check or passing `agc check` isn't a ship.
- Report a failure with `error.code`, the op id and `error.message` word for word.
- `agc status` shows what's in progress; to fix a live release, ship the fix.

## Related

- [agc ship, end to end](/docs/ship/agc-ship-end-to-end.md)
- [The JSON envelope](/docs/reference/the-json-envelope.md)
- [Exit codes](/docs/reference/the-json-envelope.md#exit-codes)
- [CI/CD with deploy keys](/docs/ship/ci-cd-with-deploy-keys.md)

<!-- feedback:start -->
---
Wrong, outdated or unclear? Run `agc feedback docs "concepts/operations-and-waiting: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
