Spec: merge authority revision 3, thin v1 (scope cut)
One gate, authorizeMerge, before dispatch and synchronously before each hub request through a merge_request lease; no queued automatic merge; Wait never consents; open cards never re-decided; the ships question once per project; Undo as an ordinary revert task proven by tree equality, offered only for a hub-confirmed merge SHA with parents; any Undo puts the project in ask mode. Verification, trust counter, fix intents and the revert step move to v2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+447
−588
docs/superpowers/specs/2026-11-11-equipo-merge-authority.md+447 −588
Intent
diff --git a/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md b/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md| index e3de36b1..6d59ffc0 100644 |
| --- a/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md |
| +++ b/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md |
| @@ -1,83 +1,75 @@ |
| -# Equipo merge authority: when the coordinator merges without asking |
| - |
| -Status: spec addendum for review, 2026-11-11, revision 2 after Astra |
| -round 1 (REQUEST CHANGES at 7eba9c8, 13 findings; §13 maps each). Drafted |
| -by Claude (Opus 5.5) on `merge-authority` from main ac4a809. Builds on |
| -slice 4c (`docs/superpowers/plans/SLICE4C-PROGRESS.md`: the merge step, |
| -the merge card, `ready_sha`, `merge_eligible`), Mac runners |
| -(`2026-11-07-equipo-mac-runners.md` §4.3, ruling 2) and housekeeping |
| -(`2026-11-08-equipo-housekeeping.md` §3, decision classes). Not |
| +# Equipo merge authority, thin v1 |
| + |
| +Status: spec addendum for review, 2026-11-11, revision 3 ("thin v1"). |
| +Revision 1 (7eba9c8) and revision 2 (4ab106f) drew REQUEST CHANGES from |
| +Astra; the controller cut the scope (§11 lists what moved to v2, §12 |
| +maps the round 2 findings). Drafted by Claude (Opus 5.5) on |
| +`merge-authority` from main ac4a809. Builds on slice 4c |
| +(`docs/superpowers/plans/SLICE4C-PROGRESS.md`) and the housekeeping |
| +decision classes (`2026-11-08-equipo-housekeeping.md` §3). Not |
| implemented. |
| -## 0. Why |
| +## 0. Why, and the shape |
| Paul, on the card "Merge Swipe from the edge to go back doesn't work |
| without checks? [Merge] [Wait for checks]": "How do we give the |
| co-ordinator authority to merge stuff like this? I think it needs to be |
| able to make a decision ... we can give it heuristics and best |
| -practice." This replaces his slice 4c ruling "ask once when checks |
| -can't run": Equipo decides, and asks only when its policy says so. |
| - |
| -Today (`internal/equipo/chat/merge.go`) a candidate whose checks |
| -`passed`, approved on the same SHA, first Ready under the policy and not |
| -checked outside the sandbox is merged at once; anything else approved |
| -gets one merge card per SHA. This addendum adds a third outcome for |
| -approved work whose checks could not run: merge and tell, with Undo, |
| -then verify on the merged commit. |
| - |
| -Invariants, each tested as such: |
| - |
| -1. **The gate is code, on the instance.** One pure function decides. |
| - No model output and no runner can make it merge; a runner only |
| - supplies measured facts, and missing facts mean ask. |
| -2. **Never looser.** The coordinator can only make a decision stricter. |
| - Loosening needs an owner's tap or form. |
| -3. **One door.** Every merge dispatch and every hub request goes through |
| - `authorizeMerge`, which writes one audit row per decision. |
| +practice." Equipo decides, and asks only when its policy says so. |
| + |
| +Thin v1 is one rule checked at one moment: **right before Equipo sends a |
| +merge request to the hub, a pure function on the instance decides |
| +whether Equipo may send it on its own.** Nothing is queued on a |
| +decision; a decision that is not "merge now" leaves the task where |
| +today's code leaves it, with a better card. |
| + |
| +Invariants, each tested: |
| + |
| +1. **The gate is code, on the instance.** No model output can make it |
| + merge. A runner supplies measured facts; missing facts mean ask. |
| +2. **Never looser.** The coordinator can only tighten. Loosening needs |
| + an owner's tap or form. |
| +3. **One door.** Every merge request goes through `authorizeMerge` |
| + synchronously, with the hub's `expect_sha`, and each call writes one |
| + audit row. |
| +4. **Never retroactive.** Only a candidate whose review ran on a |
| + protocol 3 runner after the upgrade can merge without checks on its |
| + own; an open card is never re-decided automatically. |
| ## 1. Decision classes |
| -The housekeeping classes, reused by name: |
| - |
| -| Class | When | What happens | |
| +| Class | Meaning | What happens | |
| |---|---|---| |
| -| `act` (merge and tell) | every criterion of §2.2 holds | merge step dispatched; receipt card with Undo (§6); verification afterwards (§5) | |
| -| `ask` (with a recommendation) | approved, but a criterion fails | one merge card per SHA, worded as Equipo's call (§4) | |
| -| `never` | checks failed or still running, review asked for changes or has not finished, branch moved, task ended or cancelled, a merge in flight | no merge, no card (fix rounds and Needs you as today) | |
| +| `act` | Equipo may send the merge request now | the request goes; a receipt (§6) | |
| +| `ask` | approved, but a criterion of §2.3 fails | the merge card, once per SHA, worded as Equipo's call (§4) | |
| +| `never` | not approved, checks failed or running, branch moved, task ended, cancelled or merging already | nothing (fix rounds and Needs you as today) | |
| -The housekeeping principal still may never merge, open a merge card or |
| +The housekeeping principal may still never merge, open a merge card or |
| change a merge policy (`hkForbid`, unchanged). |
| ## 2. The gate |
| -### 2.1 Package and inputs |
| +### 2.1 `mergegate.Decide` |
| -New package `internal/equipo/mergegate`, pure: no store, no clock, no |
| -I/O. `chat` builds `Inputs` inside the write transaction. |
| +New package `internal/equipo/mergegate`, pure (no store, clock or I/O). |
| ```go |
| type Inputs struct { |
| Candidate string // newest pushed candidate; "" when the branch moved |
| - Verdict string // newest review verdict on Candidate, finished |
| + Verdict string // newest finished review verdict on Candidate |
| Checks string // passed | failed | none | cannot_run | "" (running) |
| ChecksReason string |
| OutsideSandbox bool // checks_sandbox none |
| - CanCheckLater bool // §2.3 |
| - Change *ChangeFacts // §3; nil when missing, refused or from an old runner |
| + Eligible bool // k.MergeEligible == Candidate (slice 4c) |
| + Person bool // a person chose Merge for this SHA (§2.4) |
| + Change *ChangeFacts // §3; nil when missing or refused |
| + Protocol int // the primary's protocol on its current connection |
| Policy Policy // §7; defaults when no row |
| - AsksLeft int // §8 |
| Hold string // §4.3 |
| - Consent *Consent // §2.4; nil for Equipo's own decision |
| - Revert *RevertFacts // §6; set only for a revert task |
| - Eligible bool // k.MergeEligible == Candidate (slice 4c) |
| + Revert *RevertCheck // §6; only for a revert task |
| } |
| -type Criterion struct { |
| - Name string |
| - OK bool |
| - Value string |
| - Limit string |
| -} |
| +type Criterion struct{ Name string; OK bool; Value, Limit string } |
| type Decision struct { |
| Class string // act | ask | never |
| @@ -89,151 +81,161 @@ type Decision struct { |
| func Decide(in Inputs) Decision |
| ``` |
| -### 2.2 Order of evaluation |
| +### 2.2 Order |
| 1. **Never** when `Candidate == ""`, `Verdict != approve`, `Checks == |
| failed` or `Checks == ""`. |
| -2. **Consent** (§2.4) present and valid: `act` (the person decided). |
| -3. **Checks passed** and not outside the sandbox: `act` with `Checks: |
| - true` only when `Eligible` (slice 4c's `merge_eligible`: the |
| - candidate first earned Ready under the policy with checks passed), and |
| - not `Policy.Mode == always_ask`, `AsksLeft > 0` or `Hold != ""`; |
| - otherwise `ask` (options Merge, Not now; the adopt card when not |
| - eligible). Size, sensitivity and shipping are not applied to checked |
| - work: slice 4c is unchanged for it. |
| -4. **Without checks**: `act` only when ALL of these hold, else `ask`. |
| +2. **A person's Merge** (`Person`): `act`. The person decided; holds |
| + and policy are shown on the card they answered, not re-applied. |
| +3. **Checks passed**, not outside the sandbox, `Eligible`: `act` with |
| + `Checks: true` unless `Policy.Mode == ask` or `Hold != ""` (then |
| + `ask`, options Merge, Not now). Not eligible: `ask` (slice 4c's adopt |
| + card). Outside the sandbox: `ask`, as today. |
| +4. **Without checks**: `act` only when ALL hold, else `ask`: |
| | Criterion | Holds when | |
| |---|---| |
| | `approved_exact_sha` | `Verdict == approve` on `Candidate`, branch at it | |
| | `environment_reason` | `Checks == cannot_run`, `ChecksReason` in `{needs_macos, runner_offline}` | |
| -| `can_check_later` | `CanCheckLater` | |
| -| `facts_present` | `Change != nil` (§3 accepted it) | |
| -| `small` | `Change.Lines <= Policy.MaxLines`, `Change.Files <= Policy.MaxFiles`, `Change.Binary == 0`, in every mode | |
| -| `not_sensitive` | no path (old or new side) matches §3.3, `!Change.Special`, `!Change.Signing` | |
| -| `not_shipping` | `Policy.MainShips == no` (§7.3); `unknown` and `yes` fail | |
| -| `trusted` | `AsksLeft == 0` | |
| +| `runner_reports_facts` | `Protocol >= 3` | |
| +| `facts_present` | `Change != nil` (accepted under §3.4) | |
| +| `small` | `Change.Lines <= Policy.MaxLines`, `Change.Files <= Policy.MaxFiles`, `Change.Binary == 0` | |
| +| `not_sensitive` | no old or new path matches §3.3, `!Change.Special`, `!Change.Signing` | |
| +| `main_does_not_ship` | `Policy.MainShips == no`, answered by an owner (§7.3) | |
| +| `policy_allows` | `Policy.Mode == rules` | |
| | `no_hold` | `Hold == ""` | |
| -| `policy_allows` | `Policy.Mode != always_ask` | |
| -| `revert_exact` | only when `Revert != nil`: §6 | |
| - |
| -`none` (no gate found), `checks_timeout`, `checks_unavailable` and |
| -`needs_network` are not environment reasons: they always ask. Checks |
| -passed outside the sandbox ask, as today. Without checks, nothing |
| -retroactive can pass: a review finished before the upgrade carries no |
| -change facts, so `facts_present` fails and it asks (§12 tests the |
| -upgrade). |
| - |
| -### 2.3 Can check later |
| - |
| -`CanCheckLater` uses the same predicate placement uses, extracted as |
| -`runnerFits(runner, needs, refusedBy)` (protocol 2, not removing, tags |
| -cover the needs, not in `refused_by`), over the person's enrolled |
| -runners, online or not, with the needs the task's checks step stored |
| -(`chat_steps.needs`). False when no enrolled runner fits. |
| - |
| -### 2.4 Consent |
| - |
| -A person's Merge (card, task page `POST /tasks/{id}/merge`, Retry of a |
| -refused merge, or the merge that follows a Wait) records consent on the |
| -task: `{person, sha, policy_revision, trust_generation, hold_revision, |
| -at}`. Consent is valid for `authorizeMerge` only while the person is |
| -still the task's creator and an owner (current roster, inside the |
| -transaction), the SHA is the candidate, the branch is at it, and the |
| -policy revision, trust generation and hold revision are unchanged. |
| -Anything else voids it and the task asks again (a new card revision). |
| - |
| -### 2.5 `authorizeMerge(task, candidateSHA)`: the one door |
| - |
| -`func (t *txn) authorizeMerge(k *taskRecord, sha string, at string) |
| -(Decision, error)`, `at` naming the caller. It loads the inputs, calls |
| -`Decide`, writes one audit row (§9) and returns the decision. Callers: |
| - |
| -| Caller | On `act` | Otherwise | |
| +| `revert_exact` | only for a revert task: §6.3 | |
| + |
| +`none`, `checks_timeout`, `checks_unavailable` and `needs_network` are |
| +not environment reasons and always ask. No policy value waives a |
| +criterion; size applies in every mode. |
| + |
| +### 2.3 `authorizeMerge(task, candidateSHA)` |
| + |
| +`func (t *txn) authorizeMerge(k *taskRecord, sha, at string, person bool) |
| +(Decision, error)` builds the inputs inside the write transaction (the |
| +current roster is checked there for `person`: the creator, still an |
| +owner), calls `Decide`, writes one audit row (§8) and returns the |
| +decision. It is the only function that may return `act`, and it is |
| +called at two moments: |
| + |
| +**(a) Before dispatch.** The only code that creates a merge step, |
| +`startMerge`, calls it first and creates the step only on `act`. |
| +Callers of `startMerge`: |
| + |
| +| Caller | `person` | Natural trigger | |
| |---|---|---| |
| -| `advance` at Ready (Equipo's own) | `startMerge` | `ask`: card once per SHA; `never`: nothing | |
| -| `answerMerge` (Merge), `MergeTask`, merge Retry | record consent, then `startMerge` | 409 with the failing reason; card refreshed | |
| -| Wait's checks passing (§4.2) | `startMerge` | card again | |
| -| `Store.Authorize` for a merge step attempt (§2.6) | grant | refuse | |
| - |
| -`startMerge` is unexported and has no other callers (a test lists the |
| -call sites with `go/ast`). The merge guards that exist today (ended, |
| -cancelled, moved, merge in flight, `hkForbid`) stay in `startMerge` too. |
| - |
| -### 2.6 Re-check before every hub request |
| - |
| -The runner's forge calls `Confirm` (the step's lease, `Store.Authorize`) |
| -immediately before every hub merge request, including a re-request |
| -after an uncertain answer and every resumption of a step deferred for |
| -the hub's own CI (`internal/runner/forge/merge.go`, `MergeBranch`). |
| -For merge steps, `Authorize` changes: |
| - |
| -- it runs `authorizeMerge` on **every** call, not only the first |
| - (today it returns early once `started_at` is set); |
| -- on anything but `act` it marks the attempt withdrawn |
| - (`reason = merge_not_authorized`), refuses the lease with |
| - `withdrawn`, and returns the task to Ready to merge, where the ask |
| - card is raised. Both old and new runners already end an attempt whose |
| - lease is refused as withdrawn, so no wire change is needed. |
| - |
| -The irreversible boundary is therefore the hub request itself. A |
| -request already sent when policy changes is reconciled by the forge |
| -record from the default branch, as today; a merge that lands that way |
| -is audited as `landed_after_change`. Queued merges (offline runner, |
| -deferred for CI) are re-decided before they can send anything. |
| - |
| -Policy, trust and hold changes bump their revisions, which void consent |
| -(§2.4) and touch open merge cards of the project (a new card revision), |
| -so an answer given under the old rules is refused 409. |
| +| `autoMerge` from `advance` | false | the candidate is at Ready to merge, on any report or sync | |
| +| `answerMerge` (Merge) | true | the person's tap | |
| +| `MergeTask` (task page Merge) | true | the person's tap | |
| +| merge Retry | true | the person's tap | |
| + |
| +`autoMerge` calls it only while the task has no merge card for this SHA |
| +(`merge_asked != candidate`) and no merge step for this SHA has ended. |
| +So once Equipo asked, only the person acts, and a failed automatic |
| +attempt is not repeated on its own (Ready to merge with the reason and |
| +Retry, as today). On `ask` it raises the card and sets `merge_asked`; on |
| +`never` it does nothing. |
| + |
| +**(b) Right before each hub request.** The runner's forge calls |
| +`Confirm` immediately before every hub merge request: the first, a |
| +re-request after an uncertain answer, and every resumption while the |
| +hub's own CI is pending (`internal/runner/forge/merge.go`, |
| +`MergeBranch`; it inspects the remote first, so a request already sent |
| +is settled from the default branch before any new request). A protocol |
| +3 runner sends that `Confirm` as a lease check with the new optional |
| +`purpose: "merge_request"` (beside the existing `publication` |
| +purpose). `Store.Authorize` for that purpose: |
| + |
| +- re-runs `authorizeMerge` (with `person` from the merge step's |
| + `decided_by`), on every call, after the ordinary attempt checks; |
| +- on `act`, grants; |
| +- otherwise refuses with the reason `merge_not_authorized`, and in the |
| + same transaction raises the ask card for the SHA (once) when the |
| + class is `ask`. |
| + |
| +The runner maps that refusal to a terminal failure `merge_not_authorized` |
| +before anything is sent (the forge record stays `prepared`; `Confirm` |
| +runs before the record moves to `requested`). The instance applies it as |
| +any other non-conflict merge refusal: back at Ready to merge, with the |
| +card. Nothing is withdrawn, so `withdrawnSettle` is not involved, and |
| +the step's first lease (which only starts the step, before any |
| +inspection) is unchanged. |
| + |
| +**No queued automatic merge.** `startMerge` for `person == false` |
| +creates the step only when the person's primary is online (and, for a |
| +merge without checks, on protocol 3, which `runner_reports_facts` |
| +already requires). Otherwise nothing is created and the next sync's |
| +`advance` is the next trigger. A person's Merge may wait |
| +for the primary as today. The runner's existing bounded wait while the |
| +hub's CI is pending (10 minutes) holds no decision: each resumption |
| +calls `Confirm`, which decides again. |
| + |
| +**Protocol 1 and 2 runners** never get an automatic merge without |
| +checks (`runner_reports_facts`), and an automatic merge with checks |
| +passed is created for them only as today; their `Confirm` cannot name |
| +the merge, so for those the gate runs at dispatch only. This is |
| +recorded in the audit row (`at: dispatch_only`). |
| + |
| +### 2.4 What a person's Merge means |
| + |
| +A person's Merge (card, task page, Retry) is `decided_by: person:<id>` |
| +on the merge step. It is bound to the SHA by `expect_sha` and to the |
| +person by the roster check at both moments. It is not stored anywhere |
| +else and never outlives the step. |
| ## 3. Change facts |
| ### 3.1 What the runner measures |
| -New optional `wire.ChangeFacts` on the **Review** step's report |
| -(Review runs on the primary, on exactly the candidate, before approval): |
| +New optional `wire.ChangeFacts` on the Review step's report, sent only |
| +on a protocol 3 connection: |
| ```go |
| type ChangeFacts struct { |
| - ReviewStep string `json:"review_step"` // the review step's ID |
| - Attempt int64 `json:"attempt"` |
| - Repo string `json:"repo"` |
| - Base string `json:"base"` // merge-base(task base, candidate) |
| - SHA string `json:"sha"` // the candidate |
| - Files int `json:"files"` |
| - Lines int `json:"lines"` // added + deleted, text files |
| - Binary int `json:"binary"` |
| - Special bool `json:"special"` // §3.2 |
| - Signing bool `json:"signing"` // §3.3 content rule |
| - Paths []Path `json:"paths"` // every changed entry, old and new |
| - Complete bool `json:"complete"` |
| + ReviewStep string `json:"review_step"` |
| + Attempt int64 `json:"attempt"` |
| + Repo string `json:"repo"` |
| + Base string `json:"base"` // merge-base(task base, candidate) |
| + SHA string `json:"sha"` // the candidate |
| + Files int `json:"files"` |
| + Lines int `json:"lines"` // added + deleted, text files |
| + Binary int `json:"binary"` |
| + Special bool `json:"special"` |
| + Signing bool `json:"signing"` |
| + Entries []Entry `json:"entries"` |
| + Complete bool `json:"complete"` |
| + Revert *RevertCheck `json:"revert,omitempty"` // §6.3 |
| +} |
| +type Entry struct { |
| + Status string `json:"status"` |
| + Old string `json:"old"` |
| + New string `json:"new"` |
| + OldMode string `json:"old_mode"` |
| + NewMode string `json:"new_mode"` |
| } |
| -type Path struct{ Old, New string; OldMode, NewMode string } |
| ``` |
| -Computed deterministically (no model) in the review tree from the exact |
| -pair: `git diff --raw -z -M --no-abbrev <base> <sha>` (modes, both |
| -paths of a rename or copy, status) and `git diff --numstat -z -M <base> |
| -<sha>` (lines, binary as `-`), plus `git diff -U0 <base> <sha> --` over |
| -the `.pbxproj`, `.xcconfig` and `Info.plist` files only, for the |
| -signing rule. The two listings must name the same entries; any |
| -disagreement, error, or more than `MaxChangePaths` (200) entries sets |
| -`Complete: false`. |
| +Computed with no model, in the review tree, from the exact pair: |
| +`git diff --raw -z -M --no-abbrev <base> <sha>` (status, both paths of |
| +a rename or copy, modes), `git diff --numstat -z -M <base> <sha>` |
| +(lines; `-` is binary) and `git diff -U0 <base> <sha> --` limited to |
| +`.pbxproj`, `.xcconfig` and `Info.plist` files (the signing rule). The |
| +two listings must name the same entries; disagreement, an error, or |
| +more than 200 entries gives `Complete: false`. |
| ### 3.2 Special entries |
| -`Special` is true when any entry has mode `120000` (symlink) or `160000` |
| -(gitlink, a submodule) on either side, or the old and new modes differ |
| -(including a new file created executable, `100755`). |
| +`Special` when any entry has mode `120000` (symlink) or `160000` |
| +(gitlink) on either side, or its old and new modes differ, or it adds a |
| +file with mode `100755`. |
| ### 3.3 Sensitive areas |
| -Defaults are a table in `mergegate/sensitive.go`, matched against both |
| -the old and the new path of every entry, case-insensitive. A path's |
| -**tokens** are its segments split on `/`, `.`, `-`, `_` and |
| -lower-to-upper case changes; token rules match whole tokens (so |
| -`keyboard` is not `key`). Every glob without a leading directory |
| -matches at any depth. |
| +A table in `mergegate/sensitive.go`, matched against the old and the |
| +new path of every entry, case-insensitive. Tokens are path segments |
| +split on `/`, `.`, `-`, `_` and lower-to-upper case changes, matched |
| +whole (`keyboard` is not `key`). Every glob matches at any depth. |
| | Class | Globs | Tokens | |
| |---|---|---| |
| @@ -245,466 +247,323 @@ matches at any depth. |
| | `release_signing` | `**/*.entitlements`, `**/*.mobileprovision`, `**/ExportOptions*.plist`, `**/fastlane/**`, `**/*.xcconfig`, `**/.goreleaser*`, `**/VERSION` | `release`, `releases`, `signing`, `entitlements`, `provisioning` | |
| | `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` | |
| -**Signing** (content rule): an added or removed line in a `.pbxproj`, |
| -`.xcconfig` or `Info.plist` naming `CODE_SIGN`, `DEVELOPMENT_TEAM`, |
| +**Signing**: an added or removed line in a `.pbxproj`, `.xcconfig` or |
| +`Info.plist` naming `CODE_SIGN`, `DEVELOPMENT_TEAM`, |
| `PROVISIONING_PROFILE`, `ENTITLEMENTS`, `PRODUCT_BUNDLE_IDENTIFIER`, |
| `MARKETING_VERSION`, `CURRENT_PROJECT_VERSION`, `CFBundleVersion` or |
| `CFBundleShortVersionString`. A `.pbxproj` change that only adds a file |
| reference is not sensitive by itself. |
| -A project's policy may add globs (`extra_sensitive`, at most 20, each |
| -<= 200 bytes, `path.Match` syntax plus `**`). No one can remove a |
| -default: the table is code. |
| - |
| -### 3.4 Acceptance by the instance |
| - |
| -The instance stores facts as JSON on the review step (`change_facts`) |
| -only when all hold, else drops them (the verdict still counts; the gate |
| -then asks on `facts_present`): |
| +A project may add globs (`extra_sensitive`, at most 20, each <= 200 |
| +bytes). Nobody can remove a default. |
| -- the report is from the person's primary runner and the runner the |
| - review step is placed on; |
| -- `ReviewStep` and `Attempt` are this step and its current attempt; |
| -- `Repo` is the task's project, `SHA` the step's `CandidateSHA`, `Base` |
| - a valid SHA; |
| -- `Complete` is true, the counts match the entries, every path is clean |
| - (`cleanPath`) and every mode is one of git's six. |
| +### 3.4 Acceptance |
| -`facts_present` reads only the facts on the review step whose verdict |
| -the gate is using. |
| +Stored on the review step (`change_facts`) only when: the report comes |
| +from the person's primary and the runner the step is placed on, on a |
| +protocol 3 connection; `ReviewStep` and `Attempt` are this step's |
| +current attempt; `Repo` is the task's project; `SHA` is the step's |
| +`CandidateSHA`; `Base` is a valid SHA; `Complete`; the counts match the |
| +entries; every path passes `cleanPath`; every mode is one of git's. |
| +Otherwise dropped (the verdict still counts; `facts_present` fails). |
| +`Decide` reads only the facts on the review step whose verdict it uses. |
| ## 4. Asking, with a recommendation |
| ### 4.1 The card |
| -The existing `merge` card, one per SHA (`merge_asked`), in the |
| -creator's conversation only, its question composed by the instance from |
| -the decision (no model turn): |
| +The existing `merge` card, once per SHA, in the creator's conversation, |
| +its question composed by the instance from the decision: |
| -- `Stance: merge` when the only failing criteria are `small` and |
| +- `Stance: merge` when the only failing criteria are `small` or |
| `policy_allows`: "I'd merge: %s." with up to three passing phrases |
| ("approved by Review", "a small change, %d lines in %d files", |
| "nothing ships until a release"). |
| - `Stance: wait` otherwise: "I'd wait: %s." with up to two failing |
| - phrases ("it touches payments (%s)", "I don't know whether %s's main |
| - ships to users", "checks failed on main after a recent merge", "the |
| - runner didn't say what changed", the coordinator's hold text). |
| + phrases ("it touches payments (%s)", "I don't know yet whether %s's |
| + main ships to users", "the runner didn't say what changed", "this |
| + project asks before every merge", the coordinator's hold text). |
| -Options: cannot run for `needs_macos`, or `runner_offline` with a macOS |
| -need: **Merge**, **Wait for a Mac**; other cannot-run reasons and |
| -`none`: **Merge**, **Wait for checks**; checks passed but asked: |
| -**Merge**, **Not now**. |
| +Options: `needs_macos`, or `runner_offline` with a macOS need: |
| +**Merge**, **Wait for a Mac**; other cannot-run reasons and `none`: |
| +**Merge**, **Wait for checks**; checks passed but asked: **Merge**, |
| +**Not now**. |
| ### 4.2 Wait |
| -Wait for a Mac or Wait for checks queues the checks step for the same |
| -SHA again (attempt n+1) without the `OfflineLimit` (it waits for a |
| -runner that fits) and records consent (§2.4). When those checks pass, |
| -`advance` calls `authorizeMerge` (the consent makes it `act` if still |
| -valid); when they fail, the fix round runs as usual. When |
| -`can_check_later` is false, Wait keeps today's meaning (stays at Ready |
| -to merge; Merge stays offered). |
| +Wait only waits; it is never consent. The task stays at Ready to merge |
| +with Merge offered (today's behaviour). If checks later pass on that SHA |
| +(a person's Retry of checks), the existing checks-passed path decides |
| +through `authorizeMerge`; if they still cannot run, the card asks again |
| +(a new card for that SHA: `merge_asked` is cleared when a new checks |
| +result arrives for the candidate). |
| ### 4.3 The coordinator: stricter only |
| -- Tool `hold_merge{task, reason}` (own task, not final, not merging): |
| - sets `merge_hold` (plain text, <= 200 bytes) and bumps |
| - `hold_revision`. A held task never merges without a person's consent |
| - given after the hold. No tool releases a hold; the person's Merge is |
| - the release for that SHA. |
| -- The coordinator's text reaches the gate only as `Hold`, which can only |
| - turn `act` into `ask`. |
| +- Tool `hold_merge{task, reason}` (own task; stage before Done, |
| + including Ready to merge and Merging before the hub request): sets |
| + `merge_hold` (plain text, <= 200 bytes). `Decide` then never acts on |
| + its own for that task; an automatic request not yet sent is refused at |
| +its `Confirm`. A person's Merge is not refused by a hold (they saw it on |
| +the card). |
| + No tool releases a hold; a person's Merge is the release for that SHA. |
| +- The coordinator's words reach the gate only as `Hold`. |
| - `read_task` shows the newest decision (class, stance, reasons). |
| -## 5. Verification after the merge |
| - |
| -### 5.1 Its own record |
| - |
| -A merge labelled without checks (any path) writes, in `mergeDone`'s |
| -transaction, a row in `chat_merge_verifications`; the done task is not |
| -touched again: |
| - |
| -`id` (`v_...`), `task_id`, `project_id`, `person`, `repo`, `merge_sha` |
| -(verified, §5.4), `base_sha` (the merge commit's first parent), |
| -`needs` (JSON, copied from the task's checks step), `state` (`waiting`, |
| -`placed`, `running`, `passed`, `failed`, `not_run`, `expired`), |
| -`attempt`, `runner_id`, `refused_by`, `placed_at`, `expires_at` |
| -(absolute, 14 days after the merge, never reset), `trust_generation` |
| -(§8), `gate`, `exit_code`, `reason`, `log_tail`, `output`, `revision`, |
| -timestamps. |
| - |
| -### 5.2 Lifecycle |
| - |
| -All in `Store.Place` (every minute) and the report path, one |
| -transaction each: |
| - |
| -- **waiting → placed**: a runner with `runnerFits(needs)` is online; |
| - a `dispatch` command is queued with `TaskID` = the task, `StepID` = |
| - the verification's ID, `Attempt`, specialist `checks`, |
| - `CandidateSHA` = `merge_sha`, `BaseSHA` = `base_sha`, the task's |
| - branch name (the runner only fetches and checks out the SHA). Inbound |
| - pack transfers for a worker key on the verification ID the same way. |
| -- **placed or running → waiting** (attempt n+1, cancel sent): the |
| - runner is offline for `WithdrawAfter`, refuses it |
| - (`placement_refused` adds to `refused_by`), or no report arrived for |
| - an hour. |
| -- **→ passed / failed / not_run**: the runner's report (§5.3). |
| -- **→ expired**: `expires_at` passed in any non-final state. |
| - |
| -Code that keys on step IDs routes `v_` IDs to the verification instead |
| -of a step: `stepReport`, `Store.Authorize`, the transfer handlers |
| -(`transfers.go`, which today refuse a done task's steps) and `syncSteps` |
| -(a held verification attempt the instance does not know is cancelled; |
| -one it knows is reconciled like a step). `progressOf`, `advance`, |
| -`RetryTask`, `withdrawnSettle` and `offline` never see verifications. |
| -One handler, `verificationEnded(v, outcome)`, applies every final |
| -state, idempotent on `(id, attempt)`. |
| - |
| -### 5.3 Outcomes |
| - |
| -- **passed**: the receipt card gains "Checks passed on main afterwards." |
| - (new revision, no new message); trust credit (§8); audit row. |
| -- **failed**: in one transaction: trust lowered (§8); a fix-task intent |
| - (§5.5); one coordinator line in the creator's conversation, "Checks |
| - failed on main after I merged [%s](%s). I opened [%s](%s) to fix it." |
| - (or, when the intent could not start a task, "... I couldn't start a |
| - fix: %s."); audit row. |
| -- **not_run** or **expired**: audit row and one line, "Checks still |
| - couldn't run on main after merging [%s](%s) (%s)." Trust unchanged. |
| - |
| -### 5.4 Verified landing |
| - |
| -`mergeDone` records `merged_verified` only when the merge SHA is |
| -established, never guessed: |
| - |
| -- the hub's `200 {merged, sha}` answer gives it; or |
| -- reconciliation finds, on the default branch's first-parent line, the |
| - commit that brought the candidate in (a merge whose second parent is |
| - the candidate, or the candidate itself for a fast-forward or squash |
| - recorded as such). |
| - |
| -`inspectMerge` (`internal/runner/thin/mergestep.go`) today falls back to |
| -the tip when the bounded search misses. Revised: it reports `MergeSHA` |
| -empty and the new optional `landing_verified: false`. The instance then |
| -marks the task done with `merged_sha` unknown, writes no verification |
| -and offers no Undo, and tells the creator: "Merged [%s](%s), but I |
| -couldn't tell which commit on main it is, so I can't check it or undo |
| -it." An old runner's report (no `landing_verified`) is treated the same |
| -for verification and Undo. |
| - |
| -### 5.5 Fix-task intent |
| - |
| -`chat_fix_intents`: `id`, `verification_id` (unique), `project_id`, |
| -`creator`, `title` ("Fix checks after merging %s", clipped), `brief` |
| -(merge SHA, gate, exit code, last 60 lines), `state` (`pending`, |
| -`created`, `started`, `reported`, `blocked`), `task_id`, `reason`. |
| - |
| -Written with the failure. `realizeIntent(id)` runs in the same |
| -transaction and again from `Place` while `pending` or `created`: |
| - |
| -- If the project has an open task created from an intent, the failure |
| - is added to it as a report entry (`reported`); no new task. |
| -- Else it creates the task directly with the store's task insert (not |
| - `recordTask`: no similarity check, no project card, no tool result), |
| - `fix_intent` set on the task, then starts it with the internal start |
| - (the creator is a current owner, execution is enabled, Engineering |
| - dispatched as `startTask` does). A refusal leaves `created` or |
| - `blocked` with the reason; the failure, trust change and line are |
| - kept either way. |
| - |
| -The fix task goes through the gate like any task; with trust lowered it |
| -asks. |
| - |
| -## 6. Undo is a revert task |
| - |
| -The creator's Undo on a receipt (card, or `POST |
| -/api/v1/tasks/{id}/undo-merge`) within 7 days (`housekeeping.UndoWindow`) |
| -creates a **normal task** in the same project: title "Undo %s", brief |
| -"Revert merge commit <sha> on <branch> with `git revert -m 1 <sha>` |
| -(plain `git revert <sha>` for a squash). Change nothing else.", |
| -`revert_of` = the task, `revert_sha` = the recorded merge SHA; it is |
| -started at once (owner, execution enabled). It then runs Engineering, |
| -checks and Review like any task, and reaches the gate like any task. |
| - |
| -- Refused (409) with a line to the creator when the merge SHA is not |
| - verified (§5.4), when the task already has an open or merged revert |
| - task, outside the window, or for a teammate (404) or a non-owner |
| - (403). Never falls back to main's tip. |
| -- **`revert_exact`** (only for a revert task): the review report's |
| - change facts carry the optional `revert_of: {sha, exact}`, where the |
| - runner compares `git patch-id --stable` of `git diff <sha> <sha>^1` |
| - with that of `git diff <base> <candidate>`. Only `exact: true` for the |
| - task's `revert_sha` passes. A revert that conflicted or did more is |
| - asked about. |
| -- Trust is lowered when the revert task's merge is done (`mergeDone` |
| - for a task with `revert_of`), once, keyed by the original merge SHA. |
| - |
| -No special runner step and no new specialist. |
| +## 5. What happens on the hub's answer |
| + |
| +`mergeDone` gains the landing's provenance, from new optional fields on |
| +the merge step's report (protocol 3): |
| + |
| +- `merge_source`: `hub` when the SHA is from this request's `200 |
| + {merged, sha}` answer; `reconciled` when the forge settled it from |
| + the default branch; `cached` when it returned an earlier record. |
| +- `merge_parents`: the merge commit's parents, read from the fetched |
| + default branch after the answer (empty if the fetch failed). |
| + |
| +`forge.MergeOutcome` gains `Source` to carry this; the forge's other |
| +behaviour is unchanged. The forge's fallback at |
| +`internal/runner/forge/merge.go:243` (substituting the tip when the |
| +landing commit is not found) is **not** changed here; it is filed as a |
| +separate small issue for every merge. Instead, for an automatic merge |
| +without checks, the instance treats any report whose `merge_source` is |
| +not `hub`, or whose `merge_parents` are not exactly two with the |
| +candidate second (the hub's merge commit), as **unverified**: the task is done (the |
| +commit is on the default branch), `merge_verified` is false, the |
| +receipt has no Undo, and the audit row says `landed_unverified`. |
| + |
| +## 6. Receipt and Undo |
| + |
| +### 6.1 The receipt |
| + |
| +An `act` merge without checks writes, in `mergeDone`'s transaction, a |
| +receipt card (kind `merge_receipt`) in the creator's conversation |
| +instead of the `chat.merged_without_checks` line, idempotent per task |
| +(`merged:<task>`, the existing key): "Merged [%s](%s) into %s without |
| +checks: %s." (`%s` the passing phrases of §4.1). It is visible at once, |
| +bound to the task (`task_id`), revision 1. Undo is offered only when |
| +`merge_verified` and for 7 days (`housekeeping.UndoWindow`). Merges with |
| +checks passed and a person's merges keep today's lines and no receipt. |
| + |
| +### 6.2 Undo creates an ordinary task |
| + |
| +The creator's Undo (card answer `undo`, or `POST |
| +/api/v1/tasks/{id}/undo-merge`, owner, current card revision) creates, in |
| +one transaction, an ordinary task through the store's task insert (no |
| +similarity check), title "Revert %s in %s" (short SHA, project), brief |
| +"Revert merge commit <sha> with `git revert -m 1 <sha>` and change |
| +nothing else.", `revert_of` = the task, `revert_sha` = the verified |
| +merge SHA, and starts it as `start_task` does (owner, execution on). |
| +It then runs Engineering, checks, Review and the gate like any task. |
| +The receipt's revision grows and it shows "Reverting: [%s](%s)." |
| + |
| +Refused (409, with a line to the creator) when not verified, outside the |
| +window, or a revert task for it exists; a teammate gets 404, a non-owner |
| +403. |
| + |
| +Any Undo puts the project in ask mode at once (§7.2: `mode: ask`, |
| +reason `reverted <sha>`), until an owner says otherwise. |
| + |
| +### 6.3 Exact revert |
| + |
| +The revert target travels to the runner as an optional `revert_sha` on |
| +the Review step's dispatch (protocol 3). The runner adds to the change |
| +facts `revert: {sha, on_top, exact}`: `on_top` when the candidate's |
| +parent is the reverted merge commit itself, and `exact` when |
| +additionally the candidate's tree equals that merge commit's first |
| +parent's tree (`git rev-parse <candidate>^{tree}` and `<sha>^1^{tree}`). |
| +`revert_exact` holds only for `on_top && exact` for the task's |
| +`revert_sha`. A revert made after main moved on, or one that changed |
| +more, is asked about. Since Undo sets ask mode, the revert task asks |
| +anyway in v1; `revert_exact` makes the card's stance merge ("I'd merge: |
| +it exactly reverts %s."). |
| ## 7. Policy per project |
| ### 7.1 Storage |
| -Migration **0058** (next free on main ac4a809; another open branch may |
| -also claim 0058, and whichever lands second renumbers) adds tables |
| -`chat_merge_policies`, `chat_merge_audit`, `chat_merge_verifications`, |
| -`chat_fix_intents`, `chat_trust_credits`, and columns |
| -`chat_steps.change_facts`, `chat_tasks.merge_hold`, |
| -`chat_tasks.hold_revision`, `chat_tasks.merge_consent`, |
| -`chat_tasks.merged_verified`, `chat_tasks.revert_of`, |
| -`chat_tasks.revert_sha`, `chat_tasks.fix_intent`, |
| -`chat_tasks.merge_decision`. All additive; each table is registered in |
| -`chat.Models` and `Schema`, and the migration check covers them. |
| +Migration **0058** (next free on main ac4a809; whichever branch lands |
| +second renumbers). Tables `chat_merge_policies` and `chat_merge_audit`; |
| +columns `chat_steps.change_facts`, `chat_steps.decided_by`, |
| +`chat_steps.merge_source`, `chat_steps.merge_parents`, |
| +`chat_tasks.merge_hold`, `chat_tasks.merge_verified`, |
| +`chat_tasks.revert_of`, `chat_tasks.revert_sha`. Additive; registered in |
| +`chat.Models` and `Schema`; the migration check covers them. |
| `chat_merge_policies` (team record, one row per project): |
| -`project_id`, `mode` (`rules` | `always_ask`), `max_lines` (default |
| -300, 0 to 2000), `max_files` (default 15, 0 to 100), `main_ships` |
| -(`unknown` | `yes` | `no`), `ships_asked` (bool), `extra_sensitive` |
| -(JSON), `words` (<= 300 bytes, display only), `asks_left`, |
| -`trust_generation`, `trust_reason`, `revision`, `updated_by`, |
| -`updated_at`. No row means the defaults (`rules`, 300, 15, `unknown`). |
| +`project_id`, `mode` (`rules` | `ask`), `mode_reason`, `max_lines` |
| +(default 300, 0 to 2000), `max_files` (default 15, 0 to 100), |
| +`main_ships` (`unknown` | `yes` | `no`), `ships_answered_by`, |
| +`ships_asked` (bool), `extra_sensitive` (JSON), `words` (<= 300 bytes, |
| +display only), `revision`, `updated_by`, `updated_at`. No row means |
| +`rules`, 300, 15, `unknown`. |
| ### 7.2 Setting it |
| - **In conversation**: tool `set_merge_policy{project, words, mode?, |
| max_lines?, max_files?, main_ships?, add_sensitive?}`. Each field is |
| - compared with the stored one. Only tighter fields (towards |
| - `always_ask`, smaller numbers, `main_ships: yes`, added globs): applied |
| - at once with a receipt and Undo (the home card's revision pattern; |
| - Undo applies only if the revision is still the one it made, and never |
| - restores trust fields). Any looser field: nothing applied; a confirm |
| - card "Change how Equipo merges %s: %s? [Save] [Cancel]" for the |
| - person, and Save (an owner, current revision) applies all of it. The |
| - instance never parses words; they are stored for display. |
| -- **On the project page**: a section "How Equipo merges" (a partial |
| - `merge_policy.html` included with one line in `work_project.html`, to |
| - stay clear of the Projects and Tasks work) shows the policy in plain |
| - sentences, the words, the trust state ("Asking for the next %d merges: |
| - checks failed on main after %s.") and the last five decisions with |
| - their reasons. An owner's form edits the fields (CSRF, revision, |
| - current roster); teammates see it read only. |
| + compared with the stored one. If every changed field is tighter (to |
| + `ask`, smaller numbers, `main_ships: yes`, added globs), it applies at |
| + once, with one coordinator line and an audit row. If any is looser, |
| + nothing applies: a confirm card "Change how Equipo merges %s: %s? |
| + [Save] [Cancel]" goes to the person, and Save (an owner, current |
| + policy revision) applies all of it. "for Woodstar, merge when Review |
| + approves" is `mode: rules` (and the ships answer); "always ask me |
| + about Suite" is `mode: ask`. The instance never parses the words. |
| +- **On the project page**: a section "How Equipo merges" (partial |
| + `merge_policy.html`, one include line in `work_project.html`, to stay |
| + clear of the Projects and Tasks work) shows the policy in plain |
| + sentences, the words, the mode reason, and the last five decisions |
| + with their reasons. An owner's form edits the fields (CSRF, policy |
| + revision, current roster); teammates see it read only. |
| - `GET/PUT /api/v1/projects/{id}/merge-policy` mirror the form. |
| -No policy waives `approved_exact_sha`, `environment_reason`, |
| -`can_check_later`, `facts_present`, `small`, the default sensitive |
| -table, `trusted` or `no_hold`. |
| - |
| ### 7.3 Does main ship to users? |
| -`main_ships` starts `unknown`, and unknown fails `not_shipping`. The |
| -first time a decision fails only or partly on it, and `ships_asked` is |
| -false, the instance (in the same transaction) sends one card to the |
| -task's creator if they are an owner: "Does merging to %s's main ship to |
| -users? [It ships] [It doesn't]". The answer, by an owner on the current |
| -policy revision, sets `main_ships` (`yes` or `no`) as owner policy with |
| -an audit row; `ships_asked` stops a second card. The project page edits |
| -it too. Nothing in the repository (the checks script, the index, CI |
| -files) is evidence either way. The answer does not re-decide the task |
| -whose card is open; that card stays the person's to answer. |
| - |
| -## 8. Trust per project |
| - |
| -State on the policy row: `trust_generation` (starts 0), `asks_left` |
| -(starts 0, trusted). Table `chat_trust_credits`: `project_id`, |
| -`merge_sha`, `kind` (`credit` | `debit`), `generation`, unique on |
| -`(project_id, merge_sha, kind)`. |
| - |
| -Every merge done by Equipo records the `trust_generation` current at |
| -its `mergeDone` (on the verification row, or on the audit row for a |
| -checked merge). |
| - |
| -Transitions, each in the transaction of the event, each an audit row: |
| - |
| -- **Lower** (debit), on a verification `failed`, or a revert task's |
| - merge done (keyed by the original merge SHA): if no debit row exists |
| - for that key: `trust_generation += 1`, `asks_left = 5`, |
| - `trust_reason` set, debit row written. A second, different failure |
| - while lowered lowers again (new generation, 5 again). |
| -- **Credit**, on a clean merge: a merge with checks passed (at |
| - `mergeDone`), or a verification `passed` from the primary or a |
| - sandboxed worker (not `checks_sandbox: none`): if `asks_left > 0`, the |
| - merge's recorded generation equals the current one, and no credit row |
| - exists for its SHA: `asks_left -= 1`, credit row written. Merges from |
| - an earlier generation never credit. |
| -- **Restored** when `asks_left` reaches 0; the project page says so. |
| - |
| -While `asks_left > 0`, `trusted` fails: every merge asks, including |
| -checks passed (§2.2 step 3). So a lowered project needs five clean |
| -merges, each of which a person approved, to be trusted again. |
| - |
| -## 9. Audit |
| - |
| -`chat_merge_audit`, append only: `id`, `project_id`, `task_id`, |
| -`kind` (`decision`, `authorize`, `answer`, `merged`, |
| -`landed_after_change`, `verification`, `fix_intent`, `undo`, `trust`, |
| -`policy`, `ships`), `at` (the `authorizeMerge` caller), `candidate_sha`, |
| -`merge_sha`, `class`, `stance`, `decided_by` (`policy`, `person:<id>`, |
| -`coordinator:<id>`), `reasons` (every `Criterion`), `inputs` (counts, |
| -the first ten matched paths, policy revision, trust generation and |
| -`asks_left`, hold revision, checks reason, review label, consent), |
| -`created_at`. Written in the transaction of the effect, which also |
| -appends the instance's audit event as every write does; a rolled-back |
| -effect leaves no row. No credentials and no model prose except the hold |
| -text. |
| - |
| -## 10. Wire and versions |
| - |
| -The gate and all decisions live on the instance. New wire fields are |
| -optional and `omitempty`: `StepReport.change`, |
| -`StepReport.landing_verified`, `ChangeFacts.revert_of`. They belong to a |
| -new **protocol 3**: the runner sends them only when the welcome says 3, |
| -and `wire.Encode` clears them for a protocol 2 connection (the existing |
| -`downgrade` pattern), so an old instance never receives a field its |
| -strict decoder refuses. Rollout order is instance first, then runners, |
| -as today. |
| +`main_ships` starts `unknown`, which fails `main_does_not_ship`. When a |
| +decision fails on it and `ships_asked` is false, the same transaction |
| +sends one card to the task's creator if they are an owner: "Does |
| +merging to %s's main ship to users? [It ships] [It doesn't]", and sets |
| +`ships_asked`. An owner's answer on the current policy revision sets |
| +`main_ships` and `ships_answered_by`, with an audit row. It applies to |
| +decisions made after it: the card already open for that task stays open |
| +until the person acts, because `autoMerge` never decides a SHA that has |
| +a card (§2.3). Nothing in the repository is evidence either way. The |
| +project page edits it too. |
| + |
| +## 8. Audit |
| + |
| +`chat_merge_audit`, append only: `id`, `project_id`, `task_id`, `kind` |
| +(`decision`, `answer`, `merged`, `landed_unverified`, `undo`, |
| +`policy`, `ships`, `hold`), `at` (`dispatch`, `confirm`, |
| +`dispatch_only`, or the form or tool), `candidate_sha`, `merge_sha`, |
| +`class`, `stance`, `decided_by` (`policy`, `person:<id>`, |
| +`coordinator:<id>`), `reasons` (every criterion), `inputs` (counts, the |
| +first ten matched paths, policy revision, protocol, checks reason, |
| +review label, hold), `created_at`. Written in the transaction of the |
| +effect, with the instance's audit event as every write; a rolled-back |
| +effect leaves no row; a replayed report adds none (keyed on step, |
| +attempt and kind). |
| + |
| +## 9. Wire and versions |
| + |
| +Protocol 3, all new fields optional and `omitempty`: |
| +`StepReport.change`, `StepReport.merge_source`, |
| +`StepReport.merge_parents`, `LeaseCheck.purpose`, |
| +`DispatchCommand.revert_sha`. The runner sends them only on a protocol 3 |
| +connection; `wire.Encode` clears them for protocol 2 and 1 (the |
| +existing `downgrade`). Instance first, then runners, as today. |
| | Combination | Behaviour | |
| |---|---| |
| -| New instance, old runner | no change facts: every merge without checks asks; no `landing_verified`: no verification, no Undo; consent and re-checks still apply (lease refusal is protocol 2) | |
| -| Old instance, new runner | protocol 2 welcome: the runner omits the new fields | |
| -| New both | as specified | |
| -| Runner downgraded after a receipt | Undo is a normal task (no capability needed); verification placement needs nothing new | |
| - |
| -## 11. Failure modes |
| - |
| -| What goes wrong | What happens | |
| -|---|---| |
| -| Facts missing, incomplete, mismatched or from a worker | dropped: asks | |
| -| Policy, trust or hold changes with a merge queued | `Authorize` re-decides before the request; withdrawn, asks | |
| -| Change after the hub request was sent | reconciled from the default branch; audited `landed_after_change` | |
| -| Branch moves | expect_sha refuses (`branch_moved`), as today | |
| -| Merge SHA not established | done, no verification, no Undo, one line | |
| -| Mac never returns | verification expires after 14 days, one line | |
| -| Relay primary offline during a worker verification | no report within the hour: back to waiting, attempt n+1 | |
| -| Repeated failures | one open fix task per project; later failures are reports on it | |
| -| Fix task cannot start | intent `blocked` with the reason; the line says so | |
| -| Revert conflicts or does more | `revert_exact` fails: asks | |
| -| The coordinator tries to loosen | confirm card; nothing changes without a tap | |
| -| Hub refuses (`ci_not_green`, forbidden) | today's reasons and Retry, Retry through `authorizeMerge` | |
| - |
| -## 12. Test plan |
| - |
| -Each test is written first and watched failing; each guard is broken |
| -and a test watched failing (recorded in the progress log). |
| - |
| -**Gate (`mergegate`)** |
| -- `TestDecideEachCriterion`: all pass gives `act`; each criterion |
| - failing alone gives `ask` naming it. |
| -- `TestDecideNever`; `TestDecideChecksPassedPath`; `TestDecideConsent` |
| - (valid, and each voiding change). |
| -- `TestDecideNeverLooser`, an invariant simulation over random inputs: |
| - `act` without checks and without consent implies every row of §2.2 |
| - holds (independent oracle); a hold never yields `act` without later |
| - consent; no policy value waives a fixed criterion; size applies in |
| - every mode. |
| -- `TestSensitivePaths`: each class at the root and nested, old and new |
| - rename paths, token boundaries (`keyboard`, `monkey`, `tokenizer`), |
| - extra globs only add. |
| - |
| -**Runner** |
| -- `TestReviewReportsChangeFacts`: numstat and raw agree, rename both |
| - paths, binary, symlink, gitlink, mode change, new executable, |
| - signing lines, a plain pbxproj file add, truncation, protocol 2 omits |
| - the field. |
| -- `TestRevertPatchIDExact`: exact revert true; revert plus another edit |
| - false. |
| -- `TestInspectMergeNeverGuessesTip`: the landing commit beyond the |
| - search window gives `landing_verified: false`, empty SHA. |
| - |
| -**Store contracts (`internal/equipo/chat`)** |
| -- `TestContractMergeAuthorityAct`: a Woodstar-shaped needs_macos change |
| - with `main_ships: no` merges, receipt, audit row, verification waiting. |
| -- `TestContractMergeAuthorityAsks`: each criterion gives the card with |
| - the stance and options of §4.1. |
| -- `TestContractOneDoor`: every caller of §2.5 goes through |
| - `authorizeMerge` (a `go/ast` scan of `startMerge` callers) and each |
| - writes one audit row. |
| -- `TestContractAuthorizeRechecks`: a merge step queued for an offline |
| - runner, then policy to `always_ask` (and separately a hold, a trust |
| - drop, a void consent): the lease is refused, nothing reaches the |
| - forge, the task asks. |
| -- `TestContractDeferredMergeRechecked`: deferred for the hub's CI, a |
| - hold arrives, the resumption is refused. |
| -- `TestContractShipsQuestion`: one card per project, owner only, |
| - stale revision 409, answer is policy, no second card. |
| -- `TestContractWaitForAMac`: requeue without the offline limit, pass |
| - merges through consent, fail runs the fix round, consent voided by a |
| - policy change asks again. |
| -- `TestContractVerificationLifecycle`: placed when a Mac comes online, |
| - worker offline back to waiting, `placement_refused`, no report in an |
| - hour, expiry, transfer for a `v_` ID, `syncSteps` with an unknown and |
| - a known verification, the done task untouched throughout. |
| -- `TestContractVerificationPassed`, `TestContractVerificationFailed` |
| - (intent, fix task started bypassing similarity, one line, trust 5, |
| - next merge asks, a second failure is a report on the open fix task, |
| - start refused keeps the line and trust). |
| -- `TestContractFixIntentIdempotent`: `realizeIntent` run twice and |
| - after a crash between create and start makes one task. |
| -- `TestContractUndoMerge`: revert task created and started, normal |
| - path, `revert_exact` passes and fails, unverified SHA refused with a |
| - line, window, 403/404/409, trust lowered once at the revert's merge. |
| -- `TestContractTrustTransitions`: lower, a second failure, five clean |
| - credits restore, an older generation's success never credits, a |
| - merge credited once, outside-sandbox pass never credits. |
| -- `TestContractMergePolicyTool`: tighter applies with Undo, looser |
| - makes a confirm card, Save by an owner applies, a teammate cannot, |
| - Undo after a later change 409, Undo never touches trust. |
| -- `TestContractHoldMerge`; `TestContractRosterDenial`: a removed |
| - member's or demoted owner's consent, Save, ships answer and Undo are |
| - refused inside the transaction. |
| -- `TestContractAuditRollback`: an effect that fails rolls back its audit |
| - row; a replayed report adds none. |
| - |
| -**Upgrade (migration 0058 on fixtures built with 0057)** |
| -- `TestUpgradeReadyWithOpenCard`, `TestUpgradeReadyAnsweredWait`, |
| - `TestUpgradeMovedAwayReady`, `TestUpgradeEligibleChecked` (a |
| - `merge_eligible` task still merges, through `authorizeMerge`), |
| - `TestUpgradeMergingInFlight` (the next `Authorize` re-decides): none |
| - merges without checks on upgrade, because none has change facts. |
| -- `TestUpgradeReplay`: a protocol 2 runner reconnecting and replaying |
| - held reports after the upgrade. |
| -- `TestWireProtocol3Downgrade`: both directions of §10. |
| - |
| -**Pages and end to end** |
| -- `TestProjectPageMergePolicy` (section, form, read only for |
| - teammates); browser `TestBrowserMergePolicy` with `-run`. |
| -- Headless `ma_act` (fake CLI, local forge: an iOS change merges and |
| - tells; a fake Mac worker comes online; verification passes) and |
| - `ma_fail` (fails: fix task, line, the next merge asks). |
| -- Gates kept green: `make budget`, gofmt, `go vet ./internal/...`, |
| - `scripts/runner-dead-references.py`, `TestPlan3ReleaseBoundaries`, |
| - the migration and model check. |
| - |
| -## 13. Round 1 findings and where they went |
| - |
| -1. Size waivable: `review_enough` removed; `small` in every mode (§2.2, §7.2). |
| -2. Facts underspecified: raw plus numstat, both paths, modes, any depth, |
| - bound to the review run, acceptance rules (§3). |
| -3. Shipping inferred: removed; `unknown` asks; one owner question per |
| - project; nothing in the repository is evidence (§7.3). |
| -4. Gate invocation incomplete: one door `authorizeMerge` for every path |
| - (§2.5). |
| -5. Queued merges outlive authority: re-check before every hub request, |
| - consent voided by changes (§2.4, §2.6). |
| -6. Done-task paths: verification is its own record and lifecycle (§5). |
| -7. Lost Mac need: needs copied at merge time, shared `runnerFits`, |
| - absolute expiry, relay recovery (§2.3, §5). |
| -8. Undo state machine: a normal revert task, no special step (§6). |
| -9. Tip fallback: never guessed; unverified means no verification and no |
| - Undo (§5.4). |
| -10. Trust ordering: generation, unique credits and debits, transitions |
| - (§8). |
| -11. Fix task not guaranteed: durable intent, direct insert, idempotent |
| - (§5.5). |
| -12. Mixed versions: protocol 3 optional fields, downgrade, table (§10). |
| -13. Tests: upgrade, roster, audit and lifecycle cases listed (§12). |
| - |
| -## 14. Choices to confirm with Paul |
| - |
| -1. Trust: lowered for five clean merges of the current generation; each |
| - asks, so each is a person's call. |
| -2. Lowered trust and `always_ask` also ask for checks-passed merges. |
| -3. Any binary file (an image asset) asks. |
| -4. "for Woodstar, merge when Review approves" is the default `rules` |
| - mode plus `main_ships: no`; it waives nothing else. |
| -5. Answering "Does main ship?" does not re-decide the card already open. |
| +| new instance, protocol 1 or 2 runner | no facts: every merge without checks asks; checks-passed merges as today, gate at dispatch only | |
| +| old instance, new runner | protocol 2 welcome: the new fields are never sent | |
| +| a runner downgrades after review | `Protocol` is read at each decision: asks | |
| + |
| +## 10. Tests |
| + |
| +Each written first and watched failing; each guard broken and a test |
| +watched failing; commands and results in the progress log. |
| + |
| +**Gate (`mergegate`)**: `TestDecideEachCriterion` (all pass: act; each |
| +failing alone: ask naming it); `TestDecideNever`; |
| +`TestDecideChecksPassedPath`; `TestDecidePersonMerge`; |
| +`TestDecideNeverLooser` (an invariant simulation over random inputs: |
| +act without checks and without a person implies every row of §2.2 holds, |
| +by an independent oracle; a hold never yields act without a person; no |
| +policy value waives a criterion); `TestSensitivePaths` (each class at |
| +root and nested, old and new rename paths, token boundaries: |
| +`keyboard`, `monkey`, `tokenizer`; extra globs only add). |
| + |
| +**Runner**: `TestReviewReportsChangeFacts` (raw and numstat agree, |
| +rename both paths, binary, symlink, gitlink, mode change, new |
| +executable, signing lines, a plain pbxproj file add, truncation, |
| +protocol 2 omits it); `TestRevertCheck` (on top and exact; on top plus |
| +another edit; not on top); `TestMergeConfirmPurpose` (the forge's |
| +`Confirm` sends `merge_request`; a refusal ends `merge_not_authorized` |
| +with nothing sent and the record `prepared`); `TestMergeSource` (hub |
| +answer, reconciled, cached; parents read). |
| + |
| +**Store contracts**: `TestContractMergeAuthorityAct` (a Woodstar-shaped |
| +needs_macos change, `main_ships: no`: merged, receipt with Undo, audit |
| +rows at dispatch and confirm); `TestContractMergeAuthorityAsks` (each |
| +criterion gives the card with §4.1's stance and options); |
| +`TestContractOneDoor` (every `startMerge` caller passes |
| +`authorizeMerge`; a `go/ast` scan finds no other creator of merge |
| +steps); `TestContractConfirmRechecks` (policy to ask, a hold, the |
| +runner reconnecting at protocol 2, each between dispatch and confirm: |
| +refused, nothing reaches the forge, the card raised); |
| +`TestContractNoQueuedAutoMerge` (primary offline: no step; next sync |
| +merges); `TestContractNoRetryLoop` (an automatic attempt refused by the |
| +hub is not repeated on sync); `TestContractOpenCardNotRedecided` |
| +(answer "It doesn't ship" while a card is open: the next sync does not |
| +merge; the next candidate does); `TestContractShipsQuestion` (one card |
| +per project, owners only, stale revision 409); `TestContractWait` |
| +(Wait stays Ready; a later cannot-run asks again; never merges on its |
| +own); `TestContractUnverifiedLanding` (reconciled or cached source, or |
| +wrong parents: done, no Undo, audit); `TestContractUndo` (ordinary task |
| +without similarity, started, project to ask, receipt revision, 403, |
| +404, 409, window); `TestContractRevertExact`; |
| +`TestContractMergePolicyTool` (tighter applies, looser makes a confirm |
| +card, owner Save applies, teammate refused); |
| +`TestContractHoldMerge` (including during Merging before the request); |
| +`TestContractRosterDenial` (a removed or demoted person's Merge, Save, |
| +ships answer and Undo are refused inside the transaction); |
| +`TestContractAuditRollback` (a failed effect leaves no row; a replay |
| +adds none); `TestContractFactsAcceptance` (worker, wrong attempt, wrong |
| +SHA, incomplete, mismatched counts: dropped). |
| + |
| +**Upgrade (0058 on fixtures built at 0057)**: a Ready task with an open |
| +card, one answered Wait, one moved away, one eligible with checks |
| +passed (still merges, through the gate), one merging in flight (its |
| +next `Confirm` from a protocol 2 runner keeps today's behaviour): none |
| +merges without checks; `TestWireProtocol3Downgrade` (both directions). |
| + |
| +**Pages and end to end**: `TestProjectPageMergePolicy` (section, form, |
| +read only for teammates); browser `TestBrowserMergePolicy` with `-run`; |
| +headless `ma_act` (fake CLI, local forge: an iOS change merges and |
| +tells; Undo opens the revert task) and `ma_ask` (the ships question, |
| +then the card). |
| + |
| +Gates kept green: `make budget`, gofmt, `go vet ./internal/...`, |
| +`scripts/runner-dead-references.py`, `TestPlan3ReleaseBoundaries`, the |
| +migration and model check. |
| + |
| +### Copy inventory |
| + |
| +All in `internal/equipo/copy.go`, each marked `COPY REVIEW REQUIRED`, |
| +each listed in the Plan 3 copy inventory: the card stances and phrases |
| +(§4.1); "Wait for a Mac"; the receipt and "Reverting: [%s](%s)." (§6); |
| +Undo's refusal lines; "Merged [%s](%s), but I couldn't tell which commit |
| +on main it is, so I can't undo it."; the ships question and its two |
| +answers (§7.3); the policy confirm card and the tightening line (§7.2); |
| +the project page section's sentences; the `hold_merge` and |
| +`set_merge_policy` tool descriptions; the Stopped line for |
| +`merge_not_authorized`. |
| + |
| +## 11. Moved to v2 |
| + |
| +- Verification on the merged commit when checks can run, as its own |
| + durable record. |
| +- The trust counter with generations and credits. |
| +- Automatic fix-task intents after a failed verification. |
| +- A deterministic revert step (v1's Undo is an ordinary task). |
| +- Fixing the forge's tip fallback for every merge (a separate issue). |
| + |
| +## 12. Round 2 findings and where they went |
| + |
| +1. Wait as consent: Wait never consents (§4.2). |
| +2. Open card reconsidered: `autoMerge` never decides a SHA that has a |
| + card (§2.3, §7.3). |
| +3. Withdrawal versus reconciliation: no withdrawal; a refused |
| + `merge_request` lease before any request, after inspection (§2.3); |
| + holds allowed while Merging (§4.3). |
| +4. Guessed landing: provenance from the hub answer and parents; anything |
| + else is unverified with no Undo; the forge fallback is a separate |
| + issue (§5). |
| +5. and 6., 7. Verification, trust and fix intents: moved to v2 (§11). |
| +8. Revert target and exactness: `revert_sha` on the dispatch; tree |
| + equality on top of the merge commit (§6.3). |
| +9. Protocol 1: automatic merges without checks need protocol 3; older |
| + runners are gated at dispatch only, as recorded (§2.3, §9). |
| +10. Receipt rules and copy inventory restored (§6.1, §10). |