Mac slice F task 9 fix 3: cleanup deadline, per-launch records, checks
After the final review (Astra round 3: #7, #8, #10 partly resolved), tests first: - #7 Verify passes its one deadline into the pending cleanup's proof read; settleRecord refuses a proof once it has passed - #8 completion is tracked per launch; after any lost evidence write no further launch starts in the turn and the record is never complete - #10 check reads withhold the proof and the Mac's clearance while any runner-uid process born during the turn lives (not the runner's own, not a launchd relaunch), without adding it to the kill set; spec 8.8 keeps only the relaunch identification as its limit Mutations, all caught: R7c, R8e-R8g, R10b-R10e, F10b, M9. R7d survived (redundant with settleRecord's own check) and its line was removed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+314
−54
docs/superpowers/specs/2026-11-07-equipo-mac-runners.md+15 −13internal/runner/mac/fix2_test.go+228 −12internal/runner/mac/launch.go+7 −21internal/runner/mac/proc/proc.go+9 −4internal/runner/mac/proc/ps.go+24 −0internal/runner/mac/turns.go+31 −4
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 20bfa229..cedf82d7 100644 |
| --- a/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md |
| +++ b/docs/superpowers/specs/2026-11-07-equipo-mac-runners.md |
| @@ -991,9 +991,13 @@ process is never signalled. |
| agent again. It is not killed and does not block the proof. One that |
| started before the cutoff is killed, even if the first read missed |
| it. |
| -3. Later reads only check whether the kill set and the obligations are |
| - gone. They signal the kill set again (SIGKILL once the grace is over) |
| - and never add or spare anything. |
| +3. Later reads only check. They signal the kill set again (SIGKILL once |
| + the grace is over) and add nothing to it. Each one withholds both the |
| + proof and the Mac's clearance (`Owed`) while any process of the |
| + runner user born during the turn is alive, other than the runner's |
| + own and a relaunch as defined in phase 2. Such a process is not |
| + signalled; the turn's record stays, and the next turn's settling, |
| + with its own kill pass, ends it. |
| Every group and session a kill-set process leads becomes an obligation. |
| So a process born into one after discovery (a fork from a dying target) |
| @@ -1014,9 +1018,10 @@ gives its parts no separate budgets: |
| final note marked it complete. |
| If the turn's record cannot be written, the operation is stopped at once |
| -and its proof withheld. A record is complete only once the stop's final |
| -note, written after every group and session write, has succeeded (a |
| -durable `complete` mark). After a restart, a record without that mark is |
| +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 |
| +the turn has written its own final note, each after all its group and |
| +session writes, and no evidence write of the turn ever failed. After a restart, a record without that mark is |
| incomplete: what it left is swept as usual, but recovery never proves its |
| attempts over. Each such attempt stays unterminated with no Retry, and |
| the Mac's card on the Machines page says so (the capability code |
| @@ -1059,13 +1064,10 @@ its limit reports at once but keeps the turn until its gates have |
| stopped and cleaned up. The credential flag (task 11) is separate: it |
| holds no turn. |
| -**The honest limit.** Two cases are left: |
| - |
| -- a process with a system path, reparented to launchd, that starts |
| - after the relaunch cutoff, during the kill pass itself. It cannot be |
| - told from a relaunch, so it is spared; |
| -- a process born after the discovery read that carries no marker and is |
| - outside every group and session the attempt made or led. |
| +**The honest limit.** One case is left: the relaunch identification |
| +itself. A process with a system path, reparented to launchd, that starts |
| +after the relaunch cutoff (during the kill pass) cannot be told from a |
| +relaunch, so it is spared and does not block the proof. |
| Also not covered: |
diff --git a/internal/runner/mac/fix2_test.go b/internal/runner/mac/fix2_test.go| index 8be8c29c..d716ff71 100644 |
| --- a/internal/runner/mac/fix2_test.go |
| +++ b/internal/runner/mac/fix2_test.go |
| @@ -170,23 +170,23 @@ func TestRelaunchCutoffIsTheKillPassStart(t *testing.T) { |
| } |
| // #10: discovery is the one read after the first kill pass. Later reads |
| -// add nothing: a process born after it (here as the leader dies of the |
| -// SIGKILL after discovery) is not signalled; one born into the group |
| -// that killed process led keeps the proof waiting, as an obligation. |
| +// add nothing to the kill set, but any process of the runner user born |
| +// during the turn (here as the leader dies of the SIGKILL after |
| +// discovery), not the runner's own and not a launchd relaunch, keeps |
| +// both the proof and the Mac's clearance withheld: the turn's record |
| +// stays, and the next turn's settling kills it. |
| func TestDiscoveryIsOneSnapshot(t *testing.T) { |
| me := os.Getuid() |
| for _, c := range []struct { |
| - name string |
| - late ProcInfo |
| - proven bool |
| + name string |
| + late ProcInfo |
| }{ |
| - {"unrelated", row(83400, 1, 83400, 83400, 9000, me, ""), true}, |
| - {"in a killed process's group", row(83600, 1, 83500, 83600, 9000, me, ""), false}, |
| + {"unrelated", row(83400, 1, 83400, 83400, 9000, me, "")}, |
| + {"in a killed process's group", row(83600, 1, 83500, 83600, 9000, me, "")}, |
| } { |
| t.Run(c.name, func(t *testing.T) { |
| tb := parseTable(t, turnBegan) |
| - _, u, _, run := liveTurn(t, tb, &Own{}, 300*time.Millisecond) |
| - defer u.Give() |
| + turns, u, _, run := liveTurn(t, tb, &Own{}, 300*time.Millisecond) |
| tb.add(row(83500, 1, 83500, 83500, 4000, me, ""), "/Users/paulequipo/w/lead") |
| // It needs SIGKILL, sent once the grace has passed. |
| tb.mark(&tb.stubborn, 83500) |
| @@ -196,12 +196,24 @@ func TestDiscoveryIsOneSnapshot(t *testing.T) { |
| tb.paths[c.late.PID] = "/Users/paulequipo/w/late" |
| } |
| } |
| - if got := run.Stop(); got != c.proven { |
| - t.Fatalf("proven %v, want %v (signalled %v)", got, c.proven, tb.signalled()) |
| + if run.Stop() { |
| + t.Fatalf("proven with %d alive (signalled %v)", c.late.PID, tb.signalled()) |
| } |
| if slices.Contains(tb.signalled(), c.late.PID) { |
| t.Fatalf("a read after discovery added %d: %v", c.late.PID, tb.signalled()) |
| } |
| + u.Give() |
| + if _, ok, _ := turns.loadTurn(); !ok { |
| + t.Fatal("the turn's record went with a process of the turn alive") |
| + } |
| + next, err := turns.Take(context.Background(), OpCheck) |
| + if err != nil { |
| + t.Fatalf("the next turn did not settle it: %v", err) |
| + } |
| + next.Give() |
| + if tb.has(c.late.PID) { |
| + t.Fatalf("%d survived the next turn's settling", c.late.PID) |
| + } |
| }) |
| } |
| } |
| @@ -256,3 +268,207 @@ func TestProofWaitsForEveryTarget(t *testing.T) { |
| t.Fatal("proven over with a double-forked child alive") |
| } |
| } |
| + |
| +// #7: the pending user-temp cleanup's proof read is under the same one |
| +// deadline: recovery that spends most of it settling the turn has only |
| +// the rest for the cleanup's recorded group. |
| +func TestVerifyHasOneDeadlineWithCleanup(t *testing.T) { |
| + me := os.Getuid() |
| + tb := parseTable(t, turnBegan) |
| + tb.add(row(94400, 1, 94400, 94400, 900, me, ""), "/Users/paulequipo/w/old") |
| + list, _ := tb.List(time.Time{}, nil) |
| + var before []ProcID |
| + for _, q := range list { |
| + before = append(before, q.ID) |
| + } |
| + tb.add(row(94200, 1, 94200, 94200, 5000, me, ""), "/Users/paulequipo/w/left") |
| + tb.mark(&tb.unkillable, 94200) |
| + turns := NewTurns(filepath.Join(t.TempDir(), "lock")).Sweep(tb) |
| + turns.own, turns.Settle = &Own{}, 300*time.Millisecond |
| + _, temp := userTempFixture(t) |
| + x := &Executor{Turns: turns, Settle: 300 * time.Millisecond, UserTemp: temp} |
| + if err := turns.saveTurn(turnRecord{ID: "dead", Op: OpCheck, Runner: selfID(), Sweep: true, Before: before, Markers: []string{"attempt-c"}, Complete: true}); err != nil { |
| + t.Fatal(err) |
| + } |
| + s, err := openTemp(temp, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := turns.writePending(pendingRecord{Attempt: "attempt-c", PGID: 94400, Before: s.before, Runner: selfID()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.close() |
| + time.AfterFunc(50*time.Millisecond, func() { tb.unmark(&tb.unkillable, 94200) }) |
| + time.AfterFunc(350*time.Millisecond, func() { tb.remove(94400) }) |
| + if x.Verify(RecordID(0, "attempt-c")) { |
| + t.Fatal("proven after its one deadline (the cleanup's group ended at 350 ms)") |
| + } |
| + if !x.Verify(RecordID(0, "attempt-c")) || turns.Pending() { |
| + t.Fatal("not proven, or not cleaned, on a later try once everything ended") |
| + } |
| +} |
| + |
| +// #8: once a launch's evidence could not be written, no other launch |
| +// starts in that turn, so no later stop can mark the record complete; |
| +// after a restart the first launch is never proven over. |
| +func TestFailedLaunchEndsTheTurnsLaunches(t *testing.T) { |
| + me := os.Getuid() |
| + lock := filepath.Join(t.TempDir(), "lock") |
| + tb := parseTable(t, turnBegan) |
| + turns := NewTurns(lock).Sweep(tb) |
| + turns.own, turns.Settle = &Own{}, 200*time.Millisecond |
| + u, err := turns.Take(context.Background(), OpEngineering) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx := u.Context(context.Background()) |
| + x := &Executor{Turns: turns, Grace: 20 * time.Millisecond, Settle: 200 * time.Millisecond, Poll: 10 * time.Millisecond} |
| + a, err := x.Start(ctx, Command{Argv: []string{"/bin/true"}}, "attempt-a", func(string) error { return nil }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + <-a.Exited() |
| + var failing atomic.Bool |
| + turns.beforeWrite = func() error { |
| + if failing.Load() { |
| + return errors.New("disk full") |
| + } |
| + return nil |
| + } |
| + failing.Store(true) |
| + tb.after = func(tb *table, pid int, sig syscall.Signal) { |
| + if pid == 97001 && tb.procs[97002].PID == 0 { |
| + tb.procs[97002] = row(97002, 1, 97002, 97001, 7000, 0, "") |
| + tb.paths[97002] = "/usr/bin/login" |
| + } |
| + } |
| + tb.add(row(97001, 1, a.pgid, 97001, 6001, me, ""), "/Users/paulequipo/w/s") |
| + select { |
| + case <-a.Aborted(): |
| + case <-time.After(3 * time.Second): |
| + t.Fatal("not stopped when its record could not be written") |
| + } |
| + if a.Stop() { |
| + t.Fatal("proven with its record unwritten") |
| + } |
| + // The disk recovers; the turn takes no other launch. |
| + failing.Store(false) |
| + b, err := x.Start(ctx, Command{Argv: []string{"/bin/true"}}, "attempt-b", func(string) error { return nil }) |
| + if err == nil { |
| + <-b.Exited() |
| + b.Stop() |
| + t.Error("a launch started after the turn lost a launch's evidence") |
| + } |
| + u.Give() |
| + next := NewTurns(lock).Sweep(tb) |
| + next.own, next.Settle = &Own{}, 200*time.Millisecond |
| + v, err := next.Take(context.Background(), OpCheck) |
| + if err != nil { |
| + t.Fatalf("the restarted runner is blocked: %v", err) |
| + } |
| + v.Give() |
| + nx := &Executor{Turns: next, Settle: 200 * time.Millisecond} |
| + if nx.Verify(a.ID()) || !next.Incomplete() { |
| + t.Fatal("the first launch was proven over, or the runner does not say it cannot be") |
| + } |
| +} |
| + |
| +// #8: the record is complete only when every launch of the turn has |
| +// finished its own durable writes: a launch not yet stopped keeps it |
| +// incomplete whatever another launch's stop wrote. |
| +func TestCompleteOnlyWhenEveryLaunchFinished(t *testing.T) { |
| + tb := parseTable(t, turnBegan) |
| + turns := NewTurns("").Sweep(tb) |
| + turns.own, turns.Settle = &Own{}, 200*time.Millisecond |
| + u, err := turns.Take(context.Background(), OpEngineering) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer u.Give() |
| + ctx := u.Context(context.Background()) |
| + x := &Executor{Turns: turns, Grace: 20 * time.Millisecond, Settle: 200 * time.Millisecond, Poll: 10 * time.Millisecond} |
| + a, err := x.Start(ctx, Command{Argv: []string{"/bin/sleep", "0.5"}}, "attempt-a", func(string) error { return nil }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + b, err := x.Start(ctx, Command{Argv: []string{"/bin/true"}}, "attempt-b", func(string) error { return nil }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + <-b.Exited() |
| + b.Stop() |
| + if rec, ok, _ := turns.loadTurn(); !ok || rec.Complete { |
| + t.Fatalf("complete with a launch not finished: %+v", rec) |
| + } |
| + <-a.Exited() |
| + a.Stop() |
| + if rec, ok, _ := turns.loadTurn(); !ok || !rec.Complete { |
| + t.Fatalf("not complete once every launch finished: %+v", rec) |
| + } |
| +} |
| + |
| +// #10: settling an earlier turn never releases the Mac (Owed) while a |
| +// process of the runner user born during that turn lives, though its |
| +// check reads add nothing: here a child born into a killed leader's |
| +// group after the settle's discovery read. |
| +func TestSettleKeepsTheTurnWhileALateProcessLives(t *testing.T) { |
| + me := os.Getuid() |
| + tb := parseTable(t, turnBegan) |
| + list, _ := tb.List(time.Time{}, nil) |
| + var before []ProcID |
| + for _, q := range list { |
| + before = append(before, q.ID) |
| + } |
| + turns := NewTurns("").Sweep(tb) |
| + turns.own, turns.Settle = &Own{}, 300*time.Millisecond |
| + if err := turns.saveTurn(turnRecord{ID: "old", Op: OpEngineering, Runner: selfID(), Sweep: true, Before: before, Markers: []string{"attempt-o"}, Complete: true}); err != nil { |
| + t.Fatal(err) |
| + } |
| + tb.add(row(83700, 1, 83700, 83700, 4000, me, ""), "/Users/paulequipo/w/lead") |
| + tb.mark(&tb.unkillable, 83700) |
| + signals := 0 |
| + tb.after = func(tb *table, pid int, sig syscall.Signal) { |
| + if pid != 83700 && pid != -83700 { |
| + return |
| + } |
| + // Signalled at the first kill pass and again after discovery: |
| + // then its last fork, and it dies. |
| + if signals++; signals == 3 && tb.procs[83701].PID == 0 { |
| + tb.procs[83701] = row(83701, 1, 83700, 83701, 9000, me, "") |
| + tb.paths[83701] = "/Users/paulequipo/w/late" |
| + delete(tb.unkillable, 83700) |
| + delete(tb.procs, 83700) |
| + } |
| + } |
| + if err := turns.settle(time.Now().Add(turns.settleLimit())); err == nil { |
| + t.Fatal("the Mac was released with a process of the earlier turn alive") |
| + } |
| + if _, ok, _ := turns.loadTurn(); !ok { |
| + t.Fatal("the earlier turn's record went") |
| + } |
| +} |
| + |
| +// #10: the group a killed process led stays an obligation after it |
| +// dies: a child born into it after discovery that is another user's (a |
| +// setuid program), which no read lists, still keeps the proof waiting, |
| +// though it is never signalled. |
| +func TestLedGroupObligationOutlivesItsLeader(t *testing.T) { |
| + me := os.Getuid() |
| + tb := parseTable(t, turnBegan) |
| + _, u, _, run := liveTurn(t, tb, &Own{}, 300*time.Millisecond) |
| + defer u.Give() |
| + tb.add(row(83800, 1, 83800, 83800, 4000, me, ""), "/Users/paulequipo/w/lead") |
| + tb.mark(&tb.stubborn, 83800) |
| + tb.after = func(tb *table, pid int, sig syscall.Signal) { |
| + if (pid == 83800 || pid == -83800) && sig == syscall.SIGKILL && tb.procs[83801].PID == 0 { |
| + tb.procs[83801] = row(83801, 1, 83800, 83801, 9000, 0, "") |
| + tb.paths[83801] = "/usr/bin/login" |
| + } |
| + } |
| + if run.Stop() { |
| + t.Fatal("proven while another user's child is in a group a killed process led") |
| + } |
| + if slices.Contains(tb.signalled(), 83801) { |
| + t.Fatal("another user's process was signalled") |
| + } |
| +} |
diff --git a/internal/runner/mac/launch.go b/internal/runner/mac/launch.go| index 4d84e56f..bbac89c8 100644 |
| --- a/internal/runner/mac/launch.go |
| +++ b/internal/runner/mac/launch.go |
| @@ -380,7 +380,7 @@ func (r *Run) stopWith(grace time.Duration) bool { |
| for id := range r.scope.Killed { |
| killed = append(killed, id) |
| } |
| - err := r.turn.finish(r.scope.Groups, r.scope.Sessions, killed) |
| + err := r.turn.finish(r.marker, r.scope.Groups, r.scope.Sessions, killed) |
| r.mu.Lock() |
| r.unwritten = err |
| r.mu.Unlock() |
| @@ -427,6 +427,8 @@ func (x *Executor) finishPending(ctx context.Context, turn *Turn, deadline time. |
| if !x.Turns.mayFinish(turn, r) { |
| return ErrPendingCleanup |
| } |
| + // settleRecord refuses a proof once deadline has passed (its last |
| + // act): the cleanup's proof read is under the caller's deadline. |
| if !x.settleRecord(r.PGID, r.Attempt, deadline) { |
| // That attempt's end, not this one's: nothing of this one ran. |
| return errors.Join(ErrPendingCleanup, errors.New("mac: its end is not proven")) |
| @@ -511,7 +513,8 @@ func (x *Executor) Verify(id string) bool { |
| if err != nil { |
| return false |
| } |
| - if pending && r.Attempt == attempt && x.finishPending(context.Background(), held, time.Now().Add(x.settleLimit())) != nil { |
| + // The cleanup's proof read is under the same deadline. |
| + if pending && r.Attempt == attempt && x.finishPending(context.Background(), held, deadline) != nil { |
| return false |
| } |
| } |
| @@ -560,25 +563,8 @@ func (x *Executor) settleRecord(pgid int, attempt string, deadline time.Time) bo |
| } |
| // Marked lists this user's processes whose environment carries |
| -// EQUIPO_ATTEMPT=<attempt> where the kernel shows it (/proc on Linux; |
| -// ps -E on a Mac, which cannot see platform binaries'). Never this |
| -// process. |
| -func Marked(attempt string) ([]Proc, error) { |
| - if attempt == "" { |
| - return nil, errors.New("mac: no attempt marker") |
| - } |
| - list, _, err := runnerOwn.Snapshot(time.Now().Add(30*time.Second), platformProcs, []string{attempt}) |
| - if err != nil { |
| - return nil, err |
| - } |
| - var out []Proc |
| - for _, q := range list { |
| - if q.Marker == attempt && q.PID != os.Getpid() { |
| - out = append(out, Proc{PID: q.PID, PGID: q.PGID}) |
| - } |
| - } |
| - return out, nil |
| -} |
| +// EQUIPO_ATTEMPT=<attempt> where the kernel shows it (proc.Marked). |
| +func Marked(attempt string) ([]Proc, error) { return proc.Marked(attempt) } |
| // Starter is thin's starter (containment.Manager's StartRecorded) for |
| // one Mac launch of the pinned CLI: Engineering, an ask or a token |
diff --git a/internal/runner/mac/proc/proc.go b/internal/runner/mac/proc/proc.go| index 4d6ec38d..e51ec533 100644 |
| --- a/internal/runner/mac/proc/proc.go |
| +++ b/internal/runner/mac/proc/proc.go |
| @@ -529,10 +529,13 @@ func (s *Scope) oblige(targets []Info) { |
| } |
| } |
| -// remaining is, in a check read, what keeps the proof from holding: the |
| -// kill set's processes still listed (signalled again) and marked |
| -// processes (never added). |
| +// remaining is, in a check read, what keeps the proof and the Mac's |
| +// clearance from holding: the kill set's processes still listed |
| +// (signalled again), and, never added or signalled, marked processes |
| +// and any other process of the runner user born during the turn that is |
| +// not the runner's own nor a launchd relaunch. |
| func (s *Scope) remaining(list []Info, own map[ID]bool) (left, kill []Info) { |
| + by := Index(list) |
| for _, q := range list { |
| if q.UID != s.uid || q.PID == s.self || q.PID <= 1 || own[q.ID] { |
| continue |
| @@ -540,7 +543,9 @@ func (s *Scope) remaining(list []Info, own map[ID]bool) (left, kill []Info) { |
| switch { |
| case s.Killed[q.ID]: |
| left, kill = append(left, q), append(kill, q) |
| - case s.marked(q): |
| + case s.marked(q), s.Seen[q.ID] || s.member(q, by): |
| + left = append(left, q) |
| + case s.before != nil && !s.before[q.ID] && !s.relaunch(q): |
| left = append(left, q) |
| } |
| } |
diff --git a/internal/runner/mac/proc/ps.go b/internal/runner/mac/proc/ps.go| index 0bd58fa0..d44d0464 100644 |
| --- a/internal/runner/mac/proc/ps.go |
| +++ b/internal/runner/mac/proc/ps.go |
| @@ -1,8 +1,11 @@ |
| package proc |
| import ( |
| + "errors" |
| + "os" |
| "strconv" |
| "strings" |
| + "time" |
| ) |
| // Proc is a process carrying an attempt's marker. |
| @@ -34,3 +37,24 @@ func ParseMarked(out, attempt string, self int) []Proc { |
| } |
| return procs |
| } |
| + |
| +// Marked lists this user's processes whose environment carries |
| +// EQUIPO_ATTEMPT=<attempt> where the kernel shows it (/proc on Linux; |
| +// ps -E on a Mac, which cannot see platform binaries'). Never this |
| +// process. |
| +func Marked(attempt string) ([]Proc, error) { |
| + if attempt == "" { |
| + return nil, errors.New("mac: no attempt marker") |
| + } |
| + list, _, err := Runner.Snapshot(time.Now().Add(30*time.Second), Platform, []string{attempt}) |
| + if err != nil { |
| + return nil, err |
| + } |
| + var out []Proc |
| + for _, q := range list { |
| + if q.Marker == attempt && q.PID != os.Getpid() { |
| + out = append(out, Proc{PID: q.PID, PGID: q.PGID}) |
| + } |
| + } |
| + return out, nil |
| +} |
diff --git a/internal/runner/mac/turns.go b/internal/runner/mac/turns.go| index 1840ce34..0617cde8 100644 |
| --- a/internal/runner/mac/turns.go |
| +++ b/internal/runner/mac/turns.go |
| @@ -125,6 +125,10 @@ type Turn struct { |
| rec turnRecord |
| adopted []string |
| unproven bool |
| + // finished is each launch's stop final note written; lost is set |
| + // once any evidence write of the turn failed (no launch after it). |
| + finished map[string]bool |
| + lost bool |
| gave sync.Once |
| given bool |
| } |
| @@ -261,25 +265,47 @@ func (u *Turn) before() []ProcID { |
| func (u *Turn) launch(marker string) error { |
| u.mu.Lock() |
| defer u.mu.Unlock() |
| + if u.lost { |
| + // An earlier launch's evidence was not written: its record can |
| + // never be completed, so nothing more runs in this turn. |
| + return errors.New("mac: this turn lost a launch's evidence") |
| + } |
| if !slices.Contains(u.rec.Markers, marker) { |
| u.rec.Markers = append(u.rec.Markers, marker) |
| } |
| + if u.finished == nil { |
| + u.finished = map[string]bool{} |
| + } |
| + u.finished[marker] = false |
| // Incomplete again until this launch's stop writes its final note. |
| u.rec.Complete = false |
| - return u.t.saveTurn(u.rec) |
| + if err := u.t.saveTurn(u.rec); err != nil { |
| + u.lost = true |
| + return err |
| + } |
| + return nil |
| } |
| -// finish is a stop's final note: everything it made, with the record |
| -// marked complete, written whatever grew. |
| -func (u *Turn) finish(groups, sessions span, killed []ProcID) error { |
| +// finish is launch marker's stop's final note: everything it made, |
| +// written whatever grew. The record is complete only once every launch |
| +// of the turn has finished its own writes and none was ever lost. |
| +func (u *Turn) finish(marker string, groups, sessions span, killed []ProcID) error { |
| if err := u.note(groups, sessions, killed...); err != nil { |
| return err |
| } |
| u.mu.Lock() |
| defer u.mu.Unlock() |
| + if u.lost { |
| + return errors.New("mac: this turn lost a launch's evidence") |
| + } |
| + u.finished[marker] = true |
| rec := u.rec |
| rec.Complete = true |
| + for _, done := range u.finished { |
| + rec.Complete = rec.Complete && done |
| + } |
| if err := u.t.saveTurn(rec); err != nil { |
| + u.lost = true |
| return err |
| } |
| u.rec = rec |
| @@ -320,6 +346,7 @@ func (u *Turn) note(groups, sessions span, killed ...ProcID) error { |
| return nil |
| } |
| if err := u.t.saveTurn(rec); err != nil { |
| + u.lost = true |
| return err |
| } |
| u.rec = rec |