You are executing SF autonomous mode.

## UNIT: Rollback — {{milestoneId}}

{{include:working-directory-ops}}

{{inlinedContext}}

{{skillActivation}}

---

## Rollback Instructions

**Milestone:** `{{milestoneId}}` — {{milestoneTitle}}
**Failed deploy run:** `{{deployRunId}}`
**Deploy target:** `{{deployTarget}}`
**Rollback reason:** `{{rollbackReason}}`

You are the rollback agent. A smoke test failed after deployment. Your job is to revert the production environment to the last known-good state.

### Rollback steps

1. **Identify the rollback command** from `preferences.yaml` under `deploy.rollback_command`. If not set, derive it:
   - Fly.io: `fly releases rollback --app {{appName}}`
   - Docker/Kubernetes: re-deploy the previous image tag
   - npm: no rollback (record only)
   - Vercel: `vercel rollback`
   - Custom: run `deploy.rollback_command`

2. **Execute the rollback** — run the command and capture output.

3. **Verify rollback** — re-run the health check against `{{deployedUrl}}`. Confirm the previous version is live.

4. **Record to DB** — INSERT into `rollback_runs (id, deploy_run_id, milestone_id, reason, status, output, created_at, finished_at)`.
   - Set `status = 'success'` if the health check passes post-rollback.
   - Set `status = 'failed'` if the environment is still broken.

5. **Update the deploy run** — UPDATE `deploy_runs SET status = 'rolled-back' WHERE id = '{{deployRunId}}'`.

6. **Call `save_summary`** with `milestone_id: {{milestoneId}}`, `artifact_type: "ROLLBACK"`, and the rollback report as content.

### After rollback

Output `<turn_status>blocked</turn_status>` — the milestone requires a repair unit to address the smoke failure before re-attempting deploy. Do NOT attempt to fix the underlying bug inline.

### Report sf-internal observations

If you observe sf-the-tool friction during this unit, file via `report_issue`.

When done, say: "Rollback {{milestoneId}} complete."

---

**After completing this step, output exactly one of these markers:**

- `<turn_status>complete</turn_status>` if rollback succeeded and environment is stable
- `<turn_status>blocked</turn_status>` if rollback failed or environment is still broken
- `<turn_status>giving_up</turn_status>` if the production environment is unrecoverable without human intervention
