# Darwin progress: the Mac side of Mac runners (slice D, checks only)

Branch `thin-v1-darwin` from `thin-v1-runners` at 1b89bd1 (slices A and
B, Linux). Spec: `docs/superpowers/specs/2026-11-07-equipo-mac-runners.md`
rev 4. First Mac: tito-studio, user `equipo-paul`. Nothing here has run
on a Mac: everything is tested on Linux with recorded outputs, fakes for
srt and xcodebuild, and the test build's fake worker. Conventions as in
`RUNNERS-PROGRESS.md`.

## Done

1. **The runner builds for darwin/arm64.** It did not: openat2, O_PATH,
   pidfds, prctl, close_range, SO_PEERCRED, the Linux pty ioctls and
   the boot-time clock. Each is behind a `_linux.go`/`_darwin.go` pair;
   on macOS the bubblewrap-only calls refuse (ENOSYS). The containment
   launcher reaches unix through `containment/sysunix`, so
   `NamespaceMain`'s text and the certified launcher digest are
   unchanged. `make build` (CI 05-build) cross-compiles the runner and
   the tool proxy.
2. **`internal/runner/mac`**, the Darwin pieces:
   - `ChecksSettings`: the §4.4 srt settings over the §4.2 deny list, in
     srt 0.0.81's schema (read from its package: `network.allowedDomains`,
     `deniedDomains`, `filesystem.denyRead`, `allowWrite`, `denyWrite`
     required; `allowMachLookup` takes a trailing `*`). No network;
     writes only to the tree, the attempt's scratch, DerivedData and
     SwiftPM caches. Refuses globs, relative paths and a tree inside a
     denied place (srt's denyWrite wins over allowWrite).
   - `Gate`: process-group termination (§5): own session, marker,
     environment from scratch, caffeinate `-w`, SIGTERM, 10 s, SIGKILL,
     a sweep of marked processes (`ps -E` on a Mac, `/proc` on Linux),
     `simctl shutdown` of what the attempt booted, proof only when the
     group is gone and nothing marked is left within 30 s. After a
     restart a reused group id is killed only if a marked process is
     in it.
   - Capabilities from `xcodebuild -version`, `simctl list -j`, swift,
     node, srt, claude; the `xcodebuild test` gate for a project with no
     gate (one shared scheme or the one named like it; newest iPhone
     simulator by UDID; DerivedData in scratch; no signing; several
     candidates or none is `checks_unavailable`).
   - Probes P1 to P7 and the hostile fixture (run-script phase with
     Xcode's own script sandbox off, SwiftPM build tool plugin, XCTest),
     shipped in the binary. P2 is `denied` only when every attempt of
     every place says denied and nothing outside contradicts it: a
     loopback listener per place catches a connection behind a
     "denied" line; DNS and Keychain controls run outside first; a
     missing line is not a denial. P3 and P5 say why they did not run.
   - The launchd agent; the installer's account refusals; the pinned
     srt lockfile (`npm ci`, every package by integrity).
3. **Wire** (protocol 2, omitempty, dropped at protocol 1):
   `capabilities.probes` and `step.checks_sandbox`. Fixtures
   `frames/hello-mac-probes.json`, `frames/step-mac-checks.json`.
4. **Worker on a Mac** (`thin/mac.go`): each attempt's gate follows the
   newest probe report; trees under the scratch root (outside the
   denied state dir); probes run at start when the report is not this
   version's and profile's, steps wait for them; `equipo-runner probe`
   on demand; self-update to the instance's release (darwin target,
   digest, swapped while no step runs, exit 75); `run --env-file`.
   The test build's fake worker now runs the Mac gate; it labels its
   checks none (it has no sandbox) unless `EQUIPO_FAKE_SANDBOX=seatbelt`
   makes it play a Mac whose P2 denied, as `TestMacWorker` does so that
   Equipo still merges its scenarios on its own.
5. **Install**: `install-v1.sh` dispatches on `uname` (Darwin/arm64:
   refuses root, reads the darwin target with plutil, checks shasum);
   `equipo-runner install` on a Mac refuses root, administrators, users
   not named `equipo-*`, another user's home and a readable foreign
   home, copies the runner, installs srt, writes `runner.env`, enrols
   (the link carries the code), loads the agent. `GET /install.sh` is
   `curl -fsSL https://<instance>/install.sh | sh`.
6. **Release**: `make release-runner` builds `darwin-arm64/` beside the
   Linux runner (and checks it for the fake worker);
   `install-manifest.json` gains `targets`; the instance serves the Mac
   files when they match; `staged-artifacts.py` records both targets.
7. **Instance**: migration 0055 `chat_steps.checks_sandbox`; a worker's
   checks carry `seatbelt` or `none` (anything else is none); step and
   task show it; "ran outside the sandbox" on the checks line, badge,
   timeline and Ready to merge card; the primary's checks are never
   labelled. The runners view (Connections, Machines) shows platform,
   where checks run and each probe. One-tap enrolment page.
8. **Docs**: `docs/mac-runner.md`, Paul's four steps.

Tests (each seen failing first or by a mutation, list below):
`TestChecksSettings*`, `TestGate*`, `TestParseMarked`,
`TestCapabilitiesFromRecordedTools`, `TestXcodeGate`,
`TestRunProbesAllDenied`, `TestP2IsDeniedOnlyWhenEverythingIs`,
`TestJudgeP2`, `TestP4`, `TestFixtureShips`, `TestACSleepAndNode`,
`TestRefuseAccount`, `TestReadAccount`, `TestHomes`, `TestLaunchAgent`,
`TestSRTPinned`, `TestMacWorkerConfig`, `TestWorkerMacReports`,
`TestMacChecksPick`, `TestMacProbesStart`, `TestMacFind`,
`TestMacUpdater`, `TestInstallMacRefusals`, `TestInstallMac`,
`TestEnvFileAndExits`, `TestMacInstallShell`,
`TestInstallPackagingDarwinTarget`, `TestStagedArtifactsGate`
(extended), `TestCapabilitiesGuard` and
`TestEncodeProtocol1IsTheSlice4Wire` (extended),
`TestContractChecksPlacedOnTheWorker` (extended: darwin capabilities
with probes, the label, the primary unlabelled),
`TestChecksOutsideTheSandboxAreLabelled`, `TestRunnersViewShowsProbes`,
`TestInstallScript`, `TestEnrolmentLinkIsOneTap`,
`TestOnboardingPairingBound` (extended). `TestMacWorker` (headless,
M1/M2/M4/M5) passes on the shared gate.

Mutations, each killed: profile (Keychains dropped, install dir not
denied, nesting check off); gate (status file ignored, sweep off,
reused group killed, shutdown of what was already booted, inherited
environment, proof with marked left); capabilities (unavailable
simulators, xcode tag without Xcode); xcode gate (two projects, two
schemes); probes (accepted connection ignored, missing line as denied,
DNS control ignored, sentinel kept, path in P4, srt-ran without the
build); account (admin), launchd (SuccessfulExit); thin (same-version
update, digest ignored, swap without the step lock, pick, probe rerun,
bash path, reason ignored, label dropped, ready ignored); install
(readable home, account, Intel, srt path, launchd exit); script (root,
version, digest length, Darwin/Intel); release (darwin served when
tampered, staged darwin, target version); instance (worker label on the
primary, seatbelt default, task label); views (label, probes); config
(overlap); enrolment link.

## Astra round 1 (45b6335), fixed

1. P2 on the simulator: the hostile test runs on the newest iOS
   simulator (none: P2 unavailable) and tries the host's login keychain
   file from there; denied needs the build and test completed under srt
   and the end proven. P6's test hashes and writes files until killed.
   `TestP2NeedsTheSimulatorAndAProvenEnd`.
2. Unforgeable verdict: the report lives only in the worker's memory;
   nothing on disk is read back as a verdict; `equipo-runner probe`
   only asks for a new run. Trusted while this version's, this
   profile's, made with the srt, Node and ripgrep on disk now
   (fingerprint) and under a day old; otherwise checks run labelled
   outside the sandbox and the probes run again. `TestMacProbesTrust`,
   `TestSRTFingerprint`.
3. Record before running: marker recorded before anything starts (the
   worker's git processes carry it too), group recorded once it exists,
   nothing runs or the group is killed if a record fails; recovery never
   takes an unrecorded attempt as ended (UnrecordedStep, settled by the
   marker on a worker, by "no namespace left" on Linux).
   `TestGateRecordsBeforeRunning`, `TestGateVerifyByMarkerAlone`,
   `TestWorkerRecordsBeforeRunning`, `TestStepRecoverUnrecorded`.
4. Homes: closed only if this user can neither list, traverse (a
   missing name answers "not found" to a searcher) nor open a usual
   file; symlinked homes and their targets; a /Users that cannot be
   read stops the installer, fails P4 and denies all of /Users.
   `TestHomes`. On Linux the file-read check is not separately
   testable (reading needs traversal), on a Mac ACLs could differ.
5. Reinstall stops the agent before replacing anything; the enrolment
   check then gets the state lock. `TestInstallMacAgain`.
6. Worker only: the Mac says so when it begins enrolment
   (`worker_only`, migration 0055 `runner_enrolments.worker_only`); the
   instance refuses to show or approve it for a person with no primary
   ("Add your main runner first"). The runner refuses a welcome as
   primary (the runners round's ErrRoleMismatch).
   `TestMacEnrolmentNeedsAPrimary`, `TestWorkerEnrolRefusesAnOlderInstance`.
7. Output: 200 lines of at most 4 KB, enforced on every write.
   `TestTailIsBounded`.
8. The env file's values reach the Mac host (Options.Getenv), and every
   tool it runs gets the runner's Node and ripgrep first on PATH.
   `TestMacHostPaths`.
Also: Linux-only tests carry a linux build tag and `make vet` vets the
runner for darwin/arm64. Merged thin-v1-runners d7c803b, then 15feb20
(enrolled role file, cancel before withdrawal, two-phase removal). A
Mac also checks the role the instance put in its enrolment credential:
anything but worker keeps nothing (`ErrEnrolledAsPrimary`) and the
installer says to add the main runner first (`TestEnrolKeepsTheRole`,
`TestInstallMacEnrolledAsPrimary`).

## Astra round 2 (be0f1e3 and 9e407e2), fixed

1. Forged approval: the tools srt runs on are checked against pins
   compiled into the runner, not a fingerprint taken at run time:
   ripgrep's and Node's programs as the pinned archives unpack them
   (`RGBinarySHA256`, `NodeBinarySHA256`) and the srt package tree
   `npm ci` makes from the shipped lockfile (`SRTTreeSHA256`; the same
   with npm 11.17 and Node 22.23.4's own npm 10.9.9), each at its
   installed place and srt's .bin link at its fixed target. Checked
   before and after every probe run and before every sandboxed check;
   the installer checks them too. A runner is tainted for good once any
   check runs outside the sandbox (labelled none): it never labels a
   check sandboxed again, whatever a later probe says. The taint is kept
   in the state dir and by the instance (`runners.tainted_at`, set from
   a tainted hello or any worker check labelled none, never cleared; the
   instance labels a tainted runner's checks none whatever it reports,
   and says tainted in every welcome). The runners view and
   docs/mac-runner.md say so. `TestVerifyToolsRefuses`,
   `TestVerifyToolsReal` (with the real archives and npm tree, run here:
   a one-byte counterfeit srt, a moved ripgrep and a re-pointed srt link
   all fail), `TestMacCounterfeitSRT`, `TestMacTaintIsSticky`,
   `TestContractWorkerTaintIsSticky`, `TestInstallMacVerifiesThePins`.
2. Reinstall: an agent launchd has is booted out, and a refused bootout
   stops the installer at once; it then waits, bounded, until launchd
   no longer has it and the state lock is free, or changes nothing and
   says so. `TestInstallMacWhenTheRunnerWillNotStop`.
3. Archive links: entries are created through an os.Root; no symbolic
   or hard link from an archive is ever made; Node's npm and npx links
   are made afterwards with fixed targets, corepack is left out.
   `TestFetchMakesNoLinksFromTheArchive` (the chained-link archive).

Env-gated tests (the real archives and npm tree are not downloaded in
CI) were run here and pass.

## Restage finding: the tool proxy

`make release` refused b4a3b6d: the darwin portability edit to
internal/toolproxy (O_PATH behind a per-OS constant) changed the Linux
tool proxy's bytes, and its digest is certified. internal/toolproxy is
back to exactly its 1b89bd1 source; the runner reaches it only on Linux
(ServeToolProxy in tool_proxy_serve_linux.go), and the Mac release has
no tool proxy (a worker has no coordinator to serve). The darwin target
names only the runner. `TestToolProxyIsTheCertifiedBuild` builds the
tool proxy as the release does and compares it with the certified
digest, so CI catches this from now on.

## The Mac user's name (Paul, 2026-11-10)

macOS's Add User dialog made `paulequipo` from "Paul Equipo". The
installer now accepts any Standard, non-root user whose short name
contains "equipo" in any case (`paulequipo`, `equipo-paul`,
`paul-equipo`); admin, root and home isolation are unchanged. Otherwise
it says "Equipo runs in its own Mac user so it can't reach your files.
Create a Standard user with 'equipo' in its account name, then run this
again." `TestRefuseAccount`, `TestInstallMacAddUserDialogName`.

## Decisions

- **P2 not denied:** checks still run (ruling 2), labelled none. If the
  fixture at least built and tested under srt, srt still confines them
  (the boundary is unproven, not absent); otherwise they run with no
  sandbox. Only P2 `denied` is labelled seatbelt.
- srt exits 0 when its command dies of SIGTERM (cli.ts). A pass needs
  srt's exit and the status the gate's shell recorded both 0.
- launchd restarts only after a non-zero exit (KeepAlive
  SuccessfulExit false): an update exits 75; a superseded runner exits
  0 on a Mac (3 on Linux). The spec said "exits 0 for KeepAlive"; that
  would also restart a superseded runner into a lease fight.
- srt is installed privately (`~/.local/lib/equipo-runner/srt`, `npm ci`
  from a shipped lockfile), not `npm install -g`: a Standard user cannot
  write Homebrew's global prefix, and the lockfile pins every package.
- What srt needs on macOS, per its README and package.json: ripgrep, and
  Node.js 22.12 or later to run (`sandbox-exec` is built in). A Standard
  user cannot use Homebrew, so the installer fetches both from their
  official releases into `~/.local/lib/equipo-runner/tools`: ripgrep
  15.2.0 (`ripgrep-15.2.0-aarch64-apple-darwin.tar.gz`, sha256
  3750b2e9...973e4, the release's own `.sha256` asset) and Node v22.23.4
  LTS (`node-v22.23.4-darwin-arm64.tar.gz`, sha256 c9e1dbc7...b66428,
  from SHASUMS256.txt), both re-checked by downloading them. The digest
  is checked before anything is unpacked; unpacking keeps every entry
  and symlink inside the archive's root. ripgrep's binary links only
  libSystem and libiconv. The runner puts both first on its own PATH
  and the gates' (srt starts through `env node`). `TestToolPins`,
  `TestFetchChecksTheDigest`, `TestFetchKeepsToTheRoot`; with
  EQUIPO_TOOL_ARCHIVES set, `TestFetchRealArchives` unpacks the real
  archives (it did, here).
- No `claude` tag on a Mac until slice F: nothing but checks is placed
  there.
- Mach services are candidates (`com.apple.CoreSimulator.*`,
  `com.apple.dt.*`, `com.apple.testmanagerd*`,
  `com.apple.coresymbolicationd`); P2 shows whether xcodebuild runs
  with them. The list is never widened automatically.
- The plist is generated per user by the installer, not shipped as a
  file.
- `/install.sh` names the team id the runner enrols with (no secret; a
  person still approves).

## Only the Mac can show

Everything Seatbelt and Xcode do: whether the profile lets
`xcodebuild test` reach the simulator (the Mach list), whether code run
by XCBBuildService, CoreSimulatorService, the plugin or the test
inherits the sandbox (P2's question), Keychain reads from inside srt
(srt allows securityd, so P2 probably fails on the Keychain and brings
ruling 2 in), `ps -E` and `simctl` outputs (recorded shapes), the
fixture's first build, `pmset` on a Mac Studio, `launchctl bootstrap`
as a Standard user, `xcodebuild -runFirstLaunch` without admin (likely
refused; ignored), the darwin binary's ad-hoc signature, srt needing
ripgrep on macOS, the self-update swap under launchd.

## Open issues

- **A likely fifth step:** macOS homes are often listable by the
  `staff` group. The installer then stops and names the ACL that shuts
  out only the Equipo user (`sudo chmod +a "<user> deny
  list,search,readattr,readextattr,readsecurity" <homes>`, undone with
  `chmod -a` and the same entry). P4 reports it too.
- Auto-merge: until slice 4c's rule for checks outside the sandbox
  exists (passed only for the creator's own repositories, spec §4.3),
  Equipo never merges those on its own; it asks "Merge <title>?"
  (`TestContractChecksPlacedOnTheWorker`).
- Sandbox violations are not tailed from `log stream` (§4.5); P2 does
  not read the unified log for the Mach services xcodebuild was denied.
- CI under load: A5 (headless connections) saw "signed out" while the
  Codex home was still being deleted (the instance infers signed out
  from the hello the runner sends once the binding is dropped); the test
  now waits for the home. `make test` passes `-timeout 15m` so the
  headless package's 720s budget, not go test's 10-minute panic, judges
  it on a loaded runner.
- Tool discovery skips `npm root -g` and a login shell's PATH.
- An srt, Node or ripgrep pin change needs the installer run again;
  self-update swaps only the runner.

## Installing under su or sudo (2026-11-10)

Paul's first install, from `sudo su paulequipo`, stopped on
`TMPDIR: parameter null or not set`. Neither installer now needs
anything from the environment:

- `install-v1.sh` works in `$TMPDIR` when set, else the user's own
  temporary folder (`getconf DARWIN_USER_TEMP_DIR`), else `mktemp -d`,
  else a private folder in the user's own home (`~/.cache/
  equipo-bootstrap`). On a Mac it sets HOME from the user directory
  (`dscl`) before handing over, and appends the system folders to PATH.
  `TestMacInstallShellUnderSu` runs it with TMPDIR unset and HOME set to
  another user's home (fails on the old script with Paul's error).
- `equipo-runner install` reads the home from `dscl` (`mac.ReadHome`),
  never `$HOME`, and runs npm and xcodebuild with HOME, USER and LOGNAME
  of the user (`userEnv`). `TestInstallMacIgnoresInheritedHome`;
  mutations (home from `$HOME`, `userEnv` keeping HOME, xcodebuild
  given `$HOME`) fail it.
- Before changing anything it checks the login session
  (`launchctl print gui/<uid>`); without one it says "Log in as <user>
  on this Mac (fast user switching) and keep it logged in, then run this
  again." (`runner.mac.not_logged_in`). From `sudo -iu` it installs when
  the session exists. Refusal case "logged out"; removing the check
  fails it.
- The home-isolation message now suggests the targeted ACL instead of
  `chmod 700` (`TestInstallMacHomeACLMessage` checks the exact text).
  The isolation check already counts an ACL deny as closed: it tries to
  list, pass through and open a file in each home and counts only
  permission denied as closed.

## Enrolment that waits and says why (2026-11-10)

Paul's install printed the link (H0SNVFN19S), polled staging from 11:58
to 12:06 UTC, then ended on "Runner installation is unavailable." The
enrolment row shows it was never approved (no page load or approve POST
after 11:58; last good poll 12:06:23). The next poll, at 12:06:28, got a
5xx; any answer other than 200 or 409 ended `runner.Enrol`, and neither
the instance (no log line for a 503 to a device) nor the installer (the
bare unavailable line) said what it was. The approval path itself works
for a Mac joining a person with a Linux primary
(`TestMacEnrolmentApprovedAfterAPrimary`).

- `runner.Enrol` waits out no answer, 5xx and 429, backing off from the
  poll interval up to a minute, until the code expires; the protocol
  question and the start of the enrolment are tried up to four times. A
  5xx on the protocol question is no longer "the instance is older".
- 403 is "expired" within a minute of the code's expiry, "turned down"
  otherwise; running out is "expired", unless it was still failing,
  which is reported as that failure. Expired or turned down, the saved
  code is dropped so the next run gets a new link.
- `Config.EnrolNotify` hears "waiting" once and each retry; both
  installers print "Waiting for you to approve…", each retry with its
  cause, and at the end the expiry, the refusal or "Adding this machine
  to Equipo failed: <cause>" before the unavailable line; the same lines
  go to the install log (`~/Library/Logs/equipo-runner/install.log` on a
  Mac, `install.log` in the runner root on Linux). Causes are the HTTP
  status and error key or the network error: never a body.
- The instance logs a server error on the two device routes, with the
  route and the error (`TestEnrolmentServerErrorIsLogged`).
- Tests: `TestEnrolWaitsOutTransientFailures`, `TestEnrolEndsInWords`,
  `TestInstallMacEnrolmentInWords`. Mutations shown failing: transient
  never retried, a 5xx protocol answer taken as older, turned down
  reported as expired, the used code kept, the last failure hidden by
  expiry.
- Open: the approve button's confirmation lasts five minutes, the code
  ten. Tapping a page opened more than five minutes earlier is refused
  ("You do not have access to this page"); opening the link again
  works.

## Copy for review

All marked COPY ACCEPTED FOR NOW and listed in the plan 3 inventory:
`runner.mac.*` (installer lines, `runner.mac.not_logged_in` and the
ACL wording of `runner.mac.home` and `runner.enrol.*` added
2026-11-10), `runner.add_title` ("Add %s to your
team"), the runners view (`runner.platform`, `runner.checks_run`,
`runner.sandbox.*`, `runner.probes`, `runner.probe.P1` to `P7`,
`runner.verdict.*`), `work.checks.outside_sandbox` ("%s, ran outside
the sandbox"), and `docs/mac-runner.md`.
