Headless Mac worker scenarios M1, M2, M4, M5 with the fake worker
A Woodstar-shaped repository whose gate runs xcodebuild test, a fake xcodebuild (passes, fails with the fixing edit, or hangs), and the fake Mac worker as the owner's second runner, run as a process. M1: checks placed on the worker through the pack relay pass, review stays on the primary, Equipo merges. M5: the worker's failing output drives the fix round. M2: offline worker, waiting, reconnect, run; then the 30-minute rule with a fake clock (runner_offline, review proceeds). M4: SIGKILL mid-checks, the process group proven gone on restart (nothing of it survives), Retry refused until then, then passes. Termination kinds default per runner; question trees keep the plain lease (an ask is not a step attempt).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+322
−11
internal/headless/env_test.go+16 −6internal/headless/mac_test.go+248 −0internal/headless/xcodebuild_test.go+31 −0internal/runner/thin/ask.go+1 −1internal/runner/thin/engineer.go+1 −1internal/runner/thin/run.go+2 −2internal/runner/thin/step.go+23 −1
CI failed — run details
Intent
diff --git a/internal/headless/env_test.go b/internal/headless/env_test.go| index fe5875e3..9e9bb7c8 100644 |
| --- a/internal/headless/env_test.go |
| +++ b/internal/headless/env_test.go |
| @@ -35,6 +35,8 @@ func TestMain(m *testing.M) { |
| switch filepath.Base(os.Args[0]) { |
| case "claude": |
| os.Exit(fakeclaude.Main(os.Args[1:], os.Stdin, os.Stdout, os.Stderr)) |
| + case "xcodebuild": |
| + os.Exit(fakeXcodebuild()) |
| case "equipo-tool-proxy": |
| if len(os.Args) != 3 || os.Args[1] != "--socket" { |
| os.Exit(2) |
| @@ -118,9 +120,12 @@ type localRunner struct { |
| opts thin.Options |
| // subprocess runs the runner as its own process, so it can be killed. |
| subprocess bool |
| - inst *thintest.Instance |
| - root string |
| - cmd *exec.Cmd |
| + // runnerID scopes the connection wait to this runner (several runners |
| + // share one instance). |
| + runnerID string |
| + inst *thintest.Instance |
| + root string |
| + cmd *exec.Cmd |
| mu sync.Mutex |
| cancel context.CancelFunc |
| @@ -374,6 +379,7 @@ type processConfig struct { |
| ClaudePath, CodexPath, CodexCodeModeHostPath, BwrapPath, GoRoot string |
| GoBinary, WorkspaceRoot, ScratchRoot, GitPath, AmadanPath, ToolProxy string |
| Digest, MoveInNote string |
| + MachineLabel, FakePlatform, FakeBin string |
| NoMoveIn bool |
| Idle, LockWait, MaxTurn, Margin time.Duration |
| // Forge is the local forge's state, so a runner process works on the |
| @@ -388,10 +394,10 @@ func runnerProcess(path string) int { |
| return 2 |
| } |
| self, _ := os.Executable() |
| - cfg := runner.Config{Origin: p.Origin, InstanceID: p.InstanceID, StateDir: p.StateDir, AccountBindingsPath: p.AccountBindingsPath, AmadanCredentialPath: p.AmadanCredentialPath, ClaudePath: p.ClaudePath, CodexPath: p.CodexPath, CodexCodeModeHostPath: p.CodexCodeModeHostPath, BwrapPath: p.BwrapPath, GoRoot: p.GoRoot, GoBinary: p.GoBinary, WorkspaceRoot: p.WorkspaceRoot, ScratchRoot: p.ScratchRoot, GitPath: p.GitPath, AmadanPath: p.AmadanPath, ToolProxyPath: p.ToolProxy, Executable: self} |
| + cfg := runner.Config{MachineLabel: p.MachineLabel, Origin: p.Origin, InstanceID: p.InstanceID, StateDir: p.StateDir, AccountBindingsPath: p.AccountBindingsPath, AmadanCredentialPath: p.AmadanCredentialPath, ClaudePath: p.ClaudePath, CodexPath: p.CodexPath, CodexCodeModeHostPath: p.CodexCodeModeHostPath, BwrapPath: p.BwrapPath, GoRoot: p.GoRoot, GoBinary: p.GoBinary, WorkspaceRoot: p.WorkspaceRoot, ScratchRoot: p.ScratchRoot, GitPath: p.GitPath, AmadanPath: p.AmadanPath, ToolProxyPath: p.ToolProxy, Executable: self} |
| ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt) |
| defer stop() |
| - opts := thin.Options{Version: "test", Logger: slog.New(slog.NewTextHandler(os.Stderr, nil)), NoMoveIn: p.NoMoveIn, MergeEvery: time.Second} |
| + opts := thin.Options{Version: "test", Logger: slog.New(slog.NewTextHandler(os.Stderr, nil)), NoMoveIn: p.NoMoveIn, MergeEvery: time.Second, FakePlatform: p.FakePlatform, FakeBin: p.FakeBin} |
| if p.Forge != nil { |
| opts.Forge = p.Forge.forge() |
| } |
| @@ -405,6 +411,10 @@ func runnerProcess(path string) int { |
| func (r *localRunner) generation() int64 { |
| var g int64 |
| + if r.runnerID != "" { |
| + r.inst.DB.Writer().QueryRow("SELECT coalesce(max(generation),0) FROM runner_sessions WHERE connected = 1 AND runner_id = ?", r.runnerID).Scan(&g) |
| + return g |
| + } |
| r.inst.DB.Writer().QueryRow("SELECT coalesce(max(generation),0) FROM runner_sessions WHERE connected = 1").Scan(&g) |
| return g |
| } |
| @@ -416,7 +426,7 @@ func (r *localRunner) startProcess(t *testing.T) { |
| if lf, ok := r.opts.Forge.(*localForge); ok { |
| fs = lf.state() |
| } |
| - raw, _ := json.Marshal(processConfig{Forge: fs, Origin: c.Origin, InstanceID: c.InstanceID, StateDir: c.StateDir, AccountBindingsPath: c.AccountBindingsPath, AmadanCredentialPath: c.AmadanCredentialPath, ClaudePath: c.ClaudePath, CodexPath: c.CodexPath, CodexCodeModeHostPath: c.CodexCodeModeHostPath, BwrapPath: c.BwrapPath, GoRoot: c.GoRoot, GoBinary: c.GoBinary, WorkspaceRoot: c.WorkspaceRoot, ScratchRoot: c.ScratchRoot, GitPath: c.GitPath, AmadanPath: c.AmadanPath, ToolProxy: c.ToolProxyPath, Digest: o.Digest, MoveInNote: o.MoveInNote, NoMoveIn: r.opts.NoMoveIn, Idle: o.Idle, LockWait: o.LockWait, MaxTurn: o.MaxTurn, Margin: o.Margin}) |
| + raw, _ := json.Marshal(processConfig{Forge: fs, Origin: c.Origin, InstanceID: c.InstanceID, StateDir: c.StateDir, AccountBindingsPath: c.AccountBindingsPath, AmadanCredentialPath: c.AmadanCredentialPath, ClaudePath: c.ClaudePath, CodexPath: c.CodexPath, CodexCodeModeHostPath: c.CodexCodeModeHostPath, BwrapPath: c.BwrapPath, GoRoot: c.GoRoot, GoBinary: c.GoBinary, WorkspaceRoot: c.WorkspaceRoot, ScratchRoot: c.ScratchRoot, GitPath: c.GitPath, AmadanPath: c.AmadanPath, ToolProxy: c.ToolProxyPath, Digest: o.Digest, MoveInNote: o.MoveInNote, MachineLabel: c.MachineLabel, FakePlatform: r.opts.FakePlatform, FakeBin: r.opts.FakeBin, NoMoveIn: r.opts.NoMoveIn, Idle: o.Idle, LockWait: o.LockWait, MaxTurn: o.MaxTurn, Margin: o.Margin}) |
| path := filepath.Join(r.root, "runner.json") |
| if err := os.WriteFile(path, raw, 0600); err != nil { |
| t.Fatal(err) |
diff --git a/internal/headless/mac_test.go b/internal/headless/mac_test.go| new file mode 100644 |
| index 00000000..a9eef865 |
| --- /dev/null |
| +++ b/internal/headless/mac_test.go |
| @@ -0,0 +1,248 @@ |
| +//go:build testbuild |
| + |
| +package headless |
| + |
| +import ( |
| + "context" |
| + "io" |
| + "log/slog" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/runner/thin" |
| + "amadan.net/oficina/equipo/internal/thintest" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +const woodstar = "amadan.net/woodstar/woodstar" |
| + |
| +// addWoodstar adds an iOS app to the local forge: its gate runs |
| +// xcodebuild test, it has a shared scheme, and edge swipe does nothing. |
| +func addWoodstar(t *testing.T, root string, f *localForge) { |
| + t.Helper() |
| + work := filepath.Join(root, "seed-woodstar") |
| + for p, body := range map[string]string{ |
| + "README.md": "# Woodstar\n\nAn iOS reading app with sliding panes.\n", |
| + ".amadan/ci": "#!/bin/sh\nset -e\nxcodebuild test -scheme Woodstar -destination 'platform=iOS Simulator,name=iPhone 16 Pro'\n", |
| + "Woodstar/Swipe.swift": "let edgeSwipe = false\n", |
| + "Woodstar.xcodeproj/xcshareddata/xcschemes/Woodstar.xcscheme": "<Scheme/>\n", |
| + } { |
| + if err := os.MkdirAll(filepath.Dir(filepath.Join(work, p)), 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + mode := os.FileMode(0600) |
| + if p == ".amadan/ci" { |
| + mode = 0700 |
| + } |
| + if err := os.WriteFile(filepath.Join(work, p), []byte(body), mode); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + gitRun(t, work, "init", "-q", "-b", "main") |
| + gitRun(t, work, "add", "-A") |
| + gitRun(t, work, "commit", "-q", "-m", "seed") |
| + gitRun(t, root, "clone", "-q", "--bare", work, f.path(woodstar)) |
| + f.mu.Lock() |
| + f.repos = append(f.repos, woodstar) |
| + f.mu.Unlock() |
| +} |
| + |
| +// macWorker is the fake Mac worker: the real thin runner of the test |
| +// build with EQUIPO_FAKE_PLATFORM, enrolled as the owner's second runner |
| +// (a worker), its own roots, the fake xcodebuild first on its gates' |
| +// PATH, run as a process so it can be killed. |
| +func macWorker(t *testing.T, inst *thintest.Instance, primary *localRunner) (*localRunner, string) { |
| + t.Helper() |
| + root := private(t, filepath.Join(primary.root, "mac")) |
| + bin := private(t, filepath.Join(root, "bin")) |
| + copyExecutable(t, filepath.Join(bin, "xcodebuild")) |
| + state := private(t, filepath.Join(root, "state")) |
| + cred := inst.EnrolRunner(t) |
| + if err := thintest.WriteRunnerCredential(state, cred); err != nil { |
| + t.Fatal(err) |
| + } |
| + cfg := primary.cfg |
| + cfg.StateDir, cfg.WorkspaceRoot, cfg.ScratchRoot, cfg.MachineLabel = state, filepath.Join(root, "work"), filepath.Join(root, "scratch"), "Tito Studio" |
| + w := &localRunner{inst: inst, root: root, cfg: cfg, subprocess: true, runnerID: cred.RunnerID, opts: thin.Options{Version: "test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), FakePlatform: "darwin/arm64", FakeBin: bin, Claude: primary.opts.Claude}} |
| + t.Cleanup(func() { w.stop(t) }) |
| + return w, filepath.Join(bin, "xcodebuild") |
| +} |
| + |
| +func stepOf(k wire.Task, specialist string, n int) wire.Step { |
| + for _, s := range k.Steps { |
| + if s.Specialist == specialist { |
| + if n == 0 { |
| + return s |
| + } |
| + n-- |
| + } |
| + } |
| + return wire.Step{} |
| +} |
| + |
| +// TestMacWorker runs the Mac worker scenarios of the spec (§6, M1, M2, |
| +// M4, M5) against a local instance, the primary runner with the fake CLI |
| +// in real bubblewrap, and the fake Mac worker. |
| +func TestMacWorker(t *testing.T) { |
| + env, inst, primary := localEnv(t) |
| + addWoodstar(t, primary.root, primary.opts.Forge.(*localForge)) |
| + primary.start(t) |
| + worker, xcodebuild := macWorker(t, inst, primary) |
| + worker.start(t) |
| + s := open(t, env) |
| + s.keep() |
| + s.wait(t, "the worker online", 30*time.Second, func(c *thintest.Conversation) bool { |
| + for _, r := range c.Runners { |
| + if r.Role == wire.RoleWorker && r.Online && r.Label == "Tito Studio" { |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + |
| + // M5: the fake gate fails on the worker (a README change, judged on a |
| + // Mac because Woodstar's gate is xcodebuild); the fix round works from |
| + // its output; the new candidate's checks pass on the worker. |
| + t.Run("M5", func(t *testing.T) { |
| + sent := s.send(t, "tool:record_task:woodstar/woodstar|Describe the panes|Say what the panes are for.\ntool:start_task:$task|edit:README.md|sliding panes|sliding panes, again") |
| + id := s.taskOf(t, sent.Turn.ID) |
| + s.wait(t, "merged", 4*time.Minute, func(c *thintest.Conversation) bool { return c.Tasks[id].Stage == wire.StageDone }) |
| + k, _ := env.Client.Task(s.ctx, id) |
| + first, second := stepOf(k, wire.SpecialistChecks, 0), stepOf(k, wire.SpecialistChecks, 1) |
| + if first.Checks != wire.ChecksFailed || first.ExitCode == nil || *first.ExitCode != 65 || first.RunnerLabel != "Tito Studio" || k.FixRounds != 1 || second.Checks != wire.ChecksPassed || second.CandidateSHA != k.CandidateSHA { |
| + t.Fatalf("fix round from the worker's output: %+v / %+v / rounds %d", first, second, k.FixRounds) |
| + } |
| + }) |
| + |
| + // M1: an iOS change; its checks are placed on the worker, the |
| + // candidate relayed as a pack, xcodebuild passes there; review stays on |
| + // the primary; Equipo merges it. |
| + t.Run("M1", func(t *testing.T) { |
| + sent := s.send(t, "tool:record_task:woodstar/woodstar|iOS edge swipe|Swipe back from the edge feels late.\ntool:start_task:$task|edit:Woodstar/Swipe.swift|edgeSwipe = true|edgeSwipe = true // from the edge") |
| + id := s.taskOf(t, sent.Turn.ID) |
| + k := s.settled(t, id, 3*time.Minute) |
| + s.wait(t, "merged", time.Minute, func(c *thintest.Conversation) bool { return c.Tasks[id].Stage == wire.StageDone }) |
| + k, _ = env.Client.Task(s.ctx, id) |
| + checks, review := stepOf(k, wire.SpecialistChecks, 0), stepOf(k, wire.SpecialistReview, 0) |
| + if checks.RunnerLabel != "Tito Studio" || checks.Checks != wire.ChecksPassed || checks.Gate != ".amadan/ci" || checks.ExitCode == nil || *checks.ExitCode != 0 || checks.TerminationKind != wire.TerminationProcessGroup || strings.Join(checks.Needs, ",") != "macos,xcode,ios_simulator" || checks.CandidateSHA != k.CandidateSHA { |
| + t.Fatalf("checks %+v", checks) |
| + } |
| + if review.RunnerID == checks.RunnerID || review.Verdict != wire.VerdictApprove || review.TerminationKind != wire.TerminationNamespace { |
| + t.Fatalf("review %+v", review) |
| + } |
| + log, err := env.Client.StepLog(s.ctx, checks.ID) |
| + if err != nil || !strings.Contains(log.Tail, "** TEST SUCCEEDED **") { |
| + t.Fatalf("checks log %+v %v", log, err) |
| + } |
| + if k.Merged == nil || k.Merged.WithoutChecks || k.EngineeringRunner == checks.RunnerID { |
| + t.Fatalf("merge %+v", k) |
| + } |
| + }) |
| + |
| + // M2: the worker is offline; checks wait (no dispatch anywhere), then |
| + // run when it is back. A second task waits 30 minutes (a fake clock) |
| + // and resolves as not run, runner_offline, never a pass; review goes on. |
| + t.Run("M2", func(t *testing.T) { |
| + worker.stop(t) |
| + s.wait(t, "the worker offline", 30*time.Second, func(c *thintest.Conversation) bool { |
| + for _, r := range c.Runners { |
| + if r.Role == wire.RoleWorker && !r.Online { |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + sent := s.send(t, "tool:record_task:woodstar/woodstar|README while away|Name the app.\ntool:start_task:$task|edit:README.md|reading app|reading app (m2a)") |
| + id := s.taskOf(t, sent.Turn.ID) |
| + s.wait(t, "checks waiting", 2*time.Minute, func(c *thintest.Conversation) bool { |
| + for _, st := range c.Tasks[id].Steps { |
| + if st.Specialist == wire.SpecialistChecks && st.Placement == wire.PlacementWaiting { |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + worker.start(t) |
| + s.wait(t, "merged after the worker came back", 3*time.Minute, func(c *thintest.Conversation) bool { return c.Tasks[id].Stage == wire.StageDone }) |
| + k, _ := env.Client.Task(s.ctx, id) |
| + if c := stepOf(k, wire.SpecialistChecks, 0); c.Checks != wire.ChecksPassed || c.RunnerLabel != "Tito Studio" { |
| + t.Fatalf("checks after reconnect %+v", c) |
| + } |
| + |
| + worker.stop(t) |
| + sent = s.send(t, "tool:record_task:woodstar/woodstar|README, worker gone|Name it again.\ntool:start_task:$task|edit:README.md|reading app (m2a)|reading app (m2b)") |
| + late := s.taskOf(t, sent.Turn.ID) |
| + s.wait(t, "checks waiting", 2*time.Minute, func(c *thintest.Conversation) bool { |
| + for _, st := range c.Tasks[late].Steps { |
| + if st.Specialist == wire.SpecialistChecks && st.Placement == wire.PlacementWaiting { |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + later := time.Now().UTC().Add(chat.OfflineLimit + time.Minute) |
| + inst.Store.Chat().SetClock(func() time.Time { return later }) |
| + if err := inst.Store.Chat().Place(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + inst.Store.Chat().SetClock(func() time.Time { return time.Now().UTC() }) |
| + k = s.settled(t, late, 2*time.Minute) |
| + c := stepOf(k, wire.SpecialistChecks, 0) |
| + if c.Checks != wire.ChecksCannotRun || c.Reason != "runner_offline" || k.Checks == wire.ChecksPassed || k.Stage != wire.StageReadyToMerge || stepOf(k, wire.SpecialistReview, 0).Verdict != wire.VerdictApprove { |
| + t.Fatalf("offline checks %+v task %+v", c, k) |
| + } |
| + }) |
| + |
| + // M4: the worker is SIGKILLed while xcodebuild runs. Its gate's process |
| + // group outlives it; on restart the worker kills what is left, proves |
| + // the end by process group, and only then does Retry run the checks |
| + // again, which pass. |
| + t.Run("M4", func(t *testing.T) { |
| + worker.start(t) |
| + if err := os.WriteFile(xcodebuild+".hang", nil, 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + sent := s.send(t, "tool:record_task:woodstar/woodstar|Killed mid checks|Tighten the summary line.\ntool:start_task:$task|edit:README.md|reading app (m2a)|reading app (m4)") |
| + id := s.taskOf(t, sent.Turn.ID) |
| + s.wait(t, "checks running on the worker", 3*time.Minute, func(c *thintest.Conversation) bool { |
| + for _, st := range c.Tasks[id].Steps { |
| + if st.Specialist == wire.SpecialistChecks && st.State == wire.StepRunning && st.StartedAt != nil { |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + time.Sleep(time.Second) |
| + worker.kill(t) |
| + if _, err := env.Client.RetryTask(s.ctx, id); thintest.Status(err) != 409 { |
| + t.Fatalf("retry before the worker proved termination: %v", err) |
| + } |
| + os.Remove(xcodebuild + ".hang") |
| + worker.start(t) |
| + k := s.settled(t, id, 2*time.Minute) |
| + c := stepOf(k, wire.SpecialistChecks, 0) |
| + if c.State != wire.StepFailed || c.Reason != "runner_restarted" || !c.Terminated || c.TerminationKind != wire.TerminationProcessGroup || k.NeedsYou != wire.NeedsRetry { |
| + t.Fatalf("after the kill %+v", c) |
| + } |
| + // Nothing of the killed attempt is left running (no checks run now). |
| + entries, _ := os.ReadDir("/proc") |
| + for _, e := range entries { |
| + env, err := os.ReadFile(filepath.Join("/proc", e.Name(), "environ")) |
| + if err == nil && strings.Contains(string(env), "EQUIPO_ATTEMPT=checks/") { |
| + t.Fatalf("process %s of the killed attempt survived", e.Name()) |
| + } |
| + } |
| + if _, err := env.Client.RetryTask(s.ctx, id); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.wait(t, "merged after Retry", 3*time.Minute, func(c *thintest.Conversation) bool { return c.Tasks[id].Stage == wire.StageDone }) |
| + k, _ = env.Client.Task(s.ctx, id) |
| + if c := stepOf(k, wire.SpecialistChecks, 0); c.Attempt != 2 || c.Checks != wire.ChecksPassed || c.RunnerLabel != "Tito Studio" { |
| + t.Fatalf("checks after Retry %+v", c) |
| + } |
| + }) |
| +} |
diff --git a/internal/headless/xcodebuild_test.go b/internal/headless/xcodebuild_test.go| new file mode 100644 |
| index 00000000..fa6caee2 |
| --- /dev/null |
| +++ b/internal/headless/xcodebuild_test.go |
| @@ -0,0 +1,31 @@ |
| +package headless |
| + |
| +import ( |
| + "fmt" |
| + "os" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// fakeXcodebuild is the fake worker's xcodebuild (a copy of this test |
| +// binary named xcodebuild): it fails while Woodstar/Swipe.swift or |
| +// Pane.swift says false, printing the edit that fixes it, passes |
| +// otherwise, and hangs while a file named like it with ".hang" exists. |
| +func fakeXcodebuild() int { |
| + self, _ := os.Executable() |
| + if _, err := os.Stat(self + ".hang"); err == nil { |
| + fmt.Println("Testing started") |
| + time.Sleep(time.Hour) |
| + return 1 |
| + } |
| + fmt.Println("Test Suite 'All tests' started") |
| + for _, c := range [][2]string{{"Woodstar/Swipe.swift", "edgeSwipe"}, {"Woodstar/Pane.swift", "paneBack"}} { |
| + src, _ := os.ReadFile(c[0]) |
| + if strings.Contains(string(src), c[1]+" = false") { |
| + fmt.Printf("%s:1: error: XCTAssertTrue failed: %s is false. edit:%s|%s = false|%s = true\n** TEST FAILED **\n", c[0], c[1], c[0], c[1], c[1]) |
| + return 65 |
| + } |
| + } |
| + fmt.Println("Test Suite 'All tests' passed.\n** TEST SUCCEEDED **") |
| + return 0 |
| +} |
diff --git a/internal/runner/thin/ask.go b/internal/runner/thin/ask.go| index b5460fd1..92414dc7 100644 |
| --- a/internal/runner/thin/ask.go |
| +++ b/internal/runner/thin/ask.go |
| @@ -718,7 +718,7 @@ func (e *Engineer) answer(ctx context.Context, a askRow, progress func(wire.Answ |
| } |
| // The tree of the exact commit, fresh and read-only, under the |
| // question's own key. |
| - r := stepRow{DispatchCommand: wire.DispatchCommand{Person: a.Person, TaskID: a.TaskID, StepID: a.QuestionID, Attempt: a.Attempt, Repo: a.Repo, Branch: a.Branch, BaseSHA: a.BaseSHA, CandidateSHA: a.CandidateSHA}} |
| + r := stepRow{DispatchCommand: wire.DispatchCommand{Person: a.Person, TaskID: a.TaskID, StepID: a.QuestionID, Attempt: a.Attempt, Repo: a.Repo, Branch: a.Branch, BaseSHA: a.BaseSHA, CandidateSHA: a.CandidateSHA}, Question: true} |
| tree, reason, err := e.judgeTree(ctx, r) |
| if err != nil { |
| return fail(reason) |
diff --git a/internal/runner/thin/engineer.go b/internal/runner/thin/engineer.go| index 7eca3ae2..e66950ea 100644 |
| --- a/internal/runner/thin/engineer.go |
| +++ b/internal/runner/thin/engineer.go |
| @@ -284,7 +284,7 @@ func (e *Engineer) Sweep(ctx context.Context, s *State) { |
| // confirmFor is the pre-push confirmation of one attempt. |
| func (e *Engineer) confirmFor(r stepRow) func(context.Context) error { |
| return func(ctx context.Context) error { |
| - if e.AuthorizeStep != nil { |
| + if e.AuthorizeStep != nil && !r.Question { |
| return e.AuthorizeStep(ctx, r.StepID, r.Attempt) |
| } |
| if e.Authorize == nil { |
diff --git a/internal/runner/thin/run.go b/internal/runner/thin/run.go| index cd69dbe9..6bc8611e 100644 |
| --- a/internal/runner/thin/run.go |
| +++ b/internal/runner/thin/run.go |
| @@ -219,7 +219,7 @@ func Run(ctx context.Context, c runner.Config, o Options) error { |
| engineer.Sweep(ctx, state) |
| engineer.sweepKept(ctx, state) |
| engineer.SweepPublications(ctx, state) |
| - }, Verify: func(ctx context.Context, id string) bool { return verifiedExit(ctx, manager, id) }} |
| + }, Verify: func(ctx context.Context, id string) bool { return verifiedExit(ctx, manager, id) }, TerminationKind: wire.TerminationNamespace} |
| link.Steps = steps |
| relay := &Relay{State: state, Engine: engineer, Notify: link.Notify, Logger: o.Logger} |
| link.Relay = relay |
| @@ -535,7 +535,7 @@ func runWorker(ctx context.Context, c runner.Config, o Options, platform wire.Pl |
| } |
| } |
| }, |
| - Verify: func(_ context.Context, id string) bool { return id == "" || gate.Verify(id) }} |
| + Verify: func(_ context.Context, id string) bool { return id == "" || gate.Verify(id) }, TerminationKind: wire.TerminationProcessGroup} |
| link.Steps = steps |
| if err := steps.Start(ctx); err != nil { |
| return err |
diff --git a/internal/runner/thin/step.go b/internal/runner/thin/step.go| index ad1c0103..11321080 100644 |
| --- a/internal/runner/thin/step.go |
| +++ b/internal/runner/thin/step.go |
| @@ -6,6 +6,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "log/slog" |
| + "strings" |
| "sync" |
| "time" |
| @@ -39,6 +40,9 @@ type stepRow struct { |
| Cancel bool |
| // Created orders steps and questions in the engine's one queue. |
| Created string |
| + // Question: a question's tree (StepID is the question's id). It is |
| + // not a step attempt, so it takes the plain execution lease. |
| + Question bool |
| } |
| func (r stepRow) key() string { return r.StepID + "/" + itoa(r.Attempt) } |
| @@ -233,7 +237,7 @@ func (s *State) proveTermination(ctx context.Context, p pendingStep) error { |
| if n, _ := res.RowsAffected(); n != 1 { |
| return nil |
| } |
| - return s.enqueue(t, wire.FrameStep, "", wire.StepReport{TaskID: p.task, StepID: p.step, Attempt: p.attempt, State: p.state, Reason: p.reason, Termination: true}) |
| + return s.enqueue(t, wire.FrameStep, "", wire.StepReport{TaskID: p.task, StepID: p.step, Attempt: p.attempt, State: p.state, Reason: p.reason, Termination: true, TerminationKind: terminationKind(p.ns)}) |
| }) |
| } |
| @@ -268,6 +272,9 @@ func (s *State) RecoverSteps(ctx context.Context, verify func(context.Context, s |
| return s.tx(ctx, func(t *sql.Tx) error { |
| for _, r := range all { |
| rep := wire.StepReport{TaskID: r.TaskID, StepID: r.StepID, Attempt: r.Attempt, BaseSHA: r.Base, Termination: proven[r.key()]} |
| + if rep.Termination { |
| + rep.TerminationKind = terminationKind(ns[r.key()]) |
| + } |
| switch { |
| case r.Phase == phaseCommitted: |
| continue |
| @@ -315,6 +322,9 @@ type StepEngine struct { |
| // Verify reports whether a namespace's exit is verified now (its |
| // record released after proof, or gone). |
| Verify func(ctx context.Context, nsID string) bool |
| + // TerminationKind is how this runner proves an attempt's end |
| + // (wire.TerminationNamespace on Linux), reported with termination. |
| + TerminationKind string |
| mu sync.Mutex |
| wake chan struct{} |
| @@ -528,6 +538,9 @@ func (e *StepEngine) askOne(ctx context.Context, a askRow) { |
| func (e *StepEngine) runOne(ctx context.Context, r stepRow) { |
| report := func(rep wire.StepReport) { |
| + if rep.Termination && rep.TerminationKind == "" { |
| + rep.TerminationKind = e.TerminationKind |
| + } |
| e.log("step report", e.State.ReportStep(context.WithoutCancel(ctx), r, rep)) |
| e.Notify() |
| } |
| @@ -568,3 +581,12 @@ func (e *StepEngine) runOne(ctx context.Context, r stepRow) { |
| // stepWait bounds one wait for the lease before an attempt starts. |
| const stepWait = time.Second |
| + |
| +// terminationKind is how a recorded attempt's end was proven: a process |
| +// group ("pg:" records, a worker) or a namespace. |
| +func terminationKind(record string) string { |
| + if strings.HasPrefix(record, "pg:") { |
| + return wire.TerminationProcessGroup |
| + } |
| + return wire.TerminationNamespace |
| +} |