oficina / equipo Public

mac: record a T cleanup before the attempt; prove its end to recover

Astra round 2 of 3 (gpt-6-astra, effort high), on the full diff against
main. Verdict: READY AFTER FIXES, with two Important findings, both
mechanical. Both are folded in here.

- Pending recovery skipped the termination proof. The next gate
  cleaned T for an attempt whose end was unproven, without checking
  that attempt's group or marker or shutting its simulators down. Now
  the record (<state>/mac-gate.lock.pending, JSON) carries the
  attempt's marker and, once it starts, its process group.
  Gate.finishPending first proves that attempt over, the way Verify
  does (settle: its group and every process with its marker gone,
  killed if need be). It then shuts the simulators down
  (QuietSimulators), cleans T against the earlier listing and drops
  the record. Not proven, not cleaned, or a record that cannot be
  read: the gate runs nothing (checks_unavailable). The plugin-cache
  warm also skips while a record is pending (Turns.Pending).
- Pending state could vanish before recovery. The listing lived only
  in memory until a cleanup failed, so a runner killed mid-run left
  nothing, and leavePending ignored write errors. Now the record is
  written (fsync, then rename) after the listing and before anything
  of the attempt starts. If it cannot be written, nothing runs. It is
  rewritten with the group after the start (best effort; the first
  record already has the marker). It is removed only once the end is
  proven and T is cleaned. A turn that cannot be taken for a reason
  other than cancellation is now checks_unavailable, not "cancelled".

Tests: TestGatePendingCleanupSurvivesTheRunner (a killed runner's
record and leftovers: the next gate runs nothing while that attempt's
marker is alive; once it is gone the leftovers are removed before the
next gate runs, simulators are shut down for both, and the record is
dropped; an unreadable record and one that cannot be written each
mean nothing runs). TestMacWarmsThePluginCacheOncePerXcode now also
checks that no warm runs while a record is pending.
Broken and seen failing: recovery without the proof, no record before
the start, the record never dropped, and the warm ignoring a pending
record.
Budget: internal/runner/thin 17160/8914 -> 17165/8918 (measured).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 2248b3a7eb696d3d0d54d0e5d2a48c6e739471e8 parent 9447cd3
6 files changed, +174 −29
  • .rastrillo/budgets.txt +1 −1
  • internal/runner/mac/gate.go +45 −4
  • internal/runner/mac/usertemp.go +60 −24
  • internal/runner/mac/usertemp_test.go +59 −0
  • internal/runner/thin/mac.go +5 −0
  • internal/runner/thin/mac_test.go +4 −0

CI passed — run details

diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 406e8381..c6446178 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -34,7 +34,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full
perf GET /releases/* skip Verified runner release file downloads, not browser GET screens.
perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen.
time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s; niced serial reruns measured 5.773s and 5.750s. The added coordinator mount check has no repeated launches to remove; 15s leaves 38 percent headroom for namespace, process-exit and recovery assertions.
-size internal/runner/thin 17160 8914 Mac simulators before T: quietSimulators shuts every simulator down (bounded) before a T cleanup and logs what is left (about 43 lines), and its test with a hung simctl (about 45 lines); measured 17160/8914. Mac user temp: the Mac host resolves the user's T and refuses an untrusted one (macUserTemp, why in words), gives every gate one turn across the worker and the probe command, and warms Xcode's plugin cache once per Xcode outside the sandbox (warm, warmNow; about 71 lines); its tests pin T on the srt gates, a refused T and the warm's once, retry and turn (about 46 lines); measured 17117/8869. Engineering in an empty repository: the step starts from no base and tells Engineering so, the push names an unborn default, Review reads an initial commit against the empty tree (changeDiff), checks list its files, and a repository whose only branches are task branches stays empty (onlyTaskBranches; about 60 lines); their tests (the task-branch, review diff and prompt tests in index_empty_test.go, about 92 lines): measured 17046/8823. Mac checks wait for the sandbox: macChecks.Run refuses unproven without the dispatch's consent, the consent context, the worker's refusal report and the link's protocol 7 gate (about 38 lines), and their tests (sandbox_consent_test.go, about 131 lines); measured 16986/8731. Mac Xcode scratch: the Mac host test pins the gate's environment (the runner user's HOME kept, no scratch home; 6 lines); measured 16948/8600. Empty repositories merged onto main: measured 16948/8594. Empty repositories: the index lists a reachable repository with no commits as empty, DefaultBranch tells that from no access (lsRemote), reads of it say so, and the handshake hello keeps empty entries back until a protocol 6 welcome (about 52 lines); their tests (index_empty_test.go, the handshake hello at protocols 5 and 6, startLinkWith; about 183 lines). Token row facts merged onto main: measured 16896/8411. Token row facts read the check's rate limit and record it as a turn's (TokenCheck, the Verify wiring, about 40 lines); measured 16614. The leftover helper's debug line adds 3 lines: measured 16572. The Mac host's hang fix and probe pacing add the process group and its kill (procgroup_unix.go, procgroup_other.go), the bounded wait for a command's output, and the untrusted report's rerun decision with its tool fingerprint (about 165 lines); measured 16569. Runner startup logs add the info lines a silent start is pinned to a phase by (startup phases, the Mac host's xcode-select and capability commands, slow-command warnings, the probes, and the link's connecting, hello and welcome lines: startPhase, openRunner, watchSlow and logged, about 155 lines); measured 16405. Merge authority thin v1 adds the review's measured change facts (facts.go: raw and numstat listings, modes, signing lines, the revert tree check, about 230 lines), the merge_request confirmation and the merge's provenance; measured 16196 with spend-1 merged. Spend 1 resumes a fix round in Engineering's kept session on its healthy connection (fixSession, fixPlan, fixPrompt, keptCommit, about 90 lines); measured 15873. Claude's sign-in by a link's review round 1 contains its setup-token in a recorded namespace (the contained terminal, its proven stop and the start's recovery before a home goes, about 130 lines); measured 15787. Claude's sign-in by a link adds the runner's own setup-token attempt, the code's sealed delivery with its crash boundaries and the shared token commit (signin.go, about 300 lines, less the removed terminal watcher); measured 15655. Claude setup tokens add sealed delivery, the token check, Check again and recovery (token.go, tokencheck.go, about 700 lines) beside the composer and Mac lines; measured 15239. Astra round 2 moves the attachment quota to admission: arriving files counted by declared size, admissions protecting a file until its message names it, room made from the oldest unprotected files, refusal as runner_storage_full, and a sweep that stops when protection cannot be read (about 150 lines); measured 12191. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path. Mac P2 diagnostics hand the probes' host runner.log's WARN (macHost.warn, 8 lines) and pin it with a test (12 lines): measured 16854/8411. Mac probe deadlines bound the booted simctl list, move the worker's wait for the probes out of its lock (hold) and warn when a probe run reaches its limit (about 24 lines); their tests (mac_stall_test.go: a fake xcrun that never answers, probes stalled while an update applies, about 270 lines) beside the Mac host they drive: measured 16846/8399. Release slice 1 merged onto main: measured 16822/8130. Release slice 1 (hosted checks) adds the hub's hosted CI verdict for checks: the deferred one-read poll with its persisted deadline, the one-snapshot verdict, the failing units and the restart case (judge_hosted.go, about 200 lines) and the forge's CI reads (forge.go, about 40); measured 16821. Its tests (judge_hosted_test.go, about 270 lines) take the package's tests to 8113, beside the step engine they drive. The leftover helper's debug line adds 3 lines: measured 16572. The Mac host's hang fix and probe pacing add the process group and its kill (procgroup_unix.go, procgroup_other.go), the bounded wait for a command's output, and the untrusted report's rerun decision with its tool fingerprint (about 165 lines); measured 16569. Runner startup logs add the info lines a silent start is pinned to a phase by (startup phases, the Mac host's xcode-select and capability commands, slow-command warnings, the probes, and the link's connecting, hello and welcome lines: startPhase, openRunner, watchSlow and logged, about 155 lines); measured 16405. Merge authority thin v1 adds the review's measured change facts (facts.go: raw and numstat listings, modes, signing lines, the revert tree check, about 230 lines), the merge_request confirmation and the merge's provenance; measured 16196 with spend-1 merged. Spend 1 resumes a fix round in Engineering's kept session on its healthy connection (fixSession, fixPlan, fixPrompt, keptCommit, about 90 lines); measured 15873. Claude's sign-in by a link's review round 1 contains its setup-token in a recorded namespace (the contained terminal, its proven stop and the start's recovery before a home goes, about 130 lines); measured 15787. Claude's sign-in by a link adds the runner's own setup-token attempt, the code's sealed delivery with its crash boundaries and the shared token commit (signin.go, about 300 lines, less the removed terminal watcher); measured 15655. Claude setup tokens add sealed delivery, the token check, Check again and recovery (token.go, tokencheck.go, about 700 lines) beside the composer and Mac lines; measured 15239. Astra round 2 moves the attachment quota to admission: arriving files counted by declared size, admissions protecting a file until its message names it, room made from the oldest unprotected files, refusal as runner_storage_full, and a sweep that stops when protection cannot be read (about 150 lines); measured 12191. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path. The paste box house rule merged onto the runner logs: measured 16573. The leftover helper's debug line adds 3 lines: measured 16572. The Mac host's hang fix and probe pacing add the process group and its kill (procgroup_unix.go, procgroup_other.go), the bounded wait for a command's output, and the untrusted report's rerun decision with its tool fingerprint (about 165 lines); measured 16569. Runner startup logs add the info lines a silent start is pinned to a phase by (startup phases, the Mac host's xcode-select and capability commands, slow-command warnings, the probes, and the link's connecting, hello and welcome lines: startPhase, openRunner, watchSlow and logged, about 155 lines); measured 16405. Merge authority thin v1 adds the review's measured change facts (facts.go: raw and numstat listings, modes, signing lines, the revert tree check, about 230 lines), the merge_request confirmation and the merge's provenance; measured 16196 with spend-1 merged. Spend 1 resumes a fix round in Engineering's kept session on its healthy connection (fixSession, fixPlan, fixPrompt, keptCommit, about 90 lines); measured 15873. Claude's sign-in by a link's review round 1 contains its setup-token in a recorded namespace (the contained terminal, its proven stop and the start's recovery before a home goes, about 130 lines); measured 15787. Claude's sign-in by a link adds the runner's own setup-token attempt, the code's sealed delivery with its crash boundaries and the shared token commit (signin.go, about 300 lines, less the removed terminal watcher); measured 15655. Claude setup tokens add sealed delivery, the token check, Check again and recovery (token.go, tokencheck.go, about 700 lines) beside the composer and Mac lines; measured 15239. Astra round 2 moves the attachment quota to admission: arriving files counted by declared size, admissions protecting a file until its message names it, room made from the oldest unprotected files, refusal as runner_storage_full, and a sweep that stops when protection cannot be read (about 150 lines); measured 12191. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path.
+size internal/runner/thin 17165 8918 Mac pending cleanup: the warm waits while an attempt's cleanup is pending (5 lines, test 4); measured 17165/8918. Mac simulators before T: quietSimulators shuts every simulator down (bounded) before a T cleanup and logs what is left (about 43 lines), and its test with a hung simctl (about 45 lines); measured 17160/8914. Mac user temp: the Mac host resolves the user's T and refuses an untrusted one (macUserTemp, why in words), gives every gate one turn across the worker and the probe command, and warms Xcode's plugin cache once per Xcode outside the sandbox (warm, warmNow; about 71 lines); its tests pin T on the srt gates, a refused T and the warm's once, retry and turn (about 46 lines); measured 17117/8869. Engineering in an empty repository: the step starts from no base and tells Engineering so, the push names an unborn default, Review reads an initial commit against the empty tree (changeDiff), checks list its files, and a repository whose only branches are task branches stays empty (onlyTaskBranches; about 60 lines); their tests (the task-branch, review diff and prompt tests in index_empty_test.go, about 92 lines): measured 17046/8823. Mac checks wait for the sandbox: macChecks.Run refuses unproven without the dispatch's consent, the consent context, the worker's refusal report and the link's protocol 7 gate (about 38 lines), and their tests (sandbox_consent_test.go, about 131 lines); measured 16986/8731. Mac Xcode scratch: the Mac host test pins the gate's environment (the runner user's HOME kept, no scratch home; 6 lines); measured 16948/8600. Empty repositories merged onto main: measured 16948/8594. Empty repositories: the index lists a reachable repository with no commits as empty, DefaultBranch tells that from no access (lsRemote), reads of it say so, and the handshake hello keeps empty entries back until a protocol 6 welcome (about 52 lines); their tests (index_empty_test.go, the handshake hello at protocols 5 and 6, startLinkWith; about 183 lines). Token row facts merged onto main: measured 16896/8411. Token row facts read the check's rate limit and record it as a turn's (TokenCheck, the Verify wiring, about 40 lines); measured 16614. The leftover helper's debug line adds 3 lines: measured 16572. The Mac host's hang fix and probe pacing add the process group and its kill (procgroup_unix.go, procgroup_other.go), the bounded wait for a command's output, and the untrusted report's rerun decision with its tool fingerprint (about 165 lines); measured 16569. Runner startup logs add the info lines a silent start is pinned to a phase by (startup phases, the Mac host's xcode-select and capability commands, slow-command warnings, the probes, and the link's connecting, hello and welcome lines: startPhase, openRunner, watchSlow and logged, about 155 lines); measured 16405. Merge authority thin v1 adds the review's measured change facts (facts.go: raw and numstat listings, modes, signing lines, the revert tree check, about 230 lines), the merge_request confirmation and the merge's provenance; measured 16196 with spend-1 merged. Spend 1 resumes a fix round in Engineering's kept session on its healthy connection (fixSession, fixPlan, fixPrompt, keptCommit, about 90 lines); measured 15873. Claude's sign-in by a link's review round 1 contains its setup-token in a recorded namespace (the contained terminal, its proven stop and the start's recovery before a home goes, about 130 lines); measured 15787. Claude's sign-in by a link adds the runner's own setup-token attempt, the code's sealed delivery with its crash boundaries and the shared token commit (signin.go, about 300 lines, less the removed terminal watcher); measured 15655. Claude setup tokens add sealed delivery, the token check, Check again and recovery (token.go, tokencheck.go, about 700 lines) beside the composer and Mac lines; measured 15239. Astra round 2 moves the attachment quota to admission: arriving files counted by declared size, admissions protecting a file until its message names it, room made from the oldest unprotected files, refusal as runner_storage_full, and a sweep that stops when protection cannot be read (about 150 lines); measured 12191. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path. Mac P2 diagnostics hand the probes' host runner.log's WARN (macHost.warn, 8 lines) and pin it with a test (12 lines): measured 16854/8411. Mac probe deadlines bound the booted simctl list, move the worker's wait for the probes out of its lock (hold) and warn when a probe run reaches its limit (about 24 lines); their tests (mac_stall_test.go: a fake xcrun that never answers, probes stalled while an update applies, about 270 lines) beside the Mac host they drive: measured 16846/8399. Release slice 1 merged onto main: measured 16822/8130. Release slice 1 (hosted checks) adds the hub's hosted CI verdict for checks: the deferred one-read poll with its persisted deadline, the one-snapshot verdict, the failing units and the restart case (judge_hosted.go, about 200 lines) and the forge's CI reads (forge.go, about 40); measured 16821. Its tests (judge_hosted_test.go, about 270 lines) take the package's tests to 8113, beside the step engine they drive. The leftover helper's debug line adds 3 lines: measured 16572. The Mac host's hang fix and probe pacing add the process group and its kill (procgroup_unix.go, procgroup_other.go), the bounded wait for a command's output, and the untrusted report's rerun decision with its tool fingerprint (about 165 lines); measured 16569. Runner startup logs add the info lines a silent start is pinned to a phase by (startup phases, the Mac host's xcode-select and capability commands, slow-command warnings, the probes, and the link's connecting, hello and welcome lines: startPhase, openRunner, watchSlow and logged, about 155 lines); measured 16405. Merge authority thin v1 adds the review's measured change facts (facts.go: raw and numstat listings, modes, signing lines, the revert tree check, about 230 lines), the merge_request confirmation and the merge's provenance; measured 16196 with spend-1 merged. Spend 1 resumes a fix round in Engineering's kept session on its healthy connection (fixSession, fixPlan, fixPrompt, keptCommit, about 90 lines); measured 15873. Claude's sign-in by a link's review round 1 contains its setup-token in a recorded namespace (the contained terminal, its proven stop and the start's recovery before a home goes, about 130 lines); measured 15787. Claude's sign-in by a link adds the runner's own setup-token attempt, the code's sealed delivery with its crash boundaries and the shared token commit (signin.go, about 300 lines, less the removed terminal watcher); measured 15655. Claude setup tokens add sealed delivery, the token check, Check again and recovery (token.go, tokencheck.go, about 700 lines) beside the composer and Mac lines; measured 15239. Astra round 2 moves the attachment quota to admission: arriving files counted by declared size, admissions protecting a file until its message names it, room made from the oldest unprotected files, refusal as runner_storage_full, and a sweep that stops when protection cannot be read (about 150 lines); measured 12191. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path. The paste box house rule merged onto the runner logs: measured 16573. The leftover helper's debug line adds 3 lines: measured 16572. The Mac host's hang fix and probe pacing add the process group and its kill (procgroup_unix.go, procgroup_other.go), the bounded wait for a command's output, and the untrusted report's rerun decision with its tool fingerprint (about 165 lines); measured 16569. Runner startup logs add the info lines a silent start is pinned to a phase by (startup phases, the Mac host's xcode-select and capability commands, slow-command warnings, the probes, and the link's connecting, hello and welcome lines: startPhase, openRunner, watchSlow and logged, about 155 lines); measured 16405. Merge authority thin v1 adds the review's measured change facts (facts.go: raw and numstat listings, modes, signing lines, the revert tree check, about 230 lines), the merge_request confirmation and the merge's provenance; measured 16196 with spend-1 merged. Spend 1 resumes a fix round in Engineering's kept session on its healthy connection (fixSession, fixPlan, fixPrompt, keptCommit, about 90 lines); measured 15873. Claude's sign-in by a link's review round 1 contains its setup-token in a recorded namespace (the contained terminal, its proven stop and the start's recovery before a home goes, about 130 lines); measured 15787. Claude's sign-in by a link adds the runner's own setup-token attempt, the code's sealed delivery with its crash boundaries and the shared token commit (signin.go, about 300 lines, less the removed terminal watcher); measured 15655. Claude setup tokens add sealed delivery, the token check, Check again and recovery (token.go, tokencheck.go, about 700 lines) beside the composer and Mac lines; measured 15239. Astra round 2 moves the attachment quota to admission: arriving files counted by declared size, admissions protecting a file until its message names it, room made from the oldest unprotected files, refusal as runner_storage_full, and a sweep that stops when protection cannot be read (about 150 lines); measured 12191. Mac runners slices A and B add protocol negotiation (link.go), the capability report, the start authorization, the pack relay (relay.go), the primary's publication, the worker executor (worker.go) and the test-build fake worker, about 2700 lines on the same step engine. Composer attachments add the chunked receipt with exactly-once writes, the read-only desk delivery and its checks (files.go, about 230 lines), image blocks and localImage inputs, the attachment read through read_file; measured 11736. Connections slice 1 Astra round 1 adds the Codex step path (codexstep.go: Engineering and Review on the pinned app-server in the implement and inspect containment, about 300 lines); measured 11345. Connections slice 1 (after Astra round 1) also keeps a durable ledger of each turn's write tools so a later attempt never repeats one (effects.go), the waiting state between attempts and usage rows per attempt, about 500 lines more; measured 10590 before gate 1d. Connections slice 1 adds the Codex coordinator beside the Claude one (codex.go: the pinned app-server over JSON-RPC in the converse containment, sharing the coordinator base, desk, tool socket and session table), the connection registry over the bindings with health and provider limits (conns.go), in-app sign-in attempts (connector.go) and turn failover and holding (failover.go), about 1500 lines; the pure parts (the choice function, limit parsing, the app-server client, the sign-in flows) live in internal/runner/connect. Measured 10097. Thin v1 UX1 adds step activity lines from the specialist's stream, the repository head and checks gate in the index and project-tagged notes (about 120 lines); measured 8615 with slice 4c's review fixes. Thin v1 slice 4c adds the merge step (mergestep.go, about 190 lines) and the rebase round beside the slice 4b ask fixes. Thin v1 slice 3 adds Engineering steps beside the coordinator: the durable step state and engine (step.go) and the executor that checks out the task tree, runs the CLI in the implement containment, commits and pushes (engineer.go), about 800 lines sharing the coordinator's launch, tool socket and account selection. Measured 5686 source lines. Splitting would export the launch internals; revisit at the slice 7 sweep. Slice 4 adds checks and review on a candidate (judge.go) and the merge watch (merge.go), about 800 lines, sharing the Engineer launch path; measured 6808, 7035 after review round 1 (branch head watch, deadlines, streamed outputs). Slice 4b keeps Engineering and Review sessions and answers the creator's questions from them (ask.go: kept-session and ask state, read-only git tools, the answer stream), about 700 lines on the same launch path.
time internal/thintest 180s Mac runners slices A and B add role, scoping, migration, placement, withdrawal, transfer and publication contracts, and Astra round 1 eight transition contracts (about 15s; the package measured 126s locally under load). Housekeeping slice 1 adds six contract tests (combine, Undo round trips and the race, Pause, auto-disable, quiet hours, restart while claimed; about 6s); the package measured 67.7s beside other packages locally, so 75s. Thin v1 slice 4c adds the merge, adoption, cancel and retention contract tests (CI measured 35.7s). Thin v1 contract tests: a real instance and a scripted runner per test, fixtures replayed against every request, frame and event. Slice 3 adds the task, step-sync and grant contracts; CI measured 14.805s. 30s keeps room for the slice 4 review contracts. UX1 adds step activity, task source and duplicates, coordinator merging and project facts (four contracts, about 6s); the package measured 34s locally under load, so 40s. UX1's inner screens gallery (two owners, seven tasks, every page) adds about 3s; measured 40.9s locally under load, so 60s.
time internal/runner/mac 30s Mac runners (Darwin worker): real process groups killed after a grace and proven gone (SIGTERM, SIGKILL, the marker sweep), and the probes run end to end with fake srt and xcodebuild, P6 killing a waiting test two seconds after it starts. About 6s alone; loaded CI measured 12.5s.
time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s). Measured 17.8s locally under load. Slice 4b review adds a 16 MiB git output bound, an injected index-pack failure and stall (3s deadline) and held-answer tests; measured 30.3s locally under load. 45s keeps 33 percent headroom.
diff --git a/internal/runner/mac/gate.go b/internal/runner/mac/gate.go
index d760409e..9107130a 100644
--- a/internal/runner/mac/gate.go
+++ b/internal/runner/mac/gate.go
@@ -94,6 +94,9 @@ func (g *Gate) Run(ctx context.Context, attempt, dir string, argv []string, limi
}
if g.Turns != nil {
if err := g.Turns.take(ctx); err != nil {
+ if ctx.Err() == nil {
+ return unavailable()
+ }
res.Reason, res.Terminated = "cancelled", true
return res
}
@@ -126,13 +129,18 @@ func (g *Gate) Run(ctx context.Context, attempt, dir string, argv []string, limi
// user's own folder) or cleaned runs nothing.
var temp *tempState
if g.UserTemp != "" {
- if err := g.Turns.finishPending(g.UserTemp); err != nil {
+ if err := g.finishPending(ctx); err != nil {
return unavailable()
}
if temp, err = openTemp(g.UserTemp, nil); err != nil {
return unavailable()
}
defer temp.close()
+ // On record before anything starts: a runner killed from here
+ // on leaves the cleanup to the next gate, not to nobody.
+ if err := g.Turns.writePending(pendingRecord{Attempt: attempt, Before: temp.before}); err != nil {
+ return unavailable()
+ }
}
// Only once the run's end is proven: a process of it still alive
// could be writing T as it is cleaned. Unproven, or not finished,
@@ -143,7 +151,8 @@ func (g *Gate) Run(ctx context.Context, attempt, dir string, argv []string, limi
return
}
if !res.Terminated {
- g.Turns.leavePending(temp.before)
+ // The record stays: the next gate proves this attempt's
+ // end before it cleans.
return
}
// Simulator processes are CoreSimulator's, outside the group
@@ -152,8 +161,8 @@ func (g *Gate) Run(ctx context.Context, attempt, dir string, argv []string, limi
if g.QuietSimulators != nil {
g.QuietSimulators(context.WithoutCancel(ctx))
}
- if temp.clean() != nil {
- g.Turns.leavePending(temp.before)
+ if temp.clean() == nil {
+ _ = g.Turns.dropPending()
}
}
if err := record(RecordID(0, attempt)); err != nil {
@@ -195,6 +204,11 @@ func (g *Gate) Run(ctx context.Context, attempt, dir string, argv []string, limi
return unavailable()
}
pgid := cmd.Process.Pid
+ if temp != nil {
+ // With its group, so the next gate can prove that end too. Best
+ // effort: the record before the start has the marker.
+ _ = g.Turns.writePending(pendingRecord{Attempt: attempt, PGID: pgid, Before: temp.before})
+ }
exited := make(chan error, 1)
go func() { exited <- cmd.Wait() }()
if err := record(RecordID(pgid, attempt)); err != nil {
@@ -259,6 +273,33 @@ func (g *Gate) Run(ctx context.Context, attempt, dir string, argv []string, limi
return res
}
+// finishPending finishes the T cleanup an earlier attempt (in this
+// process or another, perhaps killed) left: that attempt's end proven
+// first (its group and every process with its marker gone, killed if
+// need be, as Verify does), its simulators shut down, then T cleaned
+// against what it held before that attempt. Holding the turn.
+func (g *Gate) finishPending(ctx context.Context) error {
+ r, ok, err := g.Turns.readPending()
+ if err != nil || !ok {
+ return err
+ }
+ if !g.settle(r.PGID, r.Attempt, false) {
+ return errors.New("mac: an earlier attempt's end is not proven")
+ }
+ if g.QuietSimulators != nil {
+ g.QuietSimulators(context.WithoutCancel(ctx))
+ }
+ s, err := openTemp(g.UserTemp, r.Before)
+ if err != nil {
+ return err
+ }
+ defer s.close()
+ if err := s.clean(); err != nil {
+ return err
+ }
+ return g.Turns.dropPending()
+}
+
// RecordID is the process record of an attempt: its group and marker.
func RecordID(pgid int, attempt string) string { return "pg:" + strconv.Itoa(pgid) + ":" + attempt }
diff --git a/internal/runner/mac/usertemp.go b/internal/runner/mac/usertemp.go
index 0ecd0ccb..f2bd0091 100644
--- a/internal/runner/mac/usertemp.go
+++ b/internal/runner/mac/usertemp.go
@@ -361,45 +361,81 @@ func (t *Turns) pending() string {
return t.lock + ".pending"
}
-// finishPending finishes a cleanup an earlier attempt (in this process
-// or another) left, against what T held before it. Called holding the
-// turn.
-func (t *Turns) finishPending(dir string) error {
+// pendingRecord is a sandboxed attempt whose T cleanup is not done yet:
+// written before anything of the attempt starts (and again with its
+// group once there is one), removed only once its end is proven and T
+// is cleaned. A runner killed meanwhile leaves it for the next gate,
+// in any runner process.
+type pendingRecord struct {
+ Attempt string `json:"attempt"`
+ PGID int `json:"pgid"`
+ Before tempListing `json:"before"`
+}
+
+// writePending records r durably (written beside, then renamed over).
+// Without a lock file (tests) there is nowhere to keep it.
+func (t *Turns) writePending(r pendingRecord) error {
p := t.pending()
if p == "" {
return nil
}
- raw, err := os.ReadFile(p)
- if errors.Is(err, fs.ErrNotExist) {
- return nil
- }
- var before tempListing
- if err != nil || json.Unmarshal(raw, &before) != nil || before == nil {
- return errors.Join(ErrUserTemp, err)
+ raw, err := json.Marshal(r)
+ if err != nil {
+ return err
}
- s, err := openTemp(dir, before)
+ f, err := os.OpenFile(p+".new", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
if err != nil {
return err
}
- defer s.close()
- if err := s.clean(); err != nil {
+ _, err = f.Write(raw)
+ if serr := f.Sync(); err == nil {
+ err = serr
+ }
+ if cerr := f.Close(); err == nil {
+ err = cerr
+ }
+ if err != nil {
return err
}
- return os.Remove(p)
+ return os.Rename(p+".new", p)
}
-// leavePending records a cleanup that did not finish, so the next gate
-// finishes it before anything runs.
-func (t *Turns) leavePending(before tempListing) {
+// readPending is the record an earlier attempt left; ok is false when
+// there is none. One that cannot be read is an error: nothing runs
+// until a person looks.
+func (t *Turns) readPending() (r pendingRecord, ok bool, err error) {
p := t.pending()
if p == "" {
- return
+ return r, false, nil
}
- raw, err := json.Marshal(before)
- if err == nil {
- err = os.WriteFile(p+".new", raw, 0600)
+ raw, err := os.ReadFile(p)
+ if errors.Is(err, fs.ErrNotExist) {
+ return r, false, nil
}
- if err == nil {
- _ = os.Rename(p+".new", p)
+ if err != nil {
+ return r, false, err
+ }
+ if err := json.Unmarshal(raw, &r); err != nil || r.Attempt == "" || r.Before == nil {
+ return r, false, errors.Join(ErrUserTemp, errors.New("mac: unreadable pending cleanup"), err)
+ }
+ return r, true, nil
+}
+
+// dropPending removes the record once its cleanup is done.
+func (t *Turns) dropPending() error {
+ p := t.pending()
+ if p == "" {
+ return nil
+ }
+ if err := os.Remove(p); err != nil && !errors.Is(err, fs.ErrNotExist) {
+ return err
}
+ return nil
+}
+
+// Pending reports whether an attempt's cleanup is still to be done
+// (the warm waits for it: that attempt's end is not proven yet).
+func (t *Turns) Pending() bool {
+ _, err := os.Lstat(t.pending())
+ return t.pending() != "" && err == nil
}
diff --git a/internal/runner/mac/usertemp_test.go b/internal/runner/mac/usertemp_test.go
index 33401d68..40117677 100644
--- a/internal/runner/mac/usertemp_test.go
+++ b/internal/runner/mac/usertemp_test.go
@@ -305,3 +305,62 @@ func TestGateQuietsSimulatorsBeforeCleaning(t *testing.T) {
t.Fatalf("quieted %v before cleaning, result %+v", saw, res)
}
}
+
+// The cleanup is on record before anything of an attempt starts: a
+// runner killed mid-run leaves it to the next gate (any process), which
+// first proves that attempt over, then cleans T, then runs. Not proven,
+// unreadable or unrecordable: nothing runs.
+func TestGatePendingCleanupSurvivesTheRunner(t *testing.T) {
+ g, dir := gateFixture(t, true)
+ _, temp := userTempFixture(t)
+ tempTree(t, temp)
+ lock := filepath.Join(t.TempDir(), "lock")
+ g.UserTemp, g.Turns, g.Settle = temp, NewTurns(lock), 500*time.Millisecond
+ // The killed runner's attempt: its record, then what it left.
+ s, err := openTemp(temp, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := g.Turns.writePending(pendingRecord{Attempt: "checks-dead", Before: s.before}); err != nil {
+ t.Fatal(err)
+ }
+ s.close()
+ if err := os.WriteFile(filepath.Join(temp, "leftover"), nil, 0600); err != nil {
+ t.Fatal(err)
+ }
+ // Still running (a process with its marker): nothing runs, nothing goes.
+ g.find = func(a string) ([]Proc, error) {
+ if a == "checks-dead" {
+ return []Proc{{PID: 1 << 30, PGID: 1 << 30}}, nil
+ }
+ return nil, nil
+ }
+ ran := filepath.Join(t.TempDir(), "ran")
+ if res, _ := run(g, dir, "checks-p-1", time.Minute, `touch `+quote(ran)); res.Reason != "checks_unavailable" || exists(ran) || !exists(filepath.Join(temp, "leftover")) {
+ t.Fatalf("ran beside an unproven attempt: %+v", res)
+ }
+ // Over: its leftovers go before the next gate runs, and the record.
+ g.find = func(string) ([]Proc, error) { return nil, nil }
+ quieted := 0
+ g.QuietSimulators = func(context.Context) { quieted++ }
+ res, _ := run(g, dir, "checks-p-2", time.Minute, `ls `+quote(temp))
+ if res.Code != 0 || strings.Contains(res.Output, "leftover") || exists(filepath.Join(temp, "leftover")) || exists(g.Turns.pending()) || quieted != 2 {
+ t.Fatalf("pending cleanup not finished first (quieted %d): %+v", quieted, res)
+ }
+ // A record that cannot be read, or written: nothing runs.
+ if err := os.WriteFile(g.Turns.pending(), []byte("{"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ if res, _ := run(g, dir, "checks-p-3", time.Minute, `touch `+quote(ran)); res.Reason != "checks_unavailable" || exists(ran) || !g.Turns.Pending() {
+ t.Fatalf("ran past an unreadable record: %+v", res)
+ }
+ if err := os.Remove(g.Turns.pending()); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Mkdir(g.Turns.pending()+".new", 0700); err != nil {
+ t.Fatal(err)
+ }
+ if res, _ := run(g, dir, "checks-p-4", time.Minute, `touch `+quote(ran)); res.Reason != "checks_unavailable" || exists(ran) {
+ t.Fatalf("ran without its cleanup on record: %+v", res)
+ }
+}
diff --git a/internal/runner/thin/mac.go b/internal/runner/thin/mac.go
index 0c62b525..e7fcb547 100644
--- a/internal/runner/thin/mac.go
+++ b/internal/runner/thin/mac.go
@@ -456,6 +456,11 @@ func (h *macHost) warm(ctx context.Context, x wire.Xcode) {
}
if h.turns != nil {
defer h.turns.Give()
+ // Nor while an earlier attempt's end is unproven (its cleanup
+ // pending): the next gate settles that first.
+ if h.turns.Pending() {
+ return
+ }
}
c, cancel := context.WithTimeout(ctx, mac.QueryLimit)
defer cancel()
diff --git a/internal/runner/thin/mac_test.go b/internal/runner/thin/mac_test.go
index 8b2f2831..73f1a251 100644
--- a/internal/runner/thin/mac_test.go
+++ b/internal/runner/thin/mac_test.go
@@ -347,6 +347,10 @@ func TestMacWarmsThePluginCacheOncePerXcode(t *testing.T) {
}
h.warm(context.Background(), b52)
other.Give()
+ // Nor while an earlier attempt's cleanup is pending.
+ _ = os.WriteFile(filepath.Join(dir, "lock.pending"), nil, 0600)
+ h.warm(context.Background(), b52)
+ _ = os.Remove(filepath.Join(dir, "lock.pending"))
_ = os.WriteFile(fail, nil, 0600)
h.warm(context.Background(), b52)
_ = os.Remove(fail)