# Merge authority thin v1: progress

Branch `merge-authority` from main ac4a809. Spec:
`docs/superpowers/specs/2026-11-11-equipo-merge-authority.md` revision
3.1 (rev 1 7eba9c8, rev 2 4ab106f, rev 3 5d7e2c4; Astra rounds 1 to 3 all
REQUEST CHANGES; Paul chose "Refuse old runners" for round 3's Critical
and the controller directed the other four findings).

## Done

1. **The gate** (`internal/equipo/mergegate`, pure): `Decide` answers act,
   ask or never with every criterion and Equipo's stance; `Sensitive`
   matches the old and new path of every entry against the fixed table
   and a project's added globs; `ValidPolicy` and `Tighter` bound a
   policy and what the coordinator may apply alone. Every automatic merge,
   checks passed included, needs `wire.ProtocolMergeFacts`.
2. **Wire, protocol named by capability**: `wire.ProtocolMergeFacts`
   (protocol 4: spend-1 kept 3 as `wire.ProtocolSpend`; the merge
   authority fields are dropped below 4 by their own downgrade step,
   chained after spend's). Optional fields: `StepReport.change`,
   `merge_source`, `merge_parents`; `LeaseCheck.purpose`
   (`merge_request`); `DispatchCommand.revert_sha`; the refusal reason
   `merge_not_authorized`. `Encode` drops them below the protocol (its own
   downgrade step).
3. **Runner**: the review measures the reviewed pair with no model
   (`facts.go`: raw and numstat listings that must agree, both rename
   paths, symlinks, gitlinks, mode changes and new executables as special,
   binary files, signing lines in Xcode project files, the revert's tree
   check against the merge commit's first parent). The merge step confirms
   every hub request with `ConfirmMerge` and ends `merge_not_authorized`,
   nothing sent, when refused (at the start lease too); its report says
   where the merge SHA came from and, from the hub's own answer, the
   merge commit's parents (`forge.MergeOutcome.Source`; the forge's tip
   fallback is unchanged, a separate issue).
4. **Instance** (`internal/equipo/chat/mergeauth.go`): `authorizeMerge`
   decides every merge and writes one audit row: `autoMerge` at Ready
   (never for a SHA already asked about; nothing decided while the
   primary is offline), a person's Merge on the card or task page (a
   failed, ended attempt is tried again), Retry, and every merge step
   lease. The fence: an automatic merge step's lease from a connection
   below the protocol is refused whatever it asks, settled failed in the
   same transaction and asked about; a `merge_request` lease decides
   again on every call. Change facts are kept only when exactly the
   review attempt's, whole, from the primary. Equipo's own merge without
   checks gets a receipt card (Undo only for a hub-named merge commit with
   the candidate as second parent, 7 days); Undo opens an ordinary revert
   task through the normal flow and puts the project in ask mode. The
   ships question asks once per project and applies to later decisions
   only. `set_merge_policy` applies only stricter changes alone (a looser
   one is a Save card for an owner); `hold_merge` only stops.
5. **Pages**: the merge, ships, policy and receipt cards in the
   conversation (`chat.html`); the project page's "How Equipo merges"
   section and owner form (`merge_policy.html`, one include line in
   `work_project.html`; no change to the Needs you card's template, only
   its options now include Wait for a Mac).
6. **API**: `POST /api/v1/tasks/{id}/undo-merge`,
   `GET/PUT /api/v1/projects/{id}/merge-policy`; `Task` gained
   `merge_decision`, `merge_hold`, `revert_of`, `undo_offered` (all
   omitempty). Fixtures `api/task-merged.json`, `api/task-ready.json`,
   `api/needs-you.json` gained `merge_decision`; new frame fixtures
   `lease-merge`, `step-review-facts`, `step-merged-hub`,
   `dispatch-revert`.
7. **Migration 0060** `thin_merge_authority` (main took 0058 for
   project stars and 0059 for usage rounds; renumbered when main was
   merged in): tables `chat_merge_policies`, `chat_merge_audit`;
   columns `chat_steps.change_facts`, `decided_by`, `merge_source`,
   `merge_parents`; `chat_tasks.merge_hold`, `merge_verified`,
   `revert_of`, `revert_sha`. Additive; if mac-recheck lands its 0060
   first, this takes the next free number.
8. **Coordinator**: the two tools in `wire.ConverseTools`, the runner's
   MCP list, the provider's converse list and the Claude launcher's
   allowlist (`TestConversePolicyCoversEveryTool`), and one house-rule
   sentence about them.

9. **Main merged twice** (spend-1 and the four UI branches; then
   mac-recheck). Migration now **0061** (main has 0060 for
   `chat_steps.recheck_by`). Protocol 4 is `wire.ProtocolMergeFacts`.
   A Mac re-run's pass (mac-recheck sets eligibility when the passing
   result lands, on the exact candidate) is judged like a merge without
   checks less the environment rule (`Inputs.Rechecked`):
   `TestContractMacRecheckMergeAuthority` (routine merges through
   authorizeMerge and its request is confirmed; sensitive asks; held
   asks; main ships asks; a pass on another SHA counts for nothing),
   first failing on sensitive and ships (Equipo merged), and
   `TestDecideRecheckedPass`. Mutations: the gate's re-run rule and the
   instance's Rechecked input, both killed.

## Tests (targeted, local, niced)

- `go test ./internal/equipo/mergegate` (9 tests, including a 20,000-input
  invariant simulation against an independent oracle)
- `go test ./internal/wire` (with `TestWireProtocol3Downgrade`)
- `go test ./internal/runner/thin -run 'TestReviewReportsChangeFacts|TestRevertCheck|TestMergeConfirmPurpose|TestMergeSource|TestLeaseRefusalReasons|TestMerge|TestRecoverSteps|TestReview|TestLink|TestOpening'`
- `go test ./internal/runner/provider/claude -run TestConversePolicy`
- `go test ./internal/thintest -run` the eleven merge authority contracts
  (`TestContractMergeAuthorityAct`, `...Asks`, `...MergeFenceOldRunner`,
  `...ConfirmRechecks`, `...NoQueuedAutoMerge`, `...ShipsQuestion`,
  `...WaitNeverMerges`, `...UndoMerge`, `...MergePolicyTool`,
  `...FactsAcceptance`, `...RosterDenial`) and the slice 4c merge, review
  and page contracts now on a `ProtocolMergeFacts` runner
- `go test ./internal/equipo/chat -run TestHousekeeping` (the principal
  may not write a merge policy)
- `go test ./internal/equipo -run 'TestMigrationModels|TestConversationMigrationSnapshot|TestTemplateCopyKeys|TestRunnerCopyInventory'`
- `go test ./internal/plan3test -run TestPlan3ReleaseBoundaries`
- headless `TestHeadless/(4_review|4c_checks_card|4c_rebase)`: 4c now
  ends with the owner answering the ships question and a third iOS change
  merging on its own, measured by the real runner, with a receipt and Undo.
  One combined run first failed in 4c_rebase (the rebase's checks still
  queued at the wait's end, docs-t1 under load); 4c_rebase alone and the
  three together then passed.
- `make budget`, gofmt, `go vet ./internal/...`,
  `scripts/runner-dead-references.py`
- `make ci` (`CGO_ENABLED=0`) runs on hosted CI only.

## Mutations (each guard broken, a test watched failing, restored)

Gate: environment reason, protocol, lines, binary, sensitive paths,
special entries, ships, policy mode, hold, exact revert, first-ready
eligibility, sandbox, never for a person, incomplete facts (first
survived; a case added), stance, Tighter on ships, glob depth, camel-case
tokens, rename old path: all killed. Wire: purpose, change facts and the
downgrade step: killed. Runner: ancestry, entry bound, mode change,
symlink, gitlink, new executable, signing, binary, rename, revert on-top,
revert tree: killed; ConfirmMerge replaced by the plain lease, the
refusal ignored, the start refusal as a cancel, mislabelled hub and
cached sources, parents for any source: killed; the refusal reason
mapping first survived (no test), then extracted and killed by
`TestLeaseRefusalReasons`; the launcher allowlist: killed by
`TestConversePolicyCoversEveryTool`. Instance: the fence at the lease and
at dispatch, the confirmation re-check, the checked-merge re-check at
confirmation (first mutation did not loosen; the real loosening killed),
the `merge_asked` guard, Merge retrying a failed attempt, verified
landing, Undo's ask mode, facts acceptance, the receipt, deciding while
offline, the ships question once (first survived; a second asking task
added), the policy tool's tighter-only rule, the audit row, the revert
target, a teammate's Undo: all killed. Three first runs that died only on
a build failure were redone as valid mutations.

## Copy for review

84 strings in `internal/equipo/copy.go`, each `COPY REVIEW REQUIRED`, each
in the Plan 3 copy inventory (`CONTROLLER-REPORT-plan-3.md`): the card's
stances and phrases (`chat.merge.*`), Wait for a Mac, the ships question
and its answers, the policy confirm card, the receipt, the revert title,
the ask-mode reason, `work.reason.merge_not_authorized` and the project
page section (`work.merge_policy.*`). Model-facing texts (tool results,
the two tool descriptions, the house-rule sentence) are not runtime copy.

## Not in v1

Verification on the merged commit, the trust counter, automatic fix
tasks, a revert step, a same-SHA checks retry after Wait, and the forge's
tip fallback fix for every merge (a separate issue).

## Astra branch review (one round, on 4d37307): REQUEST CHANGES

1. Critical, protocol 1 bypasses the lease fence: fixed. The fence now
   also runs when a runner connects below `wire.ProtocolMergeFacts`
   (`fenceOldRunner` in `Connect`): every automatic merge attempt placed
   on it is settled failed `merge_not_authorized`, an unsent dispatch is
   never sent, a received one is cancelled, and the person is asked.
   `TestContractMergeFenceOldRunner` covers a 4 to 2 and a 4 to 1
   reconnect. Mutations (no fence at connect, no cancel) killed. Limit:
   an older build already mid-request when it reconnects cannot be
   stopped by the instance; the forge record and the merge watch settle
   that landing.
2. Critical, a Mac re-run re-arms an asked SHA: not changed. The
   controller ruled that a re-run pass on the exact candidate merges a
   routine change on its own through `authorizeMerge` (sensitive,
   shipping, held and asking cases ask); this is that ruling, reported
   back as a product decision.
3. Important, open cards miss later holds and policy changes: fixed.
   `refreshMergeCards` re-decides (audited as `card_refresh`, never shown
   as the task's decision, never acted on) and rewrites an open card's
   words and options with a new revision on `hold_merge` and every
   policy change. `TestContractCardRefresh`; mutations (no refresh on a
   hold, words not rewritten) killed.
4. Important, Undo not bound to the receipt: fixed. Undo needs the open
   receipt offering it (only Equipo's own merge without checks with a
   hub-named merge commit has one) and its current revision on both the
   card and `POST /api/v1/tasks/{id}/undo-merge` (`{"revision": n}`).
   `TestContractUndoMerge` adds a person's merge with the hub's answer
   (no Undo) and a stale revision (409); mutations killed.

## The ruling on Critical 2 (Mac re-runs of an asked SHA)

The controller ruled: a re-run's pass on the exact candidate may merge
on its own (through `authorizeMerge`) only when the card asked solely
because checks could not run, or the person chose Wait for a Mac on that
SHA's card. For any other reason the SHA stays asked and the card is
re-decided as a `card_refresh`. No new column: the reason is the SHA's
newest `decision` or `card_refresh` audit row (`recheckMayMerge`); no
row counts as another reason (fails closed). The Wait is read from the
task's newest merge card, so a Wait on an earlier SHA never counts.
`recheckMac` withdraws the card and clears `merge_asked` only when the
pass may merge; otherwise `autoMerge` keeps the SHA asked and
re-decides the card once after the re-run finishes
(`refreshAfterRecheck`).

`TestContractMacRecheckMergeAuthority` through the real recheck path:
Wait chosen merges; checks only merges (its reason is seeded, since the
gate never asks a needs_macos change for checks alone); sensitive, held
and main ships stay asked with the same card refreshed; a missing reason
stays asked; a pass on another SHA counts for nothing.
`TestContractMacRecheckOnlyWaiting` now expects the waiting task's card
to stay open. Mutations, each killed: checks-only predicate off (checks
only), Wait ignored (Wait chosen), any failing criterion treated as
checks only (sensitive, held, ships), no row treated as may-merge
(missing reason), no refresh after the re-run (sensitive, held, ships),
the re-run withdrawing the card regardless (sensitive, held, ships).

Operating rule (spec §10a): deploy with no merge in flight. An older
build already part-way through a hub merge request when the instance
swaps cannot be stopped by the fence; restart the runners on the new
build right after the swap.

## Copy: delegated review (Astra, 2026-11-11)

The 84 strings went through Astra as the copy-review gate (Paul's
delegation of 2026-10-25): 55 kept, 29 changed, applied verbatim, each
now `COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11)` in `copy.go` and in
the Plan 3 inventory. The changes move the project page and the card
phrases to Equipo's first person ("I ask before every merge in this
project", "Merged on my own"), say "main branch" in the shipping
phrases and question, and tighten the size, eligibility, receipt,
stale-card and Stopped wording. Tests that quote them updated.
