# Deploy Runbook
<!--
ref: @any-corp/engineering/deploy-runbook
type: protocol
tags: [engineering, deploy, release, ci, cd, runbook]
triggers: [need to deploy code, rollback after a failed deploy, urgent hotfix required, check deployment status]
trigger_prompt: When an engineer needs to deploy code to production or address issues arising from a recent deployment.
version: 1
updated_at: 2026-04-30T17:25:41.136Z
-->

How code goes from `main` to production. Anyone with merge rights can deploy. Anyone on call can roll back.

## The pipeline

```
PR merged → main
            ↓
        Staging deploy (auto, ~5 min)
            ↓
        Canary deploy to prod (manual trigger, ~10 min)
            ↓
        Full prod deploy (auto if canary healthy, ~15 min)
```

## Default cadence

- **Staging** — every commit to `main`, automatic.
- **Production** — anytime during `prod-deploy` windows. Default: **Mon–Thu, 9am–4pm Pacific**. No prod deploys after 4pm Pacific. No prod deploys on Friday after noon.
- **Hotfixes** — anytime, with on-call awareness.

## Deploy windows

| Window | When | Status |
|---|---|---|
| Standard | Mon–Thu, 9am–4pm Pacific | Open |
| Friday morning | 9am–noon Pacific | Open for low-risk only |
| Friday afternoon | After noon Pacific | Closed |
| Weekends | Sat–Sun | Closed (hotfix only) |
| Holidays + winter break | Per `@any-corp/calendar/yearly-cycle` | Closed |
| Day before holidays | Closed |

"Closed" means deploys go through the **incident on-call** for explicit go/no-go.

## How to deploy — step by step

### 1. Confirm staging is healthy

- Check the deploy dashboard: error rate, latency, queue depth.
- If staging looks bad, **don't promote to prod**. Investigate first.

### 2. Trigger the canary

- From the deploy tool, select the commit, click **Promote to canary**.
- Canary serves **5% of prod traffic** for 10 minutes.
- Watch the canary dashboard: error rate, latency, custom business metric.
- If anything looks wrong, click **Halt** — canary stops, traffic returns to current prod.

### 3. Promote to full prod

- After canary is healthy for 10 minutes, the system **auto-promotes**.
- Manual promote available if you want to move sooner.

### 4. Watch for 15 minutes

- Stay around. Don't kick off a deploy and walk away.
- Check the post-deploy alerts. False positives happen, but real ones look ugly fast.

### 5. Confirm in #deploys

```
✅ Deploy to prod complete. SHA: <hash>. Promoted by <name>. Watching.
```

## Database migrations

Migrations follow **expand → migrate → contract**:

1. **Expand:** ship the new schema, **without using it yet**. Old code keeps running.
2. **Migrate:** ship the new code that uses the new schema.
3. **Contract:** after the new code has been deployed for at least a week, drop the unused parts of the old schema.

Each phase is its own deploy. **Never** combine schema changes and code changes that depend on them in one deploy.

For data backfills:
- **Idempotent and resumable.**
- **Run from a job, not the deploy.**
- **Status visible** in observability.

## Feature flags

We use feature flags for any user-visible new behavior.

- Default OFF in prod when shipped.
- Roll out: 1 internal user → 10 internal → 1% prod → 10% → 50% → 100%.
- Each ramp step has at least 24 hours of soak unless the flag is trivial.
- Flags removed within 60 days of full rollout. Lingering flags are tech debt.

## Rolling back

If something looks wrong post-deploy:

1. **Trigger rollback** from the deploy tool. No "let's wait and see" — roll back, then investigate.
2. Rollback takes ~3 minutes.
3. Notify `#deploys` and `#incidents`:
   ```
   ⚠ Rolling back deploy <hash> due to <symptom>. ETA <time>.
   ```
4. Page on-call (`@any-corp/engineering/incident-response`) if customer-impacting.
5. Postmortem if any of: rollback was triggered after a deploy, customers were impacted, an alert fired (`@any-corp/engineering/postmortem`).

## Rollback constraints

- **Within the same migration phase**, rollback is safe. Old code works against the schema.
- **Across migration phases**, rollback may be unsafe. Migration ordering exists to make rollback safe within a phase; don't violate it.
- **Long-running deploys** (large data migrations, slow rollouts): we don't roll those back fast — we **roll forward** to a fix.

## Hotfixes

When the fix can't wait for the normal cycle:

1. Branch from the **current production commit**, not `main`.
2. Apply the minimal fix.
3. Open PR with `[HOTFIX]` in the title; tag on-call.
4. Get review, merge to `main` and the hotfix branch.
5. Deploy the hotfix branch directly to prod (skipping staging is permitted; risky changes still go through canary).
6. After: cherry-pick or merge the fix forward into `main` if not already.

Hotfixes outside business hours: on-call handles. Don't be a hero alone.

## Who can deploy

| Role | Can deploy |
|---|---|
| Any engineer | Their team's services, during normal windows |
| On-call | Anything, anytime |
| New hire (< 90 days) | Their team's services, with a buddy in `#deploys` |
| Outside engineer (consultant, contractor) | Only via PR + sponsoring engineer's deploy |

## Audit log

Every deploy is logged with:
- Commit SHA.
- Who triggered it.
- Time started, time finished.
- Canary metrics.
- Any halts / rollbacks.

Visible in the deploy tool. Retained 1 year.

## What we don't do

- We don't deploy on Fridays after noon. Period.
- We don't skip canary "for a small change."
- We don't combine migration and code changes in the same deploy.
- We don't run migrations during peak traffic.
- We don't deploy without watching it land. Walk away after 15 healthy minutes, not before.

---

*Related: `@any-corp/engineering/code-review` · `@any-corp/engineering/git-and-pr` · `@knowledge/frameworks/the-interpretability-tax` · `@knowledge/frameworks/constraints-in-code-not-in-prompt` · `@content/youtube/aie/2026-07-11-stop-ai-agent-hallucinations-5-techniques-production-pattern`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*