| 1 | # Merge authority thin v1: progress |
| 2 | |
| 3 | Branch `merge-authority` from main ac4a809. Spec: |
| 4 | `docs/superpowers/specs/2026-11-11-equipo-merge-authority.md` revision |
| 5 | 3.1 (rev 1 7eba9c8, rev 2 4ab106f, rev 3 5d7e2c4; Astra rounds 1 to 3 all |
| 6 | REQUEST CHANGES; Paul chose "Refuse old runners" for round 3's Critical |
| 7 | and the controller directed the other four findings). |
| 8 | |
| 9 | ## Done |
| 10 | |
| 11 | 1. **The gate** (`internal/equipo/mergegate`, pure): `Decide` answers act, |
| 12 | ask or never with every criterion and Equipo's stance; `Sensitive` |
| 13 | matches the old and new path of every entry against the fixed table |
| 14 | and a project's added globs; `ValidPolicy` and `Tighter` bound a |
| 15 | policy and what the coordinator may apply alone. Every automatic merge, |
| 16 | checks passed included, needs `wire.ProtocolMergeFacts`. |
| 17 | 2. **Wire, protocol named by capability**: `wire.ProtocolMergeFacts` |
| 18 | (protocol 4: spend-1 kept 3 as `wire.ProtocolSpend`; the merge |
| 19 | authority fields are dropped below 4 by their own downgrade step, |
| 20 | chained after spend's). Optional fields: `StepReport.change`, |
| 21 | `merge_source`, `merge_parents`; `LeaseCheck.purpose` |
| 22 | (`merge_request`); `DispatchCommand.revert_sha`; the refusal reason |
| 23 | `merge_not_authorized`. `Encode` drops them below the protocol (its own |
| 24 | downgrade step). |
| 25 | 3. **Runner**: the review measures the reviewed pair with no model |
| 26 | (`facts.go`: raw and numstat listings that must agree, both rename |
| 27 | paths, symlinks, gitlinks, mode changes and new executables as special, |
| 28 | binary files, signing lines in Xcode project files, the revert's tree |
| 29 | check against the merge commit's first parent). The merge step confirms |
| 30 | every hub request with `ConfirmMerge` and ends `merge_not_authorized`, |
| 31 | nothing sent, when refused (at the start lease too); its report says |
| 32 | where the merge SHA came from and, from the hub's own answer, the |
| 33 | merge commit's parents (`forge.MergeOutcome.Source`; the forge's tip |
| 34 | fallback is unchanged, a separate issue). |
| 35 | 4. **Instance** (`internal/equipo/chat/mergeauth.go`): `authorizeMerge` |
| 36 | decides every merge and writes one audit row: `autoMerge` at Ready |
| 37 | (never for a SHA already asked about; nothing decided while the |
| 38 | primary is offline), a person's Merge on the card or task page (a |
| 39 | failed, ended attempt is tried again), Retry, and every merge step |
| 40 | lease. The fence: an automatic merge step's lease from a connection |
| 41 | below the protocol is refused whatever it asks, settled failed in the |
| 42 | same transaction and asked about; a `merge_request` lease decides |
| 43 | again on every call. Change facts are kept only when exactly the |
| 44 | review attempt's, whole, from the primary. Equipo's own merge without |
| 45 | checks gets a receipt card (Undo only for a hub-named merge commit with |
| 46 | the candidate as second parent, 7 days); Undo opens an ordinary revert |
| 47 | task through the normal flow and puts the project in ask mode. The |
| 48 | ships question asks once per project and applies to later decisions |
| 49 | only. `set_merge_policy` applies only stricter changes alone (a looser |
| 50 | one is a Save card for an owner); `hold_merge` only stops. |
| 51 | 5. **Pages**: the merge, ships, policy and receipt cards in the |
| 52 | conversation (`chat.html`); the project page's "How Equipo merges" |
| 53 | section and owner form (`merge_policy.html`, one include line in |
| 54 | `work_project.html`; no change to the Needs you card's template, only |
| 55 | its options now include Wait for a Mac). |
| 56 | 6. **API**: `POST /api/v1/tasks/{id}/undo-merge`, |
| 57 | `GET/PUT /api/v1/projects/{id}/merge-policy`; `Task` gained |
| 58 | `merge_decision`, `merge_hold`, `revert_of`, `undo_offered` (all |
| 59 | omitempty). Fixtures `api/task-merged.json`, `api/task-ready.json`, |
| 60 | `api/needs-you.json` gained `merge_decision`; new frame fixtures |
| 61 | `lease-merge`, `step-review-facts`, `step-merged-hub`, |
| 62 | `dispatch-revert`. |
| 63 | 7. **Migration 0060** `thin_merge_authority` (main took 0058 for |
| 64 | project stars and 0059 for usage rounds; renumbered when main was |
| 65 | merged in): tables `chat_merge_policies`, `chat_merge_audit`; |
| 66 | columns `chat_steps.change_facts`, `decided_by`, `merge_source`, |
| 67 | `merge_parents`; `chat_tasks.merge_hold`, `merge_verified`, |
| 68 | `revert_of`, `revert_sha`. Additive; if mac-recheck lands its 0060 |
| 69 | first, this takes the next free number. |
| 70 | 8. **Coordinator**: the two tools in `wire.ConverseTools`, the runner's |
| 71 | MCP list, the provider's converse list and the Claude launcher's |
| 72 | allowlist (`TestConversePolicyCoversEveryTool`), and one house-rule |
| 73 | sentence about them. |
| 74 | |
| 75 | 9. **Main merged twice** (spend-1 and the four UI branches; then |
| 76 | mac-recheck). Migration now **0061** (main has 0060 for |
| 77 | `chat_steps.recheck_by`). Protocol 4 is `wire.ProtocolMergeFacts`. |
| 78 | A Mac re-run's pass (mac-recheck sets eligibility when the passing |
| 79 | result lands, on the exact candidate) is judged like a merge without |
| 80 | checks less the environment rule (`Inputs.Rechecked`): |
| 81 | `TestContractMacRecheckMergeAuthority` (routine merges through |
| 82 | authorizeMerge and its request is confirmed; sensitive asks; held |
| 83 | asks; main ships asks; a pass on another SHA counts for nothing), |
| 84 | first failing on sensitive and ships (Equipo merged), and |
| 85 | `TestDecideRecheckedPass`. Mutations: the gate's re-run rule and the |
| 86 | instance's Rechecked input, both killed. |
| 87 | |
| 88 | ## Tests (targeted, local, niced) |
| 89 | |
| 90 | - `go test ./internal/equipo/mergegate` (9 tests, including a 20,000-input |
| 91 | invariant simulation against an independent oracle) |
| 92 | - `go test ./internal/wire` (with `TestWireProtocol3Downgrade`) |
| 93 | - `go test ./internal/runner/thin -run 'TestReviewReportsChangeFacts|TestRevertCheck|TestMergeConfirmPurpose|TestMergeSource|TestLeaseRefusalReasons|TestMerge|TestRecoverSteps|TestReview|TestLink|TestOpening'` |
| 94 | - `go test ./internal/runner/provider/claude -run TestConversePolicy` |
| 95 | - `go test ./internal/thintest -run` the eleven merge authority contracts |
| 96 | (`TestContractMergeAuthorityAct`, `...Asks`, `...MergeFenceOldRunner`, |
| 97 | `...ConfirmRechecks`, `...NoQueuedAutoMerge`, `...ShipsQuestion`, |
| 98 | `...WaitNeverMerges`, `...UndoMerge`, `...MergePolicyTool`, |
| 99 | `...FactsAcceptance`, `...RosterDenial`) and the slice 4c merge, review |
| 100 | and page contracts now on a `ProtocolMergeFacts` runner |
| 101 | - `go test ./internal/equipo/chat -run TestHousekeeping` (the principal |
| 102 | may not write a merge policy) |
| 103 | - `go test ./internal/equipo -run 'TestMigrationModels|TestConversationMigrationSnapshot|TestTemplateCopyKeys|TestRunnerCopyInventory'` |
| 104 | - `go test ./internal/plan3test -run TestPlan3ReleaseBoundaries` |
| 105 | - headless `TestHeadless/(4_review|4c_checks_card|4c_rebase)`: 4c now |
| 106 | ends with the owner answering the ships question and a third iOS change |
| 107 | merging on its own, measured by the real runner, with a receipt and Undo. |
| 108 | One combined run first failed in 4c_rebase (the rebase's checks still |
| 109 | queued at the wait's end, docs-t1 under load); 4c_rebase alone and the |
| 110 | three together then passed. |
| 111 | - `make budget`, gofmt, `go vet ./internal/...`, |
| 112 | `scripts/runner-dead-references.py` |
| 113 | - `make ci` (`CGO_ENABLED=0`) runs on hosted CI only. |
| 114 | |
| 115 | ## Mutations (each guard broken, a test watched failing, restored) |
| 116 | |
| 117 | Gate: environment reason, protocol, lines, binary, sensitive paths, |
| 118 | special entries, ships, policy mode, hold, exact revert, first-ready |
| 119 | eligibility, sandbox, never for a person, incomplete facts (first |
| 120 | survived; a case added), stance, Tighter on ships, glob depth, camel-case |
| 121 | tokens, rename old path: all killed. Wire: purpose, change facts and the |
| 122 | downgrade step: killed. Runner: ancestry, entry bound, mode change, |
| 123 | symlink, gitlink, new executable, signing, binary, rename, revert on-top, |
| 124 | revert tree: killed; ConfirmMerge replaced by the plain lease, the |
| 125 | refusal ignored, the start refusal as a cancel, mislabelled hub and |
| 126 | cached sources, parents for any source: killed; the refusal reason |
| 127 | mapping first survived (no test), then extracted and killed by |
| 128 | `TestLeaseRefusalReasons`; the launcher allowlist: killed by |
| 129 | `TestConversePolicyCoversEveryTool`. Instance: the fence at the lease and |
| 130 | at dispatch, the confirmation re-check, the checked-merge re-check at |
| 131 | confirmation (first mutation did not loosen; the real loosening killed), |
| 132 | the `merge_asked` guard, Merge retrying a failed attempt, verified |
| 133 | landing, Undo's ask mode, facts acceptance, the receipt, deciding while |
| 134 | offline, the ships question once (first survived; a second asking task |
| 135 | added), the policy tool's tighter-only rule, the audit row, the revert |
| 136 | target, a teammate's Undo: all killed. Three first runs that died only on |
| 137 | a build failure were redone as valid mutations. |
| 138 | |
| 139 | ## Copy for review |
| 140 | |
| 141 | 84 strings in `internal/equipo/copy.go`, each `COPY REVIEW REQUIRED`, each |
| 142 | in the Plan 3 copy inventory (`CONTROLLER-REPORT-plan-3.md`): the card's |
| 143 | stances and phrases (`chat.merge.*`), Wait for a Mac, the ships question |
| 144 | and its answers, the policy confirm card, the receipt, the revert title, |
| 145 | the ask-mode reason, `work.reason.merge_not_authorized` and the project |
| 146 | page section (`work.merge_policy.*`). Model-facing texts (tool results, |
| 147 | the two tool descriptions, the house-rule sentence) are not runtime copy. |
| 148 | |
| 149 | ## Not in v1 |
| 150 | |
| 151 | Verification on the merged commit, the trust counter, automatic fix |
| 152 | tasks, a revert step, a same-SHA checks retry after Wait, and the forge's |
| 153 | tip fallback fix for every merge (a separate issue). |
| 154 | |
| 155 | ## Astra branch review (one round, on 4d37307): REQUEST CHANGES |
| 156 | |
| 157 | 1. Critical, protocol 1 bypasses the lease fence: fixed. The fence now |
| 158 | also runs when a runner connects below `wire.ProtocolMergeFacts` |
| 159 | (`fenceOldRunner` in `Connect`): every automatic merge attempt placed |
| 160 | on it is settled failed `merge_not_authorized`, an unsent dispatch is |
| 161 | never sent, a received one is cancelled, and the person is asked. |
| 162 | `TestContractMergeFenceOldRunner` covers a 4 to 2 and a 4 to 1 |
| 163 | reconnect. Mutations (no fence at connect, no cancel) killed. Limit: |
| 164 | an older build already mid-request when it reconnects cannot be |
| 165 | stopped by the instance; the forge record and the merge watch settle |
| 166 | that landing. |
| 167 | 2. Critical, a Mac re-run re-arms an asked SHA: not changed. The |
| 168 | controller ruled that a re-run pass on the exact candidate merges a |
| 169 | routine change on its own through `authorizeMerge` (sensitive, |
| 170 | shipping, held and asking cases ask); this is that ruling, reported |
| 171 | back as a product decision. |
| 172 | 3. Important, open cards miss later holds and policy changes: fixed. |
| 173 | `refreshMergeCards` re-decides (audited as `card_refresh`, never shown |
| 174 | as the task's decision, never acted on) and rewrites an open card's |
| 175 | words and options with a new revision on `hold_merge` and every |
| 176 | policy change. `TestContractCardRefresh`; mutations (no refresh on a |
| 177 | hold, words not rewritten) killed. |
| 178 | 4. Important, Undo not bound to the receipt: fixed. Undo needs the open |
| 179 | receipt offering it (only Equipo's own merge without checks with a |
| 180 | hub-named merge commit has one) and its current revision on both the |
| 181 | card and `POST /api/v1/tasks/{id}/undo-merge` (`{"revision": n}`). |
| 182 | `TestContractUndoMerge` adds a person's merge with the hub's answer |
| 183 | (no Undo) and a stale revision (409); mutations killed. |
| 184 | |
| 185 | ## The ruling on Critical 2 (Mac re-runs of an asked SHA) |
| 186 | |
| 187 | The controller ruled: a re-run's pass on the exact candidate may merge |
| 188 | on its own (through `authorizeMerge`) only when the card asked solely |
| 189 | because checks could not run, or the person chose Wait for a Mac on that |
| 190 | SHA's card. For any other reason the SHA stays asked and the card is |
| 191 | re-decided as a `card_refresh`. No new column: the reason is the SHA's |
| 192 | newest `decision` or `card_refresh` audit row (`recheckMayMerge`); no |
| 193 | row counts as another reason (fails closed). The Wait is read from the |
| 194 | task's newest merge card, so a Wait on an earlier SHA never counts. |
| 195 | `recheckMac` withdraws the card and clears `merge_asked` only when the |
| 196 | pass may merge; otherwise `autoMerge` keeps the SHA asked and |
| 197 | re-decides the card once after the re-run finishes |
| 198 | (`refreshAfterRecheck`). |
| 199 | |
| 200 | `TestContractMacRecheckMergeAuthority` through the real recheck path: |
| 201 | Wait chosen merges; checks only merges (its reason is seeded, since the |
| 202 | gate never asks a needs_macos change for checks alone); sensitive, held |
| 203 | and main ships stay asked with the same card refreshed; a missing reason |
| 204 | stays asked; a pass on another SHA counts for nothing. |
| 205 | `TestContractMacRecheckOnlyWaiting` now expects the waiting task's card |
| 206 | to stay open. Mutations, each killed: checks-only predicate off (checks |
| 207 | only), Wait ignored (Wait chosen), any failing criterion treated as |
| 208 | checks only (sensitive, held, ships), no row treated as may-merge |
| 209 | (missing reason), no refresh after the re-run (sensitive, held, ships), |
| 210 | the re-run withdrawing the card regardless (sensitive, held, ships). |
| 211 | |
| 212 | Operating rule (spec §10a): deploy with no merge in flight. An older |
| 213 | build already part-way through a hub merge request when the instance |
| 214 | swaps cannot be stopped by the fence; restart the runners on the new |
| 215 | build right after the swap. |
| 216 | |
| 217 | ## Copy: delegated review (Astra, 2026-11-11) |
| 218 | |
| 219 | The 84 strings went through Astra as the copy-review gate (Paul's |
| 220 | delegation of 2026-10-25): 55 kept, 29 changed, applied verbatim, each |
| 221 | now `COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11)` in `copy.go` and in |
| 222 | the Plan 3 inventory. The changes move the project page and the card |
| 223 | phrases to Equipo's first person ("I ask before every merge in this |
| 224 | project", "Merged on my own"), say "main branch" in the shipping |
| 225 | phrases and question, and tighten the size, eligibility, receipt, |
| 226 | stale-card and Stopped wording. Tests that quote them updated. |
| 227 | |