oficina / equipo Public

Mac slice F wb fix 2 #1, #2: cleanup's own bound, evidence kept

Whole-branch review round 2, findings 1 and 2. The 30 s deadline
covers process termination (stop, sweep, proof). The user-temp
cleanup has its own bound, CleanLimit (3 minutes) from the cleanup's
start, read after its last act: Finish and finishPending check the
time after the pending record's removal too, and Verify gives the
cleanup that bound and checks the final save against it. Terminated
needs both. A failed or late cleanup marks the turn's end unproven,
so its record and boot-qualified evidence stay: after a reboot Verify
clears the attempt from the debt (Assess) before any old process id
is checked, and keeps the per-consumer completion. Spec 8.8 states
the two bounds. TestPendingCleanupUnderTheDeadline now sets its
CleanLimit explicitly.

Regressions: TestCleanupLateRecordRemovalIsUnproven,
TestVerifyLateRecordRemovalIsUnproven,
TestFailedCleanupClearsAfterAReboot (old group number reused by a
live process: cleared, not signalled, completion kept).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 6b8ba04b033ab9a4351ec2e89c4b28cf58cd0cd3 parent d08dd4b
5 files changed, +178 −32
  • docs/superpowers/specs/2026-11-07-equipo-mac-runners.md +16 −0
  • internal/runner/mac/fix9f2_test.go +2 −1
  • internal/runner/mac/launch.go +28 −31
  • internal/runner/mac/turns.go +4 −0
  • internal/runner/mac/wbfix2_test.go +128 −0
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 60642514..78d2cdc6 100644
--- a/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md
+++ b/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md
@@ -1017,6 +1017,22 @@ gives its parts no separate budgets:
- everything above is durably on the turn's record, and the stop's
final note marked it complete.
+**The user-temp cleanup has its own bound (2026-11-29).** The 30 s
+deadline covers process termination only: the stop, the sweep and the
+proof. An attempt that may write the runner user's T then has its
+cleanup (simulators shut down, what it made in T removed, the pending
+cleanup record removed) bounded by `CleanLimit` (3 minutes) from the
+cleanup's start, because a simulator shutdown can take minutes. The
+time is read after the last of these returns, the record removal
+included, and in `Verify` after the final save of what the attempt
+owed. An attempt is terminated (`Terminated: true`, a launch's end
+proven) only with its proof inside the 30 s and its cleanup inside its
+bound. On any error or overrun the pending cleanup record (if it is
+still there) and the turn's record stay, so its boot-qualified evidence
+survives: after a reboot `Verify` clears the attempt from that evidence
+before it looks at any old process id, and keeps the completion for
+each consumer. A later `Verify` finishes the cleanup.
+
If the turn's record cannot be written, the operation is stopped at once
and its proof withheld, and no further launch starts in that turn. A
record is complete (a durable `complete` mark) only once every launch of
diff --git a/internal/runner/mac/fix9f2_test.go b/internal/runner/mac/fix9f2_test.go
index 1c9f3770..58b6d0a1 100644
--- a/internal/runner/mac/fix9f2_test.go
+++ b/internal/runner/mac/fix9f2_test.go
@@ -88,7 +88,8 @@ func TestPendingCleanupUnderTheDeadline(t *testing.T) {
t.Fatal(err)
}
_, temp := userTempFixture(t)
- x.UserTemp = temp
+ // The cleanup has its own bound (whole-branch fix 2, #1).
+ x.UserTemp, x.CleanLimit = temp, x.settleLimit()
s, err := openTemp(temp, nil)
if err != nil {
t.Fatal(err)
diff --git a/internal/runner/mac/launch.go b/internal/runner/mac/launch.go
index 0b0841e6..ea360a42 100644
--- a/internal/runner/mac/launch.go
+++ b/internal/runner/mac/launch.go
@@ -1,6 +1,7 @@
package mac
import (
+ "cmp"
"context"
"errors"
"io"
@@ -91,14 +92,8 @@ func (x *Executor) own() *Own {
return x.Turns.owned()
}
-// cleanLimit is how much past the stop's deadline the user-temp
-// cleanup may run (a simulator shutdown).
-func (x *Executor) cleanLimit() time.Duration {
- if x.CleanLimit > 0 {
- return x.CleanLimit
- }
- return 3 * time.Minute
-}
+// cleanLimit bounds the user-temp cleanup (a simulator shutdown).
+func (x *Executor) cleanLimit() time.Duration { return cmp.Or(x.CleanLimit, 3*time.Minute) }
func (x *Executor) settleLimit() time.Duration {
if x.Settle > 0 {
@@ -286,8 +281,7 @@ type Run struct {
temp *tempState
finishOnce sync.Once
- // stopBy is the stop's deadline; cleaned: Finish's cleanup is done.
- stopBy time.Time
+ // cleaned: Finish's cleanup is done.
cleaned bool
stdin io.WriteCloser
@@ -407,7 +401,6 @@ func (r *Run) stopWith(grace time.Duration) bool {
}
}
deadline := time.Now().Add(r.x.settleLimit())
- r.stopBy = deadline
out := r.scope.Settle(r.own, deadline, grace, reaped, r.adopt)
if r.turn == nil {
return out == proc.Proven && time.Now().Before(deadline)
@@ -430,13 +423,10 @@ func (r *Run) stopWith(grace time.Duration) bool {
return true
}
-// Finish is the user-temp cleanup once the end is proven (the
-// attempt's own, in its turn): simulators quieted, then what appeared in
-// T removed, then the record, all by the stop's deadline plus
-// CleanLimit. It reports whether the cleanup is done (nothing to clean
-// is done); the end is proven only then. Unproven, failed or late, the
-// record stays, the attempt's own, for its proof later (Verify) or a
-// restart.
+// Finish is the user-temp cleanup once the end is proven: simulators
+// quieted, what appeared in T removed, then the record, within
+// CleanLimit read after the last; done (or nothing to clean) or not.
+// Failed or late, the pending and turn records stay for Verify.
func (r *Run) Finish(ctx context.Context) bool {
r.finishOnce.Do(func() {
if r.temp == nil {
@@ -447,16 +437,16 @@ func (r *Run) Finish(ctx context.Context) bool {
if !r.proven {
return
}
- by := r.stopBy.Add(r.x.cleanLimit())
+ by := time.Now().Add(r.x.cleanLimit())
qctx, cancel := context.WithDeadline(context.WithoutCancel(ctx), by)
defer cancel()
if r.x.QuietSimulators != nil {
r.x.QuietSimulators(qctx)
}
- if r.temp.clean() != nil || !time.Now().Before(by) {
- return
+ r.cleaned = r.temp.clean() == nil && time.Now().Before(by) && r.x.Turns.dropPending() == nil && time.Now().Before(by)
+ if !r.cleaned && r.turn != nil {
+ r.turn.unprovenEnd()
}
- r.cleaned = r.x.Turns.dropPending() == nil
})
return r.cleaned
}
@@ -499,10 +489,10 @@ func (x *Executor) finishPending(ctx context.Context, turn *Turn, settleBy, clea
if err := s.clean(); err != nil {
return err
}
- if !time.Now().Before(cleanBy) {
- return errors.Join(ErrPendingCleanup, errors.New("mac: the cleanup outlasted its deadline"))
+ if !time.Now().Before(cleanBy) || x.Turns.dropPending() != nil || !time.Now().Before(cleanBy) {
+ return errors.Join(ErrPendingCleanup, errors.New("mac: the cleanup failed or outlasted its bound"))
}
- return x.Turns.dropPending()
+ return nil
}
// RecordID is the process record of an attempt: its group and marker.
@@ -569,19 +559,26 @@ func (x *Executor) Verify(id string) bool {
if err != nil {
return false
}
- if pending && r.Attempt == attempt && x.finishPending(context.Background(), held, deadline, deadline) != nil {
- return false
+ if pending && r.Attempt == attempt {
+ // The cleanup's own bound, the final save's too.
+ cleanBy := time.Now().Add(x.cleanLimit())
+ if x.finishPending(context.Background(), held, deadline, cleanBy) != nil {
+ return false
+ }
+ deadline = cleanBy
}
}
if x.Turns == nil {
return true
}
- if rebooted {
+ var err error
+ if b, berr := x.Turns.bootNow(); rebooted {
// Kept for every consumer (and any later proof) of the record.
- b, err := x.Turns.bootNow()
- return err == nil && x.Turns.debts.Complete(attempt, b.ID, deadline) == nil
+ err = errors.Join(berr, x.Turns.debts.Complete(attempt, b.ID, deadline))
+ } else {
+ err = x.Turns.debts.Discharge(attempt, deadline)
}
- return x.Turns.debts.Discharge(attempt, deadline) == nil
+ return err == nil && time.Now().Before(deadline)
}
// Acknowledge: consumer (ConsumerStep, ConsumerKeychain) has durably
diff --git a/internal/runner/mac/turns.go b/internal/runner/mac/turns.go
index 3846a47c..3e68fd2b 100644
--- a/internal/runner/mac/turns.go
+++ b/internal/runner/mac/turns.go
@@ -73,6 +73,7 @@ type Turns struct {
// beforeWrite runs before each turn record write (tests: a slow or
// failing disk).
beforeWrite func() error
+ beforeDrop func() // before the pending record's removal (tests)
// boot reads this boot (creds.BootID, creds.BootTime; tests stand in).
boot func() (proc.Boot, error)
// Settle bounds settling an earlier turn (30 s).
@@ -591,6 +592,9 @@ func (t *Turns) dropPending() error {
if t.pending() == "" {
return nil
}
+ if t.beforeDrop != nil {
+ t.beforeDrop()
+ }
return t.pends.Drop()
}
diff --git a/internal/runner/mac/wbfix2_test.go b/internal/runner/mac/wbfix2_test.go
new file mode 100644
index 00000000..c7c925d0
--- /dev/null
+++ b/internal/runner/mac/wbfix2_test.go
@@ -0,0 +1,128 @@
+package mac
+
+import (
+ "context"
+ "errors"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "syscall"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runner/mac/proc"
+)
+
+// Whole-branch fix 2, #1: the cleanup has its own bound (CleanLimit),
+// checked after its last act, the pending record's removal included. A
+// removal that returns late leaves the run unterminated, and its turn's
+// record stays as the evidence a later Verify proves from.
+func TestCleanupLateRecordRemovalIsUnproven(t *testing.T) {
+ _, temp := userTempFixture(t)
+ turns := NewTurns(filepath.Join(t.TempDir(), "lock"))
+ x := &Executor{Turns: turns, UserTemp: temp, Grace: 300 * time.Millisecond, Settle: time.Second, CleanLimit: 300 * time.Millisecond}
+ slow := true
+ turns.beforeDrop = func() {
+ if slow {
+ time.Sleep(500 * time.Millisecond)
+ }
+ }
+ u, err := turns.Take(context.Background(), OpEngineering)
+ if err != nil {
+ t.Fatal(err)
+ }
+ r, err := x.Start(u.Context(context.Background()), Command{Argv: []string{"/bin/sh", "-c", "touch " + quote(filepath.Join(temp, "late"))}, Env: []string{"PATH=/usr/bin:/bin"}, Dir: t.TempDir()}, "eng-wb2-1", func(string) error { return nil })
+ if err != nil {
+ t.Fatal(err)
+ }
+ p := &process{run: r, stop: func() bool { return true }}
+ if _, err := p.Wait(context.Background()); !errors.Is(err, ErrUnproven) {
+ t.Fatalf("a launch whose record removal came late: %v", err)
+ }
+ u.Give()
+ if _, ok, _ := turns.loadTurn(); !ok {
+ t.Fatal("the turn's record went with an unproven cleanup")
+ }
+ slow = false
+ if !x.Verify(r.ID()) || turns.Pending() {
+ t.Fatal("the attempt's proof did not finish")
+ }
+}
+
+// Whole-branch fix 2, #1: Verify's cleanup has the same bound, checked
+// after the pending record's removal too.
+func TestVerifyLateRecordRemovalIsUnproven(t *testing.T) {
+ g, dir := gateFixture(t, true)
+ _, temp := userTempFixture(t)
+ g.UserTemp, g.Turns = temp, NewTurns(filepath.Join(t.TempDir(), "lock"))
+ g.QuietSimulators = func(context.Context) { _ = os.Chmod(temp, 0) }
+ t.Cleanup(func() { _ = os.Chmod(temp, 0o700) })
+ res, id := run(g, dir, "checks-wb2-1", time.Minute, `touch `+quote(filepath.Join(temp, "left")))
+ if res.Terminated {
+ t.Fatalf("%+v", res)
+ }
+ g.QuietSimulators = nil
+ if err := os.Chmod(temp, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ x := g.executor()
+ x.CleanLimit = 300 * time.Millisecond
+ slow := true
+ g.Turns.beforeDrop = func() {
+ if slow {
+ time.Sleep(500 * time.Millisecond)
+ }
+ }
+ if x.Verify(id) {
+ t.Fatal("proven with its record removed past the cleanup's bound")
+ }
+ slow = false
+ if !x.Verify(id) {
+ t.Fatal("a later proof did not finish")
+ }
+}
+
+// Whole-branch fix 2, #2: a cleanup that failed keeps its turn's record
+// and its boot. After a reboot the attempt clears boot-qualified before
+// any old process id is looked at: its group number, now another
+// long-lived process's, is never checked or signalled, and the
+// completion is kept for every consumer.
+func TestFailedCleanupClearsAfterAReboot(t *testing.T) {
+ g, dir := gateFixture(t, true)
+ _, temp := userTempFixture(t)
+ g.UserTemp, g.Turns = temp, NewTurns(filepath.Join(t.TempDir(), "lock"))
+ boot := proc.Boot{ID: "boot-1", Time: time.Now().Add(-time.Hour)}
+ g.Turns.boot = func() (proc.Boot, error) { return boot, nil }
+ g.QuietSimulators = func(context.Context) { _ = os.Chmod(temp, 0) }
+ t.Cleanup(func() { _ = os.Chmod(temp, 0o700) })
+ res, id := run(g, dir, "checks-wb2-2", time.Minute, `touch `+quote(filepath.Join(temp, "left")))
+ if res.Terminated || !g.Turns.Pending() {
+ t.Fatalf("%+v pending=%v", res, g.Turns.Pending())
+ }
+ if _, ok, _ := g.Turns.loadTurn(); !ok {
+ t.Fatal("the turn's record went with the failed cleanup")
+ }
+ // The reboot; the old group number now leads a long-lived process.
+ g.QuietSimulators = nil
+ if err := os.Chmod(temp, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ boot = proc.Boot{ID: "boot-2", Time: time.Now()}
+ other := exec.Command("/bin/sleep", "60")
+ other.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
+ if err := other.Start(); err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _ = other.Process.Kill(); _ = other.Wait() })
+ _, attempt, _ := proc.ParseRecord(id)
+ reused := RecordID(other.Process.Pid, attempt)
+ if !g.Verify(reused) || g.Turns.Pending() || exists(filepath.Join(temp, "left")) {
+ t.Fatal("a reboot did not clear the attempt whose cleanup failed")
+ }
+ if err := other.Process.Signal(syscall.Signal(0)); err != nil {
+ t.Fatalf("the process now holding the old group number was signalled: %v", err)
+ }
+ if !g.Verify(reused) {
+ t.Fatal("the reboot's completion was not kept for the next consumer")
+ }
+}