oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1# Equipo merge authority, thin v1
2
3Status: 2026-11-11, revision 3.1 ("thin v1"), being built. Revision 3
4drew REQUEST CHANGES from Astra round 3 (the last round); Paul chose
5"Refuse old runners" for its Critical, and the controller directed the
6other four findings. Those rulings are folded in (§13).
7Revision 1 (7eba9c8) and revision 2 (4ab106f) drew REQUEST CHANGES from
8Astra; the controller cut the scope (§11 lists what moved to v2, §12
9maps the round 2 findings). Drafted by Claude (Opus 5.5) on
10`merge-authority` from main ac4a809. Builds on slice 4c
11(`docs/superpowers/plans/SLICE4C-PROGRESS.md`) and the housekeeping
12decision classes (`2026-11-08-equipo-housekeeping.md` §3). Not
13implemented.
14
15## 0. Why, and the shape
16
17Paul, on the card "Merge Swipe from the edge to go back doesn't work
18without checks? [Merge] [Wait for checks]": "How do we give the
19co-ordinator authority to merge stuff like this? I think it needs to be
20able to make a decision ... we can give it heuristics and best
21practice." Equipo decides, and asks only when its policy says so.
22
23Thin v1 is one rule checked at one moment: **right before Equipo sends a
24merge request to the hub, a pure function on the instance decides
25whether Equipo may send it on its own.** Nothing is queued on a
26decision; a decision that is not "merge now" leaves the task where
27today's code leaves it, with a better card.
28
29Invariants, each tested:
30
311. **The gate is code, on the instance.** No model output can make it
32 merge. A runner supplies measured facts; missing facts mean ask.
332. **Never looser.** The coordinator can only tighten. Loosening needs
34 an owner's tap or form.
353. **One door.** Every merge request goes through `authorizeMerge`
36 synchronously, with the hub's `expect_sha`, and each call writes one
37 audit row.
384. **Never retroactive.** Only a candidate whose review ran on a
39 `wire.ProtocolMergeFacts` runner after the upgrade can merge without
40 checks on its own; an open card is never re-decided automatically.
415. **Refuse old runners** (Paul). Every automatic merge, checks passed
42 included, needs the primary at `wire.ProtocolMergeFacts` both when the
43 step is dispatched and at every hub request. A lower protocol is
44 refused, never downgraded, and the decision becomes an ask card with a
45 recommendation. Code names the capability, never a protocol number.
46
47## 1. Decision classes
48
49| Class | Meaning | What happens |
50|---|---|---|
51| `act` | Equipo may send the merge request now | the request goes; a receipt (§6) |
52| `ask` | approved, but a criterion of §2.3 fails | the merge card, once per SHA, worded as Equipo's call (§4) |
53| `never` | not approved, checks failed or running, branch moved, task ended, cancelled or merging already | nothing (fix rounds and Needs you as today) |
54
55The housekeeping principal may still never merge, open a merge card or
56change a merge policy (`hkForbid`, unchanged).
57
58## 2. The gate
59
60### 2.1 `mergegate.Decide`
61
62New package `internal/equipo/mergegate`, pure (no store, clock or I/O).
63
64```go
65type Inputs struct {
66 Candidate string // newest pushed candidate; "" when the branch moved
67 Verdict string // newest finished review verdict on Candidate
68 Checks string // passed | failed | none | cannot_run | "" (running)
69 ChecksReason string
70 OutsideSandbox bool // checks_sandbox none
71 Eligible bool // k.MergeEligible == Candidate (slice 4c)
72 Person bool // a person chose Merge for this SHA (§2.4)
73 Change *ChangeFacts // §3; nil when missing or refused
74 Protocol int // the primary's protocol on its current connection
75 Policy Policy // §7; defaults when no row
76 Hold string // §4.3
77 Revert *RevertCheck // §6; only for a revert task
78}
79
80type Criterion struct{ Name string; OK bool; Value, Limit string }
81
82type Decision struct {
83 Class string // act | ask | never
84 Stance string // merge | wait, for ask
85 Checks bool // act with checks passed
86 Reasons []Criterion // every criterion evaluated, fixed order
87}
88
89func Decide(in Inputs) Decision
90```
91
92### 2.2 Order
93
941. **Never** when `Candidate == ""`, `Verdict != approve`, `Checks ==
95 failed` or `Checks == ""`.
962. **A person's Merge** (`Person`): `act`. The person decided; holds
97 and policy are shown on the card they answered, not re-applied.
983. **Checks passed**, not outside the sandbox, `Eligible`: `act` with
99 `Checks: true` unless `Policy.Mode == ask` or `Hold != ""` (then
100 `ask`, options Merge, Not now). Not eligible: `ask` (slice 4c's adopt
101 card). Outside the sandbox: `ask`, as today. The runner must speak
102 `wire.ProtocolMergeFacts` here too (Refuse old runners). A pass from a
103 Mac re-run (mac-recheck, `chat_steps.recheck_by`) on the exact
104 candidate is eligible when the passing result lands. The controller's
105 ruling on an asked SHA: the re-run's pass may merge on its own (still
106 through `authorizeMerge`, judged like a merge without checks less the
107 environment rule) only when the card asked solely because checks
108 could not run (the SHA's newest `decision` or `card_refresh` audit row
109 fails `environment_reason` alone) or the person chose Wait for a Mac
110 on that SHA's card; then the re-run withdraws the card. For any other
111 reason (sensitive, large, ships, held, ask mode, or no recorded reason,
112 which fails closed) the SHA stays asked: the card stays open and the
113 pass re-decides its words once, as a `card_refresh` (audited, never
114 acted on). A SHA never asked about decides afresh as usual. A re-run
115 that fails takes the normal fix round; a result on another SHA counts
116 for nothing.
1174. **Without checks**: `act` only when ALL hold, else `ask`:
118
119| Criterion | Holds when |
120|---|---|
121| `approved_exact_sha` | `Verdict == approve` on `Candidate`, branch at it |
122| `environment_reason` | `Checks == cannot_run`, `ChecksReason` in `{needs_macos, runner_offline}` |
123| `runner_reports_facts` | `Protocol >= 3` |
124| `facts_present` | `Change != nil` (accepted under §3.4) |
125| `small` | `Change.Lines <= Policy.MaxLines`, `Change.Files <= Policy.MaxFiles`, `Change.Binary == 0` |
126| `not_sensitive` | no old or new path matches §3.3, `!Change.Special`, `!Change.Signing` |
127| `main_does_not_ship` | `Policy.MainShips == no`, answered by an owner (§7.3) |
128| `policy_allows` | `Policy.Mode == rules` |
129| `no_hold` | `Hold == ""` |
130| `revert_exact` | only for a revert task: §6.3 |
131
132`none`, `checks_timeout`, `checks_unavailable` and `needs_network` are
133not environment reasons and always ask. No policy value waives a
134criterion; size applies in every mode.
135
136### 2.3 `authorizeMerge(task, candidateSHA)`
137
138`func (t *txn) authorizeMerge(k *taskRecord, sha, at string, person bool)
139(Decision, error)` builds the inputs inside the write transaction (the
140current roster is checked there for `person`: the creator, still an
141owner), calls `Decide`, writes one audit row (§8) and returns the
142decision. It is the only function that may return `act`, and it is
143called at two moments:
144
145**(a) Before dispatch.** The only code that creates a merge step,
146`startMerge`, calls it first and creates the step only on `act`.
147Callers of `startMerge`:
148
149| Caller | `person` | Natural trigger |
150|---|---|---|
151| `autoMerge` from `advance` | false | the candidate is at Ready to merge, on any report or sync |
152| `answerMerge` (Merge) | true | the person's tap |
153| `MergeTask` (task page Merge) | true | the person's tap |
154| merge Retry | true | the person's tap |
155
156`autoMerge` calls it only while the task has no merge card for this SHA
157(`merge_asked != candidate`) and no merge step for this SHA has ended.
158So once Equipo asked, only the person acts, and a failed automatic
159attempt is not repeated on its own (Ready to merge with the reason and
160Retry, as today). On `ask` it raises the card and sets `merge_asked`; on
161`never` it does nothing.
162
163**(b) Right before each hub request.** The runner's forge calls
164`Confirm` immediately before every hub merge request: the first, a
165re-request after an uncertain answer, and every resumption while the
166hub's own CI is pending (`internal/runner/forge/merge.go`,
167`MergeBranch`; it inspects the remote first, so a request already sent
168is settled from the default branch before any new request). A protocol
1693 runner sends that `Confirm` as a lease check with the new optional
170`purpose: "merge_request"` (beside the existing `publication`
171purpose). `Store.Authorize` for that purpose:
172
173- re-runs `authorizeMerge` (with `person` from the merge step's
174 `decided_by`), on every call, after the ordinary attempt checks;
175- on `act`, grants;
176- otherwise refuses with the reason `merge_not_authorized`, and in the
177 same transaction raises the ask card for the SHA (once) when the
178 class is `ask`.
179
180The runner maps that refusal to a terminal failure `merge_not_authorized`
181before anything is sent (the forge record stays `prepared`; `Confirm`
182runs before the record moves to `requested`). The instance applies it as
183any other non-conflict merge refusal: back at Ready to merge, with the
184card. Nothing is withdrawn, so `withdrawnSettle` is not involved, and
185the step's first lease (which only starts the step, before any
186inspection) is unchanged.
187
188**No queued automatic merge.** `autoMerge` decides only when the
189person's primary is online; the gate's `runner_protocol` criterion then
190needs it at `wire.ProtocolMergeFacts` for every automatic merge, checked
191or not. Offline, nothing is decided or created and the next sync's
192`advance` is the next trigger. A person's Merge may wait
193for the primary as today. The runner's existing bounded wait while the
194hub's CI is pending (10 minutes) holds no decision: each resumption
195calls `Confirm`, which decides again.
196
197**Runners below `wire.ProtocolMergeFacts`** never get an automatic
198merge: at dispatch the gate asks (stance merge when only the protocol
199fails: "your runner needs an update before I merge on my own"). The
200fence: when a runner holding an automatic merge step reconnects below
201that protocol, every lease it asks for that step is refused
202`merge_not_authorized`, whatever it carries (its purpose is dropped by
203`Encode`), and the attempt is settled failed in the same transaction
204with the ask card raised. A request such a runner already sent before
205it reconnected is settled by the merge watch, which reports the
206landing as today. There is no dispatch-only path: a person's Merge is
207the only merge an older runner carries, and their decision stands.
208
209**Merge on the card after a refusal.** The card's Merge (and the task
210page's) accepts a candidate whose newest merge step failed and ended:
211it runs that step again as its next attempt, decided by the person.
212
213### 2.4 What a person's Merge means
214
215A person's Merge (card, task page, Retry) is `decided_by: person:<id>`
216on the merge step. It is bound to the SHA by `expect_sha` and to the
217person by the roster check at both moments. It is not stored anywhere
218else and never outlives the step.
219
220## 3. Change facts
221
222### 3.1 What the runner measures
223
224New optional `wire.ChangeFacts` on the Review step's report, sent only
225on a protocol 3 connection:
226
227```go
228type ChangeFacts struct {
229 ReviewStep string `json:"review_step"`
230 Attempt int64 `json:"attempt"`
231 Repo string `json:"repo"`
232 Base string `json:"base"` // merge-base(task base, candidate)
233 SHA string `json:"sha"` // the candidate
234 Files int `json:"files"`
235 Lines int `json:"lines"` // added + deleted, text files
236 Binary int `json:"binary"`
237 Special bool `json:"special"`
238 Signing bool `json:"signing"`
239 Entries []Entry `json:"entries"`
240 Complete bool `json:"complete"`
241 Revert *RevertCheck `json:"revert,omitempty"` // §6.3
242}
243type Entry struct {
244 Status string `json:"status"`
245 Old string `json:"old"`
246 New string `json:"new"`
247 OldMode string `json:"old_mode"`
248 NewMode string `json:"new_mode"`
249}
250```
251
252Computed with no model, in the review tree, from the exact pair:
253`git diff --raw -z -M --no-abbrev <base> <sha>` (status, both paths of
254a rename or copy, modes), `git diff --numstat -z -M <base> <sha>`
255(lines; `-` is binary) and `git diff -U0 <base> <sha> --` limited to
256`.pbxproj`, `.xcconfig` and `Info.plist` files (the signing rule). The
257two listings must name the same entries; disagreement, an error, or
258more than 200 entries gives `Complete: false`.
259
260### 3.2 Special entries
261
262`Special` when any entry has mode `120000` (symlink) or `160000`
263(gitlink) on either side, or its old and new modes differ, or it adds a
264file with mode `100755`.
265
266### 3.3 Sensitive areas
267
268A table in `mergegate/sensitive.go`, matched against the old and the
269new path of every entry, case-insensitive. Tokens are path segments
270split on `/`, `.`, `-`, `_` and lower-to-upper case changes, matched
271whole (`keyboard` is not `key`). Every glob matches at any depth.
272
273| Class | Globs | Tokens |
274|---|---|---|
275| `migrations` | `**/migrations/**`, `**/migrate/**`, `**/*.sql`, `**/schema.*`, `**/*.prisma` | `migration`, `migrations`, `schema` |
276| `auth_secrets` | `**/.env*`, `**/*.pem`, `**/*.key`, `**/*.p12`, `**/*.p8`, `**/*.keystore`, `**/*.jks` | `auth`, `authn`, `authz`, `oauth`, `oidc`, `saml`, `jwt`, `login`, `logout`, `signin`, `signup`, `session`, `sessions`, `password`, `passwords`, `passwd`, `credential`, `credentials`, `secret`, `secrets`, `token`, `tokens`, `key`, `keys`, `keychain`, `crypto`, `cipher`, `encrypt`, `decrypt`, `cert`, `certs`, `certificate`, `tls`, `ssl`, `permission`, `permissions`, `acl`, `rbac` |
277| `payments` | | `payment`, `payments`, `billing`, `stripe`, `checkout`, `invoice`, `invoices`, `subscription`, `subscriptions`, `purchase`, `purchases`, `storekit`, `iap`, `paywall`, `refund`, `refunds` |
278| `ci_config` | `**/.amadan/**`, `**/.github/**`, `**/.gitlab-ci.yml`, `**/.circleci/**`, `**/.buildkite/**`, `**/Makefile`, `**/GNUmakefile`, `**/makefile`, `**/*.mk` | |
279| `dependencies` | `**/go.mod`, `**/go.sum`, `**/go.work*`, `**/package.json`, `**/package-lock.json`, `**/npm-shrinkwrap.json`, `**/yarn.lock`, `**/pnpm-lock.yaml`, `**/bun.lock*`, `**/Cargo.toml`, `**/Cargo.lock`, `**/Gemfile*`, `**/requirements*.txt`, `**/pyproject.toml`, `**/poetry.lock`, `**/Pipfile*`, `**/uv.lock`, `**/Package.swift`, `**/Package.resolved`, `**/Podfile*`, `**/Cartfile*`, `**/*.gradle*`, `**/gradle.lockfile`, `**/composer.json`, `**/composer.lock`, `**/mix.exs`, `**/mix.lock`, `**/.gitmodules`, `**/vendor/**` | |
280| `release_signing` | `**/*.entitlements`, `**/*.mobileprovision`, `**/ExportOptions*.plist`, `**/fastlane/**`, `**/*.xcconfig`, `**/.goreleaser*`, `**/VERSION` | `release`, `releases`, `signing`, `entitlements`, `provisioning` |
281| `infrastructure` | `**/*.tf`, `**/*.tfvars`, `**/*.hcl`, `**/Dockerfile*`, `**/docker-compose*`, `**/*.service`, `**/fly.toml`, `**/vercel.json`, `**/netlify.toml`, `**/render.yaml`, `**/Procfile`, `**/app.yaml`, `**/carlos.toml` | `terraform`, `ansible`, `pulumi`, `cloudformation`, `infra`, `infrastructure`, `deploy`, `k8s`, `helm` |
282
283**Signing**: an added or removed line in a `.pbxproj`, `.xcconfig` or
284`Info.plist` naming `CODE_SIGN`, `DEVELOPMENT_TEAM`,
285`PROVISIONING_PROFILE`, `ENTITLEMENTS`, `PRODUCT_BUNDLE_IDENTIFIER`,
286`MARKETING_VERSION`, `CURRENT_PROJECT_VERSION`, `CFBundleVersion` or
287`CFBundleShortVersionString`. A `.pbxproj` change that only adds a file
288reference is not sensitive by itself.
289
290A project may add globs (`extra_sensitive`, at most 20, each <= 200
291bytes). Nobody can remove a default.
292
293### 3.4 Acceptance
294
295Stored on the review step (`change_facts`) only when: the report comes
296from the person's primary and the runner the step is placed on, on a
297protocol 3 connection; `ReviewStep` and `Attempt` are this step's
298current attempt; `Repo` is the task's project; `SHA` is the step's
299`CandidateSHA`; `Base` is a valid SHA; `Complete`; the counts match the
300entries; every path passes `cleanPath`; every mode is one of git's.
301Otherwise dropped (the verdict still counts; `facts_present` fails).
302`Decide` reads only the facts on the review step whose verdict it uses.
303
304## 4. Asking, with a recommendation
305
306### 4.1 The card
307
308The existing `merge` card, once per SHA, in the creator's conversation,
309its question composed by the instance from the decision:
310
311- `Stance: merge` when the only failing criteria are `small` or
312 `policy_allows`: "I'd merge: %s." with up to three passing phrases
313 ("approved by Review", "a small change, %d lines in %d files",
314 "nothing ships until a release").
315- `Stance: wait` otherwise: "I'd wait: %s." with up to two failing
316 phrases ("it touches payments (%s)", "I don't know yet whether %s's
317 main ships to users", "the runner didn't say what changed", "this
318 project asks before every merge", the coordinator's hold text).
319
320Options: `needs_macos`, or `runner_offline` with a macOS need:
321**Merge**, **Wait for a Mac**; other cannot-run reasons and `none`:
322**Merge**, **Wait for checks**; checks passed but asked: **Merge**,
323**Not now**.
324
325### 4.2 Wait
326
327Wait only waits; it is never consent. The task stays at Ready to merge
328with Merge offered (today's behaviour), and nothing re-runs the checks
329on the same SHA in v1 (a checks retry on the same SHA is v2). The
330`merge_asked` guard stays: once Equipo asked about a SHA, only the person
331acts on it; nothing (a policy answer, a sync, a later checks result)
332re-arms the automatic merge for that SHA.
333
334### 4.3 The coordinator: stricter only
335
336- Tool `hold_merge{task, reason}` (own task; stage before Done,
337 including Ready to merge and Merging before the hub request): sets
338 `merge_hold` (plain text, <= 200 bytes). `Decide` then never acts on
339 its own for that task; an automatic request not yet sent is refused at
340its `Confirm`. A person's Merge is not refused by a hold (they saw it on
341the card).
342 No tool releases a hold; a person's Merge is the release for that SHA.
343- The coordinator's words reach the gate only as `Hold`.
344- `read_task` shows the newest decision (class, stance, reasons).
345
346## 5. What happens on the hub's answer
347
348`mergeDone` gains the landing's provenance, from new optional fields on
349the merge step's report (protocol 3):
350
351- `merge_source`: `hub` when the SHA is from this request's `200
352 {merged, sha}` answer; `reconciled` when the forge settled it from
353 the default branch; `cached` when it returned an earlier record.
354- `merge_parents`: the merge commit's parents, read from the fetched
355 default branch after the answer (empty if the fetch failed).
356
357`forge.MergeOutcome` gains `Source` to carry this; the forge's other
358behaviour is unchanged. The forge's fallback at
359`internal/runner/forge/merge.go:243` (substituting the tip when the
360landing commit is not found) is **not** changed here; it is filed as a
361separate small issue for every merge. Instead, for an automatic merge
362without checks, the instance treats any report whose `merge_source` is
363not `hub`, or whose `merge_parents` are not exactly two with the
364candidate second (the hub's merge commit), as **unverified**: the task is done (the
365commit is on the default branch), `merge_verified` is false, the
366receipt has no Undo, and the audit row says `landed_unverified`.
367
368## 6. Receipt and Undo
369
370### 6.1 The receipt
371
372An `act` merge without checks writes, in `mergeDone`'s transaction, a
373receipt card (kind `merge_receipt`) in the creator's conversation
374instead of the `chat.merged_without_checks` line, idempotent per task
375(`merged:<task>`, the existing key): "Merged [%s](%s) into %s without
376checks: %s." (`%s` the passing phrases of §4.1). It is visible at once,
377bound to the task (`task_id`), revision 1. Undo is offered only when
378`merge_verified` and for 7 days (`housekeeping.UndoWindow`). Merges with
379checks passed and a person's merges keep today's lines and no receipt.
380
381### 6.2 Undo creates an ordinary task
382
383The creator's Undo (card answer `undo`, or `POST
384/api/v1/tasks/{id}/undo-merge`, owner, current card revision) creates, in
385one transaction, an ordinary task through the store's task insert (no
386similarity check), title "Revert %s in %s" (short SHA, project), brief
387"Revert merge commit <sha> with `git revert -m 1 <sha>` and change
388nothing else.", `revert_of` = the task, `revert_sha` = the verified
389merge SHA, and starts it as `start_task` does (owner, execution on).
390It then runs Engineering, checks, Review and the gate like any task.
391The receipt's revision grows and it shows "Reverting: [%s](%s)."
392
393Refused (409, with a line to the creator) when not verified, outside the
394window, or a revert task for it exists; a teammate gets 404, a non-owner
395403.
396
397Any Undo puts the project in ask mode at once (§7.2: `mode: ask`,
398reason `reverted <sha>`), until an owner says otherwise.
399
400### 6.3 Exact revert
401
402The revert target travels to the runner as an optional `revert_sha` on
403the Review step's dispatch (protocol 3). The runner adds to the change
404facts `revert: {sha, on_top, exact}`: `on_top` when the candidate's
405parent is the reverted merge commit itself, and `exact` when
406additionally the candidate's tree equals that merge commit's first
407parent's tree (`git rev-parse <candidate>^{tree}` and `<sha>^1^{tree}`).
408`revert_exact` holds only for `on_top && exact` for the task's
409`revert_sha`. A revert made after main moved on, or one that changed
410more, is asked about. Since Undo sets ask mode, the revert task asks
411anyway in v1; `revert_exact` makes the card's stance merge ("I'd merge:
412it exactly reverts %s.").
413
414## 7. Policy per project
415
416### 7.1 Storage
417
418Migration **0061** (main has 0058 project stars, 0059 usage rounds and 0060 Mac recheck;
419the next free number if another branch lands 0060 first). Tables `chat_merge_policies` and `chat_merge_audit`;
420columns `chat_steps.change_facts`, `chat_steps.decided_by`,
421`chat_steps.merge_source`, `chat_steps.merge_parents`,
422`chat_tasks.merge_hold`, `chat_tasks.merge_verified`,
423`chat_tasks.revert_of`, `chat_tasks.revert_sha`. Additive; registered in
424`chat.Models` and `Schema`; the migration check covers them.
425
426`chat_merge_policies` (team record, one row per project):
427`project_id`, `mode` (`rules` | `ask`), `mode_reason`, `max_lines`
428(default 300, 0 to 2000), `max_files` (default 15, 0 to 100),
429`main_ships` (`unknown` | `yes` | `no`), `ships_answered_by`,
430`ships_asked` (bool), `extra_sensitive` (JSON), `words` (<= 300 bytes,
431display only), `revision`, `updated_by`, `updated_at`. No row means
432`rules`, 300, 15, `unknown`.
433
434### 7.2 Setting it
435
436- **In conversation**: tool `set_merge_policy{project, words, mode?,
437 max_lines?, max_files?, main_ships?, add_sensitive?}`. Each field is
438 compared with the stored one. If every changed field is tighter (to
439 `ask`, smaller numbers, `main_ships: yes`, added globs), it applies at
440 once, with one coordinator line and an audit row. If any is looser,
441 nothing applies: a confirm card "Change how Equipo merges %s: %s?
442 [Save] [Cancel]" goes to the person, and Save (an owner, current
443 policy revision) applies all of it. "for Woodstar, merge when Review
444 approves" is `mode: rules` (and the ships answer); "always ask me
445 about Suite" is `mode: ask`. The instance never parses the words.
446- **On the project page**: a section "How Equipo merges" (partial
447 `merge_policy.html`, one include line in `work_project.html`, to stay
448 clear of the Projects and Tasks work) shows the policy in plain
449 sentences, the words, the mode reason, and the last five decisions
450 with their reasons. An owner's form edits the fields (CSRF, policy
451 revision, current roster); teammates see it read only.
452- `GET/PUT /api/v1/projects/{id}/merge-policy` mirror the form.
453
454### 7.3 Does main ship to users?
455
456`main_ships` starts `unknown`, which fails `main_does_not_ship`. When a
457decision fails on it and `ships_asked` is false, the same transaction
458sends one card to the task's creator if they are an owner: "Does
459merging to %s's main ship to users? [It ships] [It doesn't]", and sets
460`ships_asked`. An owner's answer on the current policy revision sets
461`main_ships` and `ships_answered_by`, with an audit row. It applies to
462decisions made after it: the card already open for that task stays open
463until the person acts, because `autoMerge` never decides a SHA that has
464a card (§2.3). Nothing in the repository is evidence either way. The
465project page edits it too.
466
467## 8. Audit
468
469`chat_merge_audit`, append only: `id`, `project_id`, `task_id`, `kind`
470(`decision`, `answer`, `merged`, `landed_unverified`, `undo`,
471`policy`, `ships`, `hold`), `at` (`dispatch`, `confirm`,
472`dispatch_only`, or the form or tool), `candidate_sha`, `merge_sha`,
473`class`, `stance`, `decided_by` (`policy`, `person:<id>`,
474`coordinator:<id>`), `reasons` (every criterion), `inputs` (counts, the
475first ten matched paths, policy revision, protocol, checks reason,
476review label, hold), `created_at`. Written in the transaction of the
477effect, with the instance's audit event as every write; a rolled-back
478effect leaves no row; a replayed report adds none (keyed on step,
479attempt and kind).
480
481## 9. Wire and versions
482
483`wire.ProtocolMergeFacts` (protocol 4; spend-1's protocol 3 is
484`wire.ProtocolSpend`), all new fields
485optional and `omitempty`:
486`StepReport.change`, `StepReport.merge_source`,
487`StepReport.merge_parents`, `LeaseCheck.purpose`,
488`DispatchCommand.revert_sha`. `wire.Encode` clears them for any peer
489below `wire.ProtocolMergeFacts` (its own downgrade step, chained after
490the others). Instance first, then runners, as today.
491
492| Combination | Behaviour |
493|---|---|
494| new instance, runner below `ProtocolMergeFacts` | every automatic merge asks (Refuse old runners); a person's Merge works as today |
495| old instance, new runner | protocol 2 welcome: the new fields are never sent |
496| a runner reconnects below it holding an automatic merge | the fence refuses its leases for that step; settled, asked |
497
498## 10. Tests
499
500Built on this branch (targeted `-run` locally; `make ci` with
501`CGO_ENABLED=0` on hosted CI is the final gate, never on docs-t1). Each
502guard is broken in turn and a test watched failing (progress log).
503
504**Gate (`internal/equipo/mergegate`)**: `TestDecideEachCriterion`,
505`TestDecideNever`, `TestDecideChecksPassedPath` (protocol included),
506`TestDecidePersonMerge`, `TestDecideStance`, `TestDecideNeverLooser`
507(20,000 random inputs against an independent oracle),
508`TestSensitivePaths`, `TestValidPolicy`, `TestTighter`.
509
510**Wire**: `TestWireProtocol3Downgrade` (a `ProtocolMergeFacts` frame is
511unchanged there and loses every merge authority field one protocol
512below and at protocol 1).
513
514**Runner**: `TestReviewReportsChangeFacts`, `TestRevertCheck`,
515`TestMergeConfirmPurpose`, `TestMergeSource`, `TestLeaseRefusalReasons`.
516
517**Store contracts (`internal/thintest`)**:
518`TestContractMergeAuthorityAct`, `TestContractMergeAuthorityAsks`,
519`TestContractMergeFenceOldRunner` (protocol 1 at dispatch, checks passed
520included; reconnect below the protocol refused at the lease and asked;
521Merge on the card retries the failed attempt), `TestContractConfirmRechecks`
522(a hold on a checked merge, ask mode on an unchecked one, between
523dispatch and request), `TestContractNoQueuedAutoMerge`,
524`TestContractShipsQuestion`, `TestContractWaitNeverMerges`,
525`TestContractUndoMerge` (revert task, ask mode, revert target and exact
526revert on review, teammate 404, second Undo 409, an unverified landing
527has no Undo), `TestContractMergePolicyTool` (tighter, looser card,
528bounds, member read only, the project page section),
529`TestContractFactsAcceptance`, `TestContractRosterDenial`. The slice 4c
530merge contracts and the page tests that end in Equipo's merge run on a
531`ProtocolMergeFacts` runner; at protocol 1 they now ask.
532
533Gates kept green: `make budget`, gofmt, `go vet ./internal/...`,
534`scripts/runner-dead-references.py`, `TestPlan3ReleaseBoundaries`, the
535migration and model check.
536
537### Copy inventory
538
539All in `internal/equipo/copy.go`, each marked `COPY REVIEW REQUIRED`,
540each listed in the Plan 3 copy inventory: the card stances and phrases
541(§4.1); "Wait for a Mac"; the receipt and "Reverting: [%s](%s)." (§6);
542Undo's refusal lines; "Merged [%s](%s), but I couldn't tell which commit
543on main it is, so I can't undo it."; the ships question and its two
544answers (§7.3); the policy confirm card and the tightening line (§7.2);
545the project page section's sentences; the `hold_merge` and
546`set_merge_policy` tool descriptions; the Stopped line for
547`merge_not_authorized`.
548
549## 10a. Operating rule: deploy with no merge in flight
550
551The fence for older runners (§2.3) settles every automatic merge step
552the moment such a runner connects. What it cannot stop is an older build
553that is already part-way through a hub merge request when the instance
554changes: that request goes on, and the forge record and the merge watch
555settle its landing afterwards. So deploy with no merge in flight: before
556an instance swap, check that no merge step is queued or running, and
557restart every runner on the new build right after it. A runner that has
558never connected, or installs from `install.sh`, gets the new build.
559
560## 11. Moved to v2
561
562- Verification on the merged commit when checks can run, as its own
563 durable record.
564- The trust counter with generations and credits.
565- Automatic fix-task intents after a failed verification.
566- A deterministic revert step (v1's Undo is an ordinary task).
567- Fixing the forge's tip fallback for every merge (a separate issue).
568
569## 13. Round 3 findings and the rulings
570
5711. Critical, a runner reconnecting below the protocol: Paul chose
572 "Refuse old runners" (invariant 5, §2.3 fence).
5732. Clearing `merge_asked`: the guard stays; nothing re-arms (§4.2).
5743. Merge after a confirmation refusal: the card's Merge retries the
575 failed, ended attempt (§2.3).
5764. The same-SHA checks retry: removed from v1 (§4.2), v2.
5775. `make ci` with `CGO_ENABLED=0` on hosted CI is the final gate (§10).
578
579## 12. Round 2 findings and where they went
580
5811. Wait as consent: Wait never consents (§4.2).
5822. Open card reconsidered: `autoMerge` never decides a SHA that has a
583 card (§2.3, §7.3).
5843. Withdrawal versus reconciliation: no withdrawal; a refused
585 `merge_request` lease before any request, after inspection (§2.3);
586 holds allowed while Merging (§4.3).
5874. Guessed landing: provenance from the hub answer and parents; anything
588 else is unverified with no Undo; the forge fallback is a separate
589 issue (§5).
5905. and 6., 7. Verification, trust and fix intents: moved to v2 (§11).
5918. Revert target and exactness: `revert_sha` on the dispatch; tree
592 equality on top of the merge commit (§6.3).
5939. Protocol 1: automatic merges without checks need protocol 3; older
594 runners are gated at dispatch only, as recorded (§2.3, §9).
59510. Receipt rules and copy inventory restored (§6.1, §10).
596