← Back to Skills

Ship on Approval and on Merge

Nobody has to run `tawa deploy --prod` after a merge:

Commanddeploy

About

Nobody has to run `tawa deploy --prod` after a merge:

Skill Content

This is the raw markdown that gets installed as a Claude Code command.

---
name: tawa-auto-deploy
description: "How merges and approvals ship to prod automatically (autoDeploy.onMerge/onApproval/reconcile, gated vs ungated services, Forgejo webhooks, missed-webhook reconciler). Use when a merge did or did not deploy, or when approving a gated commit."
---

# Ship on Approval and on Merge

## The Short Version

Nobody has to run `tawa deploy --prod` after a merge:

| Service | What ships it |
|---|---|
| **Gated** (enrolled in the deploy-approval gate, set in the console) | **Approving** the commit: `tawa approve`, or completing the portal approval subtask. The approved commit deploys at once, if it is still the branch tip. |
| **Ungated** | **Merging** to the service branch. A signed Forgejo push deploys it to prod. |

Both are builder runtime switches (Console → Operations → **Builder Switches**), and
`tawa deploy --prod` still works exactly as before. Source: iec-builder#290.

| Setting | Default | Does |
|---|---|---|
| `autoDeploy.onApproval` | on | Approving a prod commit that is the tip of the service branch queues its deploy |
| `autoDeploy.onMerge` | **on** (switched on 2026-10-15; the code default is off) | A push to the service branch deploys an ungated service |
| `autoDeploy.reconcile` | on | Every 3 minutes, deploy an ungated service's branch tip if no prod build of it exists — the safety net for a lost webhook (iec-builder#355) |
| `autoDeploy.excludeServices` | `[]` | Services that never deploy automatically |

## Rules that make it safe

- **Previews are never automatic.** A push or an approval never builds a preview; one exists only
  because someone (or Chaac) called the preview API. See [Preview Environments](preview-environments.md).
- **Prod only.** No branch ever deploys to sandbox or UAT automatically. Sandbox fires real crons
  and mail.
- **Only main/master.** A push to any other branch builds nothing, and a service whose own branch
  is not `main`/`master` never deploys on its own.
- **Only the current tip.** A push deploys only when its commit is the branch tip right now. A
  replayed, redelivered or out-of-order delivery of an older push builds nothing, so a webhook can
  never roll a service back. When two merges land close together, the newer automatic deploy
  cancels the older automatic build if it has not reached the deploy step. Manual builds are never
  cancelled.
- **Exact repository only.** A delivery is matched to a service by its repository URL, never by
  repository name, so a look-alike repo in the org cannot stand in for a service.
- **Gated services never deploy on merge.** They wait for an approval, and approving deploys
  them. A Chaac Cloud task follows the same rule: it stops at the gate and reports
  "waiting on approval".
- **An approval ships only the branch tip.** If `main` has moved past the approved commit, nothing
  deploys and `tawa approve` says why. Approve the tip, or run `tawa deploy --prod`. An approval
  never ships an older `main` over a newer one.
- **Every webhook must be authenticated.** Forgejo and GitHub deliveries need an HMAC-SHA256 over
  the raw body, using `FORGEJO_WEBHOOK_SECRET` / `GITHUB_WEBHOOK_SECRET` or the service's own
  `webhookSecret`. GitLab needs its token. An unsigned or forged delivery gets `401` and builds
  nothing. A hook sending form-encoded bodies is also refused: use JSON.
- **`/webhooks/generic` is retired** (`410`). It accepted any commit with no authentication.
- **No double builds.** Both triggers use the trigger-time dedupe (iec-builder#110). A merge and a
  `tawa deploy --prod` for the same commit end up as one build.
- **The builder never deploys itself.** iec-builder ships through PM2.
- **An approval never fails because of the deploy.** If queueing fails, or does not finish within
  8 seconds, the approval is still saved and the response says to deploy by hand.
- **Fail closed.** Until the builder has read its stored settings after a restart, nothing deploys
  automatically.
- **A lost webhook is caught within minutes.** See [A merge the webhook missed](#a-merge-the-webhook-missed).
- **The portal path needs the platform key.** `approve-internal`, which the portal's approval
  subtask calls, accepts only the builder's internal key, not a service API key.

## A merge the webhook missed

A merge deploys through **one** webhook delivery. If the builder is down or restarting when it
arrives (it answers `502`), that delivery is lost: Forgejo 14 does not retry a failed webhook
delivery on its own, only a manual **Replay** in the hook's delivery list. On 2026-10-24
iec-webmaster `f452972` merged during such a `502` and stayed undeployed until someone ran
`tawa deploy --prod`.

The builder now reconciles (iec-builder#355). Every 3 minutes, under a lease, it checks each
Forgejo service (tip and commit time from Forgejo's branch API) and queues the build a webhook would have queued when **all** of these hold:

| Check | Why |
|---|---|
| Every merge rule above passes: settings read, not excluded, `main`/`master`, `autoDeploy.onMerge` on, ungated | Same decision as the webhook (`decideMergeDeploy`) |
| `autoDeploy.reconcile` is on | Its own switch |
| The service has deployed to prod before | A registered repo is not a request to ship it |
| No prod build of the service is in flight | The next pass decides once it finishes |
| **No prod build of the tip exists in any status** — queued, running, completed, **failed** or cancelled | A failed build is never retried in a loop; fix it and merge again, or `tawa deploy --prod` |
| The tip was committed **after the service's last prod build**, and **within the last 6 hours** | It is a missed merge, not a backlog. A `main` someone left ahead of prod on purpose is never shipped |
| The tip is at least 3 minutes old | A slow webhook wins |

So a missed merge ships within roughly 3–6 minutes of the builder coming back. A tip that fails
only the "after the last prod build / 6 hours" check is listed as `backlog` in the pass log and
left alone; deploy it with `tawa deploy --prod` if it should ship.

> **Correction (2026-10-25):** the first version had no backlog bound. Its first prod pass found ten
> services whose `main` had sat ahead of prod for days (foundry, scaled to zero on purpose, among
> them) and was switched off before its next pass would have deployed them. Fixed in
> iec-builder#358. The build goes
through the #110 dedupe like every other trigger, is recorded with `triggeredBy: webhook`, and
Septor gets `deploy.auto_queued` with `trigger: reconcile`. The builder log says
`Missed deploy reconciled: branch tip had no prod build, queued it (#355)`.

The webhook stays the fast path. The reconciler is the guarantee: do not add per-repo hooks or
retry scripts to cover outages.

## What you see

```text
$ tawa approve --commit 105d096 --env prod
✓ Approved bio @ 105d096a6778… for prod
ℹ Approval expires: 2026-10-16T04:25:39Z
✓ Deploying now: build 5b9c3fd1
ℹ Follow it with: tawa logs --build 5b9c3fd1
```

When it did not deploy:

```text
⚠ Not deployed automatically: The approved commit is no longer the branch tip (ac7a206); approve the tip, or run tawa deploy --prod
ℹ Deploy it with: tawa deploy --prod
```

The approve response carries `autoDeploy: { queued, reason, buildId?, deduplicated? }`, and so does
the portal's `approve-internal` call. Septor records `deploy.auto_queued` and `deploy.auto_skipped`,
each with the service, commit, trigger and reason.

## Settings API

`GET /admin/settings`, `PUT /admin/settings/:key` with `{ value, expectedVersion? }`, and
`GET /admin/settings/:key/history` on the builder, with the same contract as Janus.

- Only Bio-ID ids in `BUILDER_SETTINGS_OWNERS` (default: the platform owner) may write, with their
  own token from any Bio-ID app (the Console, the CLI; no app allowlist, iec-builder#382) or an
  agent token whose subject is that owner (`act`, or a Claude or Chaac session; iec-builder#384,
  recorded as `via` in the audit). Personas and the internal service key can read but never write.
- Changes apply within about 15 seconds, with no restart.

## Platform operators

One Forgejo **org-level** webhook (`push` only) delivers to
`https://builder.tawa.pro/webhooks/forgejo`, signed with `FORGEJO_WEBHOOK_SECRET`. The secret is in
the builder's `.env` and in the Locker. Repositories that are not services are answered with
`200 ignored`.

**Add the `pull_request` event to the org hook** (iec-builder#313). Preview environments are torn
down when their PR is closed or merged; the same signed delivery path carries it. In Forgejo, org
settings, Webhooks, edit the builder hook, and tick *Pull Request* beside *Push*. A `pull_request`
event is authenticated exactly like a push (unsigned or forged is `401`), never deploys anything, and
only a `closed` action acts: it tears down that service's `pr-<n>` preview
([Preview Environments](preview-environments.md#lifecycle-ttl-reaper-teardown-iec-builder313)).
Other actions are answered `200 ignored`. The step is optional: without it the preview reaper tears
the preview down within 10 minutes of the PR closing instead of seconds.

## What changed for existing hooks

Before iec-builder#290, a Forgejo or GitHub push to `main` deployed prod whether or not it was
signed, and `/webhooks/generic` deployed any commit it was given. Now:
- every delivery must be signed;
- Forgejo and GitHub pushes deploy only while `autoDeploy.onMerge` is on;
- an unknown repository is answered `200 ignored` instead of `404`.

**Correction (2026-10-15):** 26 repositories had an **unsigned** per-repo hook to
`https://builder.tawa.insureco.io/webhooks/forgejo`, a live alias of the builder. Every push to their
`main` was already deploying them to prod with no signature at all. Among them were septor,
iec-docman, iec-test, iec-ledger, iec-ledger-ui, iec-raterspot and byte-mga. At rollout:
- the signed org hook replaced those hooks (they are deactivated, not deleted);
- `autoDeploy.onMerge` was switched on in the same step;

so those services kept deploying on merge, now signed. Do not add a per-repo hook. The org hook
covers every repository.

Install

Copy the skill content and save it to:

~/.claude/commands/tawa-auto-deploy.md
Download .md

Coming soon via CLI:

tawa chaac install tawa-auto-deploy

Details

Format
Command
Category
deploy
Version
1.0.62972
Tokens
~2,534
Updated
2026-11-25
platformdeploymentapprovalwebhookcigates