| 1 | # Runners progress: Mac runners groundwork (slices A and B) |
| 2 | |
| 3 | Branch `thin-v1-runners` from `thin-v1-slice4c` (2d1edaf), with |
| 4 | `design-mac-runner` (b5f7259) merged so the spec is on the branch, then |
| 5 | `thin-v1-composer` (0797ad0: connections slice 1, inner screens, |
| 6 | housekeeping slice 1, attachments) merged at 23b0b31. Spec: |
| 7 | `docs/superpowers/specs/2026-11-07-equipo-mac-runners.md` rev 4 |
| 8 | (accepted), slices A and B, Linux only. No Darwin code and no Mac probe: |
| 9 | those need tito-studio and a person (slice C onwards). Conventions and |
| 10 | scripts as in `SLICE1-PROGRESS.md` to `SLICE4C-PROGRESS.md`. |
| 11 | |
| 12 | ## Done |
| 13 | |
| 14 | 1. Wire, protocol 2 (`internal/wire/runners.go`): `Protocol1`, |
| 15 | `Protocol2`; roles `primary`, `worker`; sandboxes; the fixed tag set; |
| 16 | `Platform`, `Capabilities` (xcode, simulators, toolchains, harness, |
| 17 | tags) with `ValidCapabilities` (40 simulators, 300 bytes a string, |
| 18 | 8 KB in all, no path separator, newline, `~` or `=` in any string); |
| 19 | `Covers`; placement, publication and termination kinds; transfers |
| 20 | (`TransferHeader`, `Blob`, `SendPackCommand`), `PublishCommand`, |
| 21 | `PublishedReport`, `Refused`. `hello` gained `protocol`, `platform`, |
| 22 | `label`, `sandbox`, `capabilities`; `welcome` `protocol`, `role`, |
| 23 | `release`; `dispatch` `needs`, `runner_id`; `lease` `step_id`, |
| 24 | `attempt`; `step` `termination_kind`, `have`, `phase`. Every new field |
| 25 | is `omitempty`, so a protocol 1 frame is byte for byte the slice 4 |
| 26 | frame. `wire.Encode(frame, protocol)` clears the protocol 2 fields and |
| 27 | refuses protocol 2 frame types at protocol 1. New step reasons |
| 28 | `placement_refused`, `withdrawn`, `transfer_refused`, |
| 29 | `runner_offline`. Fixtures `frames/hello-mac.json`, |
| 30 | `welcome-worker.json`, `dispatch-needs.json`, `lease-step.json`, |
| 31 | `blob.json`, `send_pack.json`, `publish.json`, `published.json`, |
| 32 | `refused.json`, `step-process-group.json`. Tests: |
| 33 | `TestEncodeProtocol1IsTheSlice4Wire` (each new frame at protocol 1 has |
| 34 | the slice 4 fixture's keys and parses; the slice 4 fixtures pass |
| 35 | through byte for byte), `TestEncodeProtocol1RefusesNewFrames`, |
| 36 | `TestProtocolNegotiation`, `TestDurableRunnerFrames`, |
| 37 | `TestCapabilitiesGuard`, `TestCovers`. Mutations: Encode without the |
| 38 | downgrade, and without the protocol 2 frame refusal, each failed a |
| 39 | test. |
| 40 | |
| 41 | 2. Migration 0054 (renumbered from 0047 at the composer merge): |
| 42 | `runners.role`, `runner_commands.runner_id`, `chat_steps.runner_id` |
| 43 | (indexed), placement, publication and termination columns, |
| 44 | `chat_tasks.engineering_runner`, `runner_sessions.protocol`, |
| 45 | `runner_transfers`. In one transaction: every runner primary, every |
| 46 | command and step in every state bound to the person's primary (the |
| 47 | primaryRunner query, then fallbacks), runnerless open steps waiting. |
| 48 | `chat.UnboundSteps` is the schema check. Tests: |
| 49 | `TestRunnersMigrationBindsSlice4Rows` (SQL over an older database: |
| 50 | running, pending termination, queued, unacked commands); |
| 51 | `TestContractMigrationOverSlice4Work` (live work, schema stripped |
| 52 | back, restart migrates, the same runner carries on, Retry still |
| 53 | waits for termination). |
| 54 | 3. Per-runner scoping: Pending, ack, step reports and syncSteps by |
| 55 | runner; turns stay primary-only; a wrong-runner report is refused |
| 56 | without closing the connection (`ErrRefused`, acked, logged). |
| 57 | `TestContractWorkerScoping`; four mutations each failed it. |
| 58 | 4. Roles: first enrolment primary, later ones workers (replace a |
| 59 | primary by revoking it first); a connecting primary rebinds orphans |
| 60 | (no primary at write time, a revoked primary's). Negotiation: hello |
| 61 | offers protocol 2; the instance speaks the lower and encodes every |
| 62 | frame per connection; a protocol 1 worker is refused; the runner |
| 63 | falls back once on a strict-decode refusal and logs it; a worker |
| 64 | never does (`ErrInstanceTooOld`) and will not enrol with an instance |
| 65 | lacking `GET /api/runner/protocol`. `TestContractRunnerRoles`, |
| 66 | `TestLinkFallsBackToProtocol1`, `TestWorkerRefusesAnOlderInstance`, |
| 67 | `TestLinkSpeaksProtocol2`, `TestWorkerEnrolRefusesAnOlderInstance`. |
| 68 | 5. Capabilities (Linux probe; the test build's fixture Mac), cleaned |
| 69 | on the instance (out of bounds dropped, label one line). Index |
| 70 | reports `needs_macos` (gate) and `ios_simulator` (shared scheme); |
| 71 | Engineering reports `apple`. |
| 72 | 6. Placement (`chat/runners.go`): checks needing a Mac go to a worker |
| 73 | whose tags cover them (primary first, then fewest running steps, |
| 74 | enrolment order); offline fitting worker: waiting; after 30 minutes |
| 75 | checks resolve `cannot_run/runner_offline` and review goes on; |
| 76 | nobody fits or the primary is protocol 1: the primary judges as |
| 77 | before (`needs_macos`). The runner picks a connection among its own. |
| 78 | Engineering is pinned per task; questions go to the step's runner. |
| 79 | Start authorization (`lease{step_id, attempt}`) and withdrawal in |
| 80 | one serialised write: not started, the next attempt is placed at |
| 81 | once and the old one can never start; started, `cancel_step` and |
| 82 | the next attempt only after termination; a 2-minute grace before |
| 83 | withdrawing from a worker that dropped. `placement_refused` |
| 84 | re-places. `GET /api/v1/runners`, `snapshot.runners`, per-runner |
| 85 | events (the chat's offline line follows the primary only). |
| 86 | Contracts: `TestContractChecksPlacedOnTheWorker`, |
| 87 | `TestContractChecksWithoutAWorker`, `TestContractChecksWaitForTheWorker`, |
| 88 | `TestContractPlacementRefused`, `TestContractWithdrawal`, delayed |
| 89 | older-SHA checks and review cases in `TestContractReviewAndChecks`. |
| 90 | 7. Transfers: rows authorise every chunk (sender, open, header, current |
| 91 | attempt, bounds, order); blobs relay as commands; oversize ends |
| 92 | checks `checks_unavailable`; last ack closes; 24 h TTL. |
| 93 | `TestContractTransferAuthorization`, `TestContractTransferTooLarge`. |
| 94 | Worker side: header against its step row, digest, exactly the |
| 95 | candidate with a complete tree (`TestWorkerRefusesTamperedPacks`). |
| 96 | 8. Publication: only the primary's `published` sets Pushed for a |
| 97 | worker's commit; the primary indexes the pack beside its clone, |
| 98 | checks the parent is the base, confirms the publication right |
| 99 | before the push and pushes through forge (record then reconcile). |
| 100 | `TestContractPublication`, `TestContractCancelBeforePublication`, |
| 101 | `TestRelayRetryAfterPushFailure`, `TestRelayCrashes` (after |
| 102 | indexing; after the push), `TestRelayCancelledBeforePush`, |
| 103 | `TestRelayRefusesAWrongCommit`. |
| 104 | 9. Fake worker (`-tags testbuild` only): process group, no sandbox; |
| 105 | `make release-runner` runs `scripts/no-fake-worker.sh`; |
| 106 | `TestReleaseRunnerHasNoFakeWorker` fails if it is compiled in. |
| 107 | Headless `TestMacWorker`: M1, M5, M2 (and the 30-minute rule with a |
| 108 | fake clock), M4 (SIGKILL, process group proven gone, Retry). |
| 109 | 10. M8 `TestMixedVersions` against the staging line 0797ad0 built from |
| 110 | git history: older runner against this instance (protocol 1, task |
| 111 | done, every frame unchanged by `Encode(f, 1)`); this runner against |
| 112 | the older instance (one fallback, task done); a worker refused at |
| 113 | enrolment, nothing created. |
| 114 | |
| 115 | Mutations: about 25, each observed failing a test (listed in the |
| 116 | commits); defence in depth noted where one survived first. |
| 117 | |
| 118 | 11. Astra round 1 (REQUEST CHANGES at 1b89bd1, 7 Important, 1 Minor), |
| 119 | each fix with a test that failed first: |
| 120 | 1. A revoked primary keeps its attempts: only conversation commands |
| 121 | move to the replacement; dispatches, cancels, asks, transfers and |
| 122 | publications stay with the runner that may still run them, and the |
| 123 | replacement's empty sync settles none of its steps |
| 124 | (`TestContractRevokedPrimaryKeepsItsAttempts`). |
| 125 | 2. Withdrawal comes first in a step report and in sync: a withdrawn |
| 126 | attempt's results never count; only its termination proof does, |
| 127 | whenever it arrives, and places the next attempt; Retry clears the |
| 128 | withdrawal (`TestContractWithdrawnAttemptReports`, |
| 129 | `TestContractWithdrawnProofAfterFailure`). |
| 130 | 3. A waiting, never-dispatched step ends locally on Cancel, and |
| 131 | nothing is ever sent to an empty runner id |
| 132 | (`TestContractCancelWaitingSteps`). |
| 133 | 4. The Engineering pin is set on the task value the transaction |
| 134 | saves (`TestContractEngineeringPinKept`). |
| 135 | 5. A worker's role is kept in its state: it never falls back to |
| 136 | protocol 1 and never serves under a primary welcome, whatever its |
| 137 | OS (`TestWorkerIdentityPersists`, `TestWorkerRefusesAPrimaryWelcome`). |
| 138 | 6. A worker's report never clears the primary's `Pushed` or |
| 139 | publication (`TestContractPublishedBeforeWorkerDone`). |
| 140 | 7. Oversize is declared by a chunk count past `wire.MaxTransferChunks`, |
| 141 | refused at once by the instance (checks `checks_unavailable`) and |
| 142 | by a receiver (`TestContractTransferDeclaredTooLarge`, |
| 143 | `TestRelayDeclaresOversize`). |
| 144 | 8. Asking a step whose runner is offline answers 409 `runner_offline` |
| 145 | at once (`TestContractAskOfflineRunner`). |
| 146 | |
| 147 | 12. Astra round 2 (7 of 8 resolved; three items), each with a test that |
| 148 | failed first: |
| 149 | 1. Worker identity before connecting: enrolment keeps the role from |
| 150 | the credential the instance returns (`role` only for a worker; |
| 151 | absent means primary, as an older instance's credential is) in a |
| 152 | `role` file beside `credentials.json`, which stays what older |
| 153 | runner binaries read. A runner with no known role (enrolled before |
| 154 | roles) never falls back to protocol 1 and never serves a protocol 1 |
| 155 | welcome until a protocol 2 welcome tells it, which it keeps |
| 156 | (`TestEnrolKeepsTheRole`, `TestContractEnrolmentNamesAWorker`, |
| 157 | `TestEnrolledWorkerNeverFallsBack`, `TestUnknownRoleWaitsForTheInstance`, |
| 158 | `TestUnknownRoleLearnsFromProtocol2`). |
| 159 | 2. Cancel after withdrawal: the proof finishes the cancellation and |
| 160 | places nothing (`TestContractCancelAfterWithdrawal`). |
| 161 | 3. Removal is two-phase: the runner is marked removing first (no new |
| 162 | work, not a primary); never-started protocol 2 attempts are |
| 163 | withdrawn and placed elsewhere in the same transaction; |
| 164 | possibly-started ones (or any on a protocol 1 runner) are |
| 165 | cancelled, and the runner is revoked when the last proof arrives. |
| 166 | Nothing else settles them: no timeout, no other runner's sync. |
| 167 | Remove now revokes at once and quarantines possibly-started steps |
| 168 | (`machine_removed`, no termination, Needs you); the creator's |
| 169 | Recover (audited `task.recover`) settles them `unverified` and |
| 170 | allows Retry. Runners page: "Removing: waiting for it to stop its |
| 171 | work" and Remove now; the card and Needs you: "Stopped: the |
| 172 | machine was removed mid-step. Make sure it's switched off, then |
| 173 | Recover" with Recover (`TestContractRemovalWaitsForProof`, |
| 174 | `TestContractRemoveNowQuarantines`, `TestPagesRemovalAndRecover`; |
| 175 | `TestContractRevokedPrimaryKeepsItsAttempts` updated: the never- |
| 176 | started dispatch now moves to the replacement and its old attempt |
| 177 | can never start). |
| 178 | |
| 179 | ## Decisions |
| 180 | |
| 181 | - New wire fields are `omitempty` rather than always present: the slice |
| 182 | 4 fixtures stay byte-identical, and `Encode` at protocol 1 only has to |
| 183 | clear fields. |
| 184 | - `refused{id, reason}` answers a start authorization the instance will |
| 185 | not grant; the spec names the refusal but no frame for it. |
| 186 | - `send_pack` (instance to primary, durable) asks the primary to upload |
| 187 | an inbound transfer's pack; the spec says the primary sends the pack |
| 188 | but not how it is asked. |
| 189 | - Blob frames carry the whole transfer header, so the receiver checks |
| 190 | repository, task, step, attempt, base, candidate and direction against |
| 191 | its own step row on every chunk; `sha256` is the whole pack's digest. |
| 192 | - The capability report keeps accounts where they are (hello's |
| 193 | connections since the composer merge). |
| 194 | - Protocol 1 is the composer wire. M8 runs against 0797ad0 rather than |
| 195 | the spec's ca0a65c, whose wire predates 4b, 4c and connections. |
| 196 | - Only checks are placed by needs in this release; Engineering, Review |
| 197 | and merges stay on the primary until slice F. |
| 198 | - The worker's connections are not recorded yet (checks need none). |
| 199 | - Blob transfers use their own row and blob commands rather than the |
| 200 | attachments' chunk frames: they bind to a step attempt and a |
| 201 | direction, which attachments do not need. |
| 202 | |
| 203 | ## Open issues |
| 204 | |
| 205 | - A runner that never comes back while removing stays removing; Remove |
| 206 | now is the way out (quarantine, then Recover). |
| 207 | - `have`/thin packs are on the wire but packs are whole one-commit packs. |
| 208 | - Copy for the runner lines (waiting, offline, Runners) is not written; |
| 209 | slice D/E, with Luna's pass. |
| 210 | - 4c_rebase failed once in a loaded full headless run, passed alone. |
| 211 | |
| 212 | ## Blockers |
| 213 | |
| 214 | None. |
| 215 | |
| 216 | ## Copy for review (round 2, accepted for now) |
| 217 | |
| 218 | - `runner.removing` "Removing: waiting for it to stop its work" |
| 219 | - `runner.remove_now` "Remove now" |
| 220 | - `work.needs.machine_removed` "Stopped: the machine was removed |
| 221 | mid-step. Make sure it's switched off, then Recover" |
| 222 | - `work.reason.machine_removed` "the machine was removed mid-step" |
| 223 | - `work.recover` "Recover" |
| 224 | |