oficina / equipo Public

Mac runners spec rev 3: step backfill, start authorization, protocol

Astra's round 2 on 0f6eaa6, the final round. Migration 0045 now
backfills every existing step, including pending-termination attempts,
to the person's primary before ownership is enforced, with a test over
a slice 4 database. Withdrawal no longer equates unacked with
undelivered: starting an attempt is the existing lease round trip made
attempt-specific and serialised against withdrawal in one SQLite
transaction, with lost-ack and race tests.

Rollout: hello/welcome negotiate a protocol; the instance encodes per
connection and sends nothing new to a protocol 1 runner; upgrade order
instance, primary, workers, with a protocol 1 fallback for a rolled-back
instance; M8 runs the real slice 4 binaries. Transfers bind every chunk
to source and destination runners, repository, task, step, attempt,
base and candidate, refused before bytes are kept, tested apart from
tampering. Publication is the primary's word alone: a durable publish
command and published report, worker pushed flags refused, crash and
cancel tests between pack receipt and push. One line notes Paul's
ruling that Equipo merges its own Ready-to-merge work (slice 4c).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
claude 460f31b27bd5cdf5a73bdea72b08acac29103568 parent 0f6eaa6
1 file changed, +161 −58
  • docs/superpowers/specs/2026-11-07-equipo-mac-runners.md +161 −58

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md b/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md
index 96efc293..1e8733e4 100644
--- a/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md
+++ b/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md
@@ -1,6 +1,6 @@
# Equipo: Mac runners for thin v1
-Status: rev 2, 2026-11-07, after Astra's round 1 (NOT READY at 9852fc8)
+Status: rev 3, 2026-11-07, after Astra's rounds 1 and 2 (9852fc8, 0f6eaa6)
and the controller's steer. Written by Claude (Fable 5.1) from the
approved thin v1 spec (`2026-11-06-equipo-thin-v1.md`), the slice 1 to 4
logs and the code at `thin-v1-slice4` (ca0a65c). Not implemented. Facts
@@ -58,10 +58,18 @@ the connection is the primary, `ack` and the inbox are per person, and
`syncSteps` scans the person's queued and running steps. Rev 2 keeps the
tables and adds a destination:
-- Migration 0045 adds `runner_commands.runner_id` (indexed), backfilled
- with the person's primary, and `steps.runner_id` (nullable, empty
- means not yet placed). `txn.command` takes a runner id; message,
- cancel, reset and `watch_merge` commands name the primary.
+- Migration 0045 adds `runner_commands.runner_id` and `steps.runner_id`
+ (both indexed) and `runners.role`, in this order inside one
+ transaction: add the columns; backfill every runner `primary`; backfill
+ every command and every existing step, in every state including
+ running, pending termination and queued, with the person's primary at
+ migration time (the `primaryRunner` query, run per person); only then
+ does the code that enforces ownership (below) ship, in the same
+ release, so no existing attempt is ever reported or reconciled against
+ an empty owner. A step with an empty `runner_id` after migration is a
+ bug the schema check fails on. `txn.command` takes a runner id;
+ message, cancel, reset, `watch_merge` and `publish` commands name the
+ primary.
- `Pending` serves only commands whose `runner_id` is the connection's
runner; `ack` marks a command acked only if the acking connection is
that runner and holds the current generation and process (the
@@ -77,7 +85,11 @@ tables and adds a destination:
sync omitting a step owned by the primary leaves it untouched; a
report from the wrong runner is refused; a Linux step pending
termination survives a worker's sync and still refuses Retry
- (`TestStepPendingTermination` extended with a second runner).
+ (`TestStepPendingTermination` extended with a second runner); a
+ migration test runs 0045 over a slice 4 database holding a running
+ step, a pending-termination attempt and unacked commands, and shows
+ every row bound to the old primary and every slice 1 to 4 contract
+ test still green on it.
### 1.3 The capability report
@@ -129,16 +141,35 @@ account, session_id)` recorded on the step row, on the runner that holds
it; a different runner, account or a later attempt is refused, and an
offline runner gets "Tito Studio is offline; ask again when it is back."
-**Withdrawal.** Re-placement (offline timeout, revocation, refusal)
-happens in one transaction that marks the old dispatch `withdrawn`
-(never served by `Pending` again) and writes the new one. If the old
-dispatch was already acked, the work is possibly running: the instance
-sends `cancel_step` for that attempt and waits for its terminal report
-with termination before it creates the next attempt elsewhere, exactly
-the Retry rule. A delayed report for a withdrawn or older attempt is
-refused; a delayed checks or review result for an older SHA is dropped
-by the judged-SHA rule and cannot make a newer candidate Ready
-(`TestContractReviewAndChecks` gains a delayed-report case for both).
+**Withdrawal.** An unacked dispatch is not an undelivered one: the
+runner records a dispatch durably and wakes the step engine before it
+sends the ack (`link.go: read`), so a lost ack leaves executable work.
+Rev 3 therefore stops reasoning about delivery and makes **starting an
+attempt a transaction on the instance.** The runner already does a lease
+round trip before any step executes (`judge.go: lease`, `Engineer.lease`);
+that frame becomes `lease{generation, step_id, attempt}` and the
+instance acks it only inside a write transaction that finds the attempt
+assigned to this runner and not withdrawn, and sets `steps.started_at`
+there. Withdrawal is the other side of the same row: in one transaction
+it marks the attempt `withdrawn`, which `Pending` never serves again,
+and reads `started_at`. If it is empty, nothing can ever run: a later
+start authorization for that attempt is refused and the runner deletes
+its row with reason `withdrawn`. If it is set, the work is possibly
+running: the instance sends `cancel_step` and waits for the terminal
+report with termination before it creates the next attempt elsewhere,
+exactly the Retry rule. This is chosen over "treat every unacked
+dispatch as possibly running" because it costs nothing new (the round
+trip exists), it is exact rather than conservative, and SQLite's
+serialisation of the two writes is the proof. Tests: a lost ack (the
+instance resends, the runner's inbox dedups, the attempt is authorised
+once and runs once); withdrawal committed just before the start
+authorization (start refused, no process, re-placement proceeds at
+once); withdrawal committed just after it (withdrawal sees `started_at`,
+takes the cancel path, and the next attempt exists only after
+termination); a delayed report for a withdrawn or older attempt refused;
+a delayed checks or review result for an older SHA dropped by the
+judged-SHA rule so it cannot make a newer candidate Ready
+(`TestContractReviewAndChecks` gains both delayed-report cases).
**Honest outcomes when nobody fits.** No runner has ever had the tags:
checks end `cannot_run`/`needs_macos` at once (today), Engineering runs
@@ -161,32 +192,79 @@ when it is not the primary.
## 2. Candidates travel as packs, not credentials
-The worker has no clone and no forge access. For a step placed on a
-worker, the primary (which already prepares the judge tree with `rev-list
---objects --no-walk` and `pack-objects`, `judge.go: checkRepository`)
-builds the one-commit pack of the candidate and sends it as `blob` frames:
-`blob{key, index, total, sha256, data}`, `data` base64 under 192 KB so a
-frame stays under `MaxFrameBytes`; the instance stores chunks in a
-`blobs` table keyed by (person, key) with the destination runner and a
-24-hour TTL, and `Pending` serves them to that runner only. Blob frames
-are durable and acked like any other. The worker reassembles, checks
-`sha256`, runs `index-pack`, and refuses the step (`candidate_unavailable`)
-unless the pack yields exactly the dispatched `candidate_sha` with a
-complete tree. Bound: 64 MB per candidate; above it the step is
-`cannot_run`/`checks_unavailable` with "candidate too large to relay".
-The worker keeps the objects per repository under its state dir, and
-later dispatches carry a thin pack against what the worker's step
-report says it holds (`have`: the SHAs it has), so Woodstar moves once.
-
-For Engineering on a worker (slice F), the worker commits as the runner
-does today (`add -A`, `write-tree`, `commit-tree` on the base, identity
-`Equipo Engineering`), reports `candidate_sha`, and returns a thin pack
-of the new objects as blobs to the primary. The primary indexes it into
-the task's private repository, verifies the commit's parent is the
-dispatched base and its tree is complete, and calls `PushBranch` with
-every check it has today (repository, task branch, descendant of base,
-person, lease, `--force-with-lease`, record then reconcile). Retry of a
-failed push republishes from the primary's record, as in slice 4.
+The worker has no clone and no forge access. Objects move inside a
+**transfer**, a row the instance opens and that authorises every chunk:
+`transfers{id, person, from_runner, to_runner, repo, task_id, step_id,
+attempt, base_sha, candidate_sha, direction, state, expires_at}`. An
+inbound transfer (primary to worker) is opened in the same transaction
+as the worker's dispatch. An outbound one (worker to primary) is opened
+when the instance accepts the worker's `step{state: running, phase:
+committed, candidate_sha}` report for the current attempt, for exactly
+that candidate. The primary (which already builds a one-commit pack with
+`rev-list --objects --no-walk` and `pack-objects`, `judge.go:
+checkRepository`) or the worker then sends `blob{transfer, index, total,
+sha256, data}` frames, `data` base64 under 192 KB so a frame stays under
+`MaxFrameBytes`, durable and acked like any other.
+
+**Authorization, checked before bytes are kept.** The instance accepts a
+chunk only from the connection of `from_runner`, holding its current
+generation, for a transfer in state `open` whose attempt is the step's
+current attempt and not withdrawn, cancelled or superseded; anything else
+is refused with `transfer_refused` and logged. `Pending` serves chunks to
+`to_runner` only. The receiver, before `index-pack`, checks the transfer
+header against its own step row: repository, task, step, attempt, base
+and candidate must match, and the direction must be the one it expects.
+A transfer closes when its last chunk is acked or its attempt ends, and
+its chunks are deleted; a 24-hour TTL sweeps the rest. Tests, apart from
+byte tampering (M7): a stale attempt's chunks refused after Retry; a
+second worker uploading for a transfer not its own; chunks for task A
+sent under task B's transfer; a candidate that does not match the
+opened transfer; an inbound transfer answered in the outbound direction.
+
+**Integrity.** The worker reassembles, checks `sha256`, runs `index-pack`,
+and refuses the step (`candidate_unavailable`) unless the pack yields
+exactly the dispatched `candidate_sha` with a complete tree. Bound: 64 MB
+per transfer; above it the step is `cannot_run`/`checks_unavailable`
+with "candidate too large to relay". The worker keeps objects per
+repository under its state dir, and later dispatches carry a thin pack
+against the `have` list in its reports, so Woodstar moves once.
+
+**Publication stays the primary's word.** For Engineering on a worker
+(slice F) the worker commits as the runner does today (`add -A`,
+`write-tree`, `commit-tree` on the base, identity `Equipo Engineering`),
+reports `committed` with `candidate_sha`, uploads the thin pack in the
+outbound transfer, and ends its step `done` with `pushed: false`. A
+worker report carrying `pushed: true` is refused. The step gains
+`publication` (`none`, `pending`, `published`, `failed`): when the
+outbound transfer completes, the instance sets `pending` and writes a
+durable `publish{task, step, attempt, candidate_sha, base_sha, transfer}`
+command to the primary's mailbox in the same transaction. The primary
+indexes the pack into the task's private repository, verifies the
+commit's parent is the dispatched base and its tree complete, confirms
+the lease **and the publication id** immediately before the push (the
+existing pre-push confirmation, widened so a cancelled publication is
+refused), and calls `PushBranch` with every check it has today
+(repository, task branch, descendant of base, person, `--force-with-lease`,
+record then reconcile). It then reports durable `published{task, step,
+attempt, candidate_sha, pushed, reason}`; only this report, from the
+primary, for the current attempt and candidate, sets `Step.Pushed` and
+`publication: published`, and only then does `advance` create the checks
+and review steps. `published{pushed: false}` sets `failed` with
+`push_failed` or `push_conflict` and Needs you `retry`; Retry re-sends
+`publish` for the recorded commit (slice 4's republish) without running
+Engineering again. The primary keeps a `publications` table; its `sync`
+lists the ones it holds, the instance resends unacked `publish` commands,
+and `PushBranch`'s record-then-reconcile makes a repeat idempotent.
+Tests: push failure then Retry publishes the same commit once; primary
+SIGKILLed after indexing and before the push, restarted, pushed exactly
+once; primary SIGKILLed after the push and before `published`,
+reconciled from the remote on restart; cancel after pack receipt and
+before push: no push, the candidate never published, the worker's
+objects swept; the worker's `pushed: true` refused. Paul's ruling of
+2026-11-07 stands beside this: Equipo merges its own Ready-to-merge work
+(slice 4c, on the primary), and a Mac Engineering candidate flows into
+that path unchanged once the primary has published it; merging is not
+designed here.
What a worker can reach if its sandbox is escaped (§4.3): its own
enrolment key and state, so it could report a false result **for steps
@@ -233,9 +311,28 @@ then a login shell's `PATH`; versions go in the capability report;
`EQUIPO_CLAUDE_PATH` still overrides. Update: `welcome` gains `release`;
an older worker downloads its target from `/releases/<version>/`,
verifies the manifest digests, swaps the binary between steps and exits
-0 for `KeepAlive`. A worker that meets an unknown durable frame updates
-instead of reconnecting forever (the slice 4 skew loop). Mixed versions
-are a tested state (§6).
+0 for `KeepAlive`.
+
+**Version-aware encoding.** `wire.Strict` rejects unknown fields and
+`Frame.Decode` rejects unknown types, so nothing new may reach a runner
+that has not said it understands it. `hello` gains `protocol` (2 for
+this spec; absent means 1, the slice 4 wire) and `welcome` echoes the
+protocol the instance will speak, the lower of the two. The instance
+encodes every frame per connection with `wire.Encode(frame, protocol)`:
+to a protocol 1 runner it sends exactly the slice 4 frame set and field
+set (`welcome` without `role` or `release`, `dispatch` without `needs` or
+`runner_id`, `lease` without step fields, no `blob`, `publish` or
+`published`), it places no step whose needs are non-empty on it, and it
+treats its capability report as the Linux default. A protocol 1 runner
+is always a primary. The fixture tests encode every new frame at both
+protocols. **Upgrade order:** instance, then the primary, then workers;
+a runner's release comes only from its own instance, so a worker cannot
+run ahead. The reverse pair (a newer runner against an instance rolled
+back) still happens, so a runner whose protocol 2 `hello` is refused by
+a strict decode (the close the instance already sends for a bad frame)
+retries once with a protocol 1 `hello`, logs that the instance is older,
+and runs as a protocol 1 runner until its next `welcome` says otherwise.
+Mixed versions are tested with actual binaries (§6, M8).
### 3.4 Account sign-in and the Keychain hypothesis
@@ -419,16 +516,18 @@ it.
## 6. Wire, API v1, fixtures and testing
-Frames: `hello` adds `platform`, `label`, `sandbox`, `capabilities`;
-`welcome` adds `role`, `release`; `dispatch` adds `needs`,
-`runner_id`; new `blob{key, index, total, sha256, data}` both ways
-(durable); `step` adds `termination_kind`, `have []string`; new step
-reasons `placement_refused`, `withdrawn`; new checks reason
-`runner_offline`. Resources: `Runner` adds `label`, `role`, `since`,
+Frames (protocol 2 only): `hello` adds `protocol`, `platform`, `label`,
+`sandbox`, `capabilities`; `welcome` adds `protocol`, `role`, `release`;
+`dispatch` adds `needs`, `runner_id`; `lease` adds `step_id`, `attempt`;
+new `blob{transfer, index, total, sha256, data}` both ways, `publish`
+(instance to primary) and `published` (primary to instance), all
+durable; `step` adds `termination_kind`, `have []string`, `phase`; new
+step reasons `placement_refused`, `withdrawn`, `transfer_refused`; new
+checks reason `runner_offline`. Resources: `Runner` adds `label`, `role`, `since`,
`platform`, `capabilities`; `RunnerList` at `GET /api/v1/runners`;
`Snapshot.runners`; `Step` adds `runner_id`, `runner_label`, `needs`,
-`placement`, `termination_kind`; `Task` adds `engineering_runner` and
-Needs you `runner_offline`. Fixtures: `api/runners.json`,
+`placement`, `publication`, `termination_kind`; `Task` adds
+`engineering_runner` and Needs you `runner_offline`. Fixtures: `api/runners.json`,
`api/task-placed.json`, `api/task-mac-checks.json` (pass and fail with
`exit_code`), `frames/hello-mac.json`, `frames/welcome-worker.json`,
`frames/dispatch-needs.json`, `frames/blob.json`,
@@ -458,9 +557,13 @@ all refused), `placement_refused` and re-place, withdrawal of an unacked
dispatch, cancel-then-reassign of an acked one, a delayed old-SHA report
that cannot make a newer candidate Ready; M7 blob tampering (bad
`sha256`, wrong SHA, oversize, missing chunk) refused; M8 mixed
-versions: an old runner against a new instance ignores `needs` and
-`blob`, a new worker against an old instance gets no placement, nothing
-is lost; M9 (slice F) Engineering on the worker returns a thin pack, the
+versions with the real slice 4 binaries (instance and runner built from
+ca0a65c in CI and cached as artifacts): the slice 4 runner against the
+new instance speaks protocol 1, runs the `oficina/sample` scenario to
+Ready, and never receives a `blob` or a `needs` field; the new runner
+against the slice 4 instance falls back to protocol 1 after one refusal
+and runs the same scenario; a new worker enrolled against the slice 4
+instance is refused with a clear log line and nothing is lost; M9 (slice F) Engineering on the worker returns a thin pack, the
primary pushes, pinning holds across a fix round and a republish; ask
the implementer pinned and refused elsewhere. All slice 1 to 4 guards
stay, especially Linux termination before Retry.
@@ -492,8 +595,8 @@ by relay; Review stayed on the primary. Zero model turns. The live
| Slice | Content | Size |
|---|---|---|
-| A Mailbox destinations | migration 0045, `runner_id` on commands and steps, per-runner `Pending`, ack, reports and `syncSteps`, role column with existing runners primary, M6's scoping cases, M8 | 1.5 days |
-| B Placement and pinning | capability report, `needs`, placement in `advance`, pinning, withdrawal and cancel-then-reassign, offline rule, `runners` API and view, fake worker (testbuild only), blob relay with M7, M1 to M6 | 2.5 days |
+| A Mailbox destinations and protocol | migration 0045 with the step backfill and its test, `runner_id` on commands and steps, per-runner `Pending`, ack, reports and `syncSteps`, roles with existing runners primary, `protocol` negotiation and `wire.Encode`, M6's scoping cases, M8 with the slice 4 binaries | 2 days |
+| B Placement, transfers and publication | capability report, `needs`, placement in `advance`, start authorization and withdrawal, pinning, offline rule, `runners` API and view, fake worker (testbuild only), transfers with authorization tests and M7, `publish`/`published` with the crash and cancel tests, M1 to M6 | 3 days |
| C Mac probes | P1 to P7 on tito-studio, fixtures recorded, P2 verdict written up | 1 day plus Paul's steps |
| D Darwin checks-only | darwin/arm64 target and manifest, installer and plist, discovery, `--env-file`, self-update, process-group termination, `srt` checks profile from P2, `xcodebuild test` synthesis | 2.5 days |
| E Witness | Woodstar real pass or fail on tito-studio | 0.5 day |