oficina / equipo Public

Mac slice F task 3 fix 2: the task's Mac need is one durable fact

Astra round 2 on task 3. Migration 0120 gains chat_tasks.mac_needs:
the Mac tags a task's Engineering was first found to need, written in
the placement transaction the first time it is Mac work, never
cleared and never part of saveTask. engineeringNeeds reads it first;
the catalog can only add needs. The inferred sources (worker pin,
publication) are removed.

So a primary replaced mid base preparation with a Linux one whose
catalog omits the repository, or a task re-pinned from a Mac worker
to a Mac primary that is then removed, never sends Mac Engineering to
Linux. Never-Mac tasks are unaffected.

Budgets re-measured on HEAD: chat 38671/12096, thintest 38383.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev b9b568d8fe6512aee3ffe6e38863f39d1903f30a parent 6c0ffa2
7 files changed, +169 −24
  • .rastrillo/budgets.txt +2 −2
  • internal/equipo/chat/runners.go +29 −19
  • internal/equipo/chat/tasks.go +5 −0
  • internal/equipo/migrations/0120_mac_engineering.sql +4 −1
  • internal/equipo/migrations/schema.sql +1 −0
  • internal/equipo/migrations_mac_engineering_test.go +1 −0
  • internal/thintest/mac_engineering_contract_test.go +127 −2
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 05d19ee8..51d1f67e 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device
perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen.
perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen.
-size internal/equipo/chat 38656 12096 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places, waiting cards, Mac waits, Mac Engineering; measured 38656/12096.
+size internal/equipo/chat 38671 12096 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places, waiting cards, Mac waits, Mac Engineering; measured 38671/12096.
perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}.
perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}.
perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections.
@@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im
perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section.
time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally).
size internal/headless - 11977 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files end to end; the restart wait; the live site waits for a place; a card answer settles at the bottom; measured 11977 test lines.
-size internal/thintest - 38258 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, Mac waits, Mac Engineering; measured 38258.
+size internal/thintest - 38383 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, Mac waits, Mac Engineering; measured 38383.
perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}.
perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage.
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go
index 2417b407..2d82c910 100644
--- a/internal/equipo/chat/runners.go
+++ b/internal/equipo/chat/runners.go
@@ -406,39 +406,36 @@ func (t *txn) checksNeeds(k taskRecord, s stepRecord) ([]string, error) {
// engineeringNeeds are the tags Engineering of the task needs: macOS and
// Xcode (and the simulator) when the repository's gate needs Xcode, as
// the primary's index of its default branch says (the base, not anything
-// the change wrote), and claude to make the change there (slice F).
-// A task whose Engineering was once on a Mac keeps that need whatever the
-// catalog says later (onMac): its rounds never move to Linux. Anything
-// else needs nothing.
+// the change wrote), and claude to make the change there (slice F). The
+// task's recorded Mac need (MacNeeds) comes first: the catalog can add
+// to it, never take it away. Anything else needs nothing.
func (t *txn) engineeringNeeds(k taskRecord, person string) ([]string, error) {
info, err := t.repoInfo(k, person)
if err != nil {
return nil, err
}
- mac := info.NeedsMacOS
- if !mac {
- if mac, err = t.onMac(k); err != nil {
- return nil, err
+ needs := decodeList(k.MacNeeds)
+ for _, tag := range macNeeds(info.NeedsMacOS, info) {
+ if !slices.Contains(needs, tag) {
+ needs = append(needs, tag)
}
}
- needs := macNeeds(mac, info)
if len(needs) > 0 {
needs = append(needs, wire.TagClaude)
}
return needs, nil
}
-// onMac reports whether the task's Engineering was ever on a Mac: pinned
-// to a worker (removed or not), or a round's commit published for one.
-func (t *txn) onMac(k taskRecord) (bool, error) {
- var n int64
- if k.EngineeringRunner != "" {
- if err := t.db.Raw(`SELECT count(*) FROM runners WHERE id = ? AND role = ?`, k.EngineeringRunner, wire.RoleWorker).Scan(&n).Error; err != nil || n > 0 {
- return n > 0, err
- }
+// recordMacNeeds records, the first time placement finds the task's
+// Engineering needs a Mac, which Mac tags it needs, in the placement's
+// transaction. Never cleared or changed after.
+func (t *txn) recordMacNeeds(k *taskRecord, needs []string) error {
+ mac := macTags(needs)
+ if k.MacNeeds != "" || len(mac) == 0 {
+ return nil
}
- err := t.db.Model(&stepRecord{}).Where("task_id = ? AND specialist = ? AND coalesce(publication, '') <> ''", k.ID, wire.SpecialistEngineering).Count(&n).Error
- return n > 0, err
+ k.MacNeeds = encodeList(mac)
+ return t.db.Model(&taskRecord{}).Where("id = ? AND coalesce(mac_needs, '') = ''", k.ID).Update("mac_needs", k.MacNeeds).Error
}
// macTags are needs without claude: what makes a runner a Mac for them.
@@ -608,6 +605,8 @@ func (t *txn) place(k *taskRecord, s *stepRecord) (placed bool, err error) {
type engineeringPlacement struct {
runner, placement, waitFor string
needs []string
+ // want: everything the task's Engineering needs (whoever takes it).
+ want []string
}
// placeEngineering places Engineering's attempt (placeEngineering's
@@ -622,6 +621,11 @@ func (t *txn) placeEngineering(k *taskRecord, s *stepRecord, primary string) (bo
if err != nil {
return false, err
}
+ // Mac work from now on, whatever the catalog, a pin or a removal
+ // later says.
+ if err := t.recordMacNeeds(k, d.want); err != nil {
+ return false, err
+ }
if s.State == wire.StepQueued && s.Reason == reasonRunnerOffline {
// The wait for an offline Mac is over or starts again.
s.Reason = ""
@@ -669,6 +673,12 @@ func (t *txn) engineeringPlace(k taskRecord, s stepRecord, primary string) (engi
if err != nil {
return engineeringPlacement{}, err
}
+ d, err := t.engineeringDecide(k, s, primary, needs)
+ d.want = needs
+ return d, err
+}
+
+func (t *txn) engineeringDecide(k taskRecord, s stepRecord, primary string, needs []string) (engineeringPlacement, error) {
if len(needs) == 0 && (k.EngineeringRunner == "" || k.EngineeringRunner == primary) {
return engineeringPlacement{runner: primary}, nil
}
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go
index 885fcbe9..fdba7770 100644
--- a/internal/equipo/chat/tasks.go
+++ b/internal/equipo/chat/tasks.go
@@ -94,6 +94,11 @@ type taskRecord struct {
// rounds, retries and republishes go there, so two runners never
// touch one branch.
EngineeringRunner string
+ // MacNeeds are the Mac tags (JSON) the task's Engineering was first
+ // found to need: written once by placement (recordMacNeeds), never
+ // cleared and never in saveTask, so no later catalog, pin or
+ // removal makes it Linux work (migration 0120).
+ MacNeeds string
// Merge authority: MergeHold is the coordinator's hold (it can only
// stop Equipo merging on its own); MergeVerified, that the merge SHA
// came from the hub's own answer with the candidate as second parent
diff --git a/internal/equipo/migrations/0120_mac_engineering.sql b/internal/equipo/migrations/0120_mac_engineering.sql
index b1c76f1a..7e851dc7 100644
--- a/internal/equipo/migrations/0120_mac_engineering.sql
+++ b/internal/equipo/migrations/0120_mac_engineering.sql
@@ -1,6 +1,6 @@
-- Mac Engineering (slice F, protocol 37). Additive only: an existing row
-- reads as before (a checks transfer, no Xcode access, no outcome, no
--- kept session, no frozen question pin).
+-- kept session, no frozen question pin, and a task records no Mac need).
ALTER TABLE runner_transfers ADD COLUMN kind text;
ALTER TABLE runner_transfers ADD COLUMN old_base_sha text;
ALTER TABLE chat_steps ADD COLUMN xcode_access text;
@@ -12,3 +12,6 @@ ALTER TABLE chat_questions ADD COLUMN eng_session text;
ALTER TABLE chat_questions ADD COLUMN runner_id text;
ALTER TABLE chat_questions ADD COLUMN base_sha text;
ALTER TABLE chat_questions ADD COLUMN candidate_sha text;
+-- The Mac tags a task's Engineering was first found to need (JSON list),
+-- written once at placement and never cleared.
+ALTER TABLE chat_tasks ADD COLUMN mac_needs text;
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql
index a6df859d..46877f94 100644
--- a/internal/equipo/migrations/schema.sql
+++ b/internal/equipo/migrations/schema.sql
@@ -853,3 +853,4 @@ ALTER TABLE chat_questions ADD COLUMN eng_session text;
ALTER TABLE chat_questions ADD COLUMN runner_id text;
ALTER TABLE chat_questions ADD COLUMN base_sha text;
ALTER TABLE chat_questions ADD COLUMN candidate_sha text;
+ALTER TABLE chat_tasks ADD COLUMN mac_needs text;
diff --git a/internal/equipo/migrations_mac_engineering_test.go b/internal/equipo/migrations_mac_engineering_test.go
index 10cd9684..4daf3fff 100644
--- a/internal/equipo/migrations_mac_engineering_test.go
+++ b/internal/equipo/migrations_mac_engineering_test.go
@@ -130,6 +130,7 @@ func TestMacEngineeringMigrationKeepsOpenTransfersAndQuestions(t *testing.T) {
"runner_transfers": {"kind", "old_base_sha"},
"chat_steps": {"xcode_access", "outcome_phase", "session_id"},
"chat_questions": {"eng_attempt", "eng_account", "eng_session", "runner_id", "base_sha", "candidate_sha"},
+ "chat_tasks": {"mac_needs"},
}
for table, cols := range added {
was, now := columns(before, table), columns(w, table)
diff --git a/internal/thintest/mac_engineering_contract_test.go b/internal/thintest/mac_engineering_contract_test.go
index 925c26df..f55c014a 100644
--- a/internal/thintest/mac_engineering_contract_test.go
+++ b/internal/thintest/mac_engineering_contract_test.go
@@ -967,8 +967,9 @@ func TestContractPrepareBaseAfterPrimaryReplaced(t *testing.T) {
}
token := r.inst.EnrolRunner(t).Token
h := primaryHello(0)
- h.Protocol, h.Label = wire.ProtocolChangeDiffs, "docs-t2"
- h.Catalog[0].NeedsMacOS = true
+ // A Linux replacement whose catalog does not name the repository: the
+ // task's Mac need outlives that.
+ h.Protocol, h.Label, h.Catalog = wire.ProtocolChangeDiffs, "docs-t2", []wire.RepoInfo{}
p35, err := DialRunnerHello(r.ctx, r.inst.URL, token, h)
if err != nil || p35.Welcome.Role != wire.RolePrimary {
t.Fatalf("replacement %+v %v", p35, err)
@@ -1015,6 +1016,9 @@ func TestContractPrepareBaseAfterPrimaryReplaced(t *testing.T) {
if d := body.(*wire.DispatchCommand); d.Attempt != 2 || d.BaseSHA != sha(2) {
t.Fatalf("dispatch %+v", d)
}
+ if n := r.mailboxHas(p37.Welcome.RunnerID, `"specialist":"engineering"`); n != 0 {
+ t.Fatalf("%d engineering dispatches to the Linux replacement", n)
+ }
}
// ackedBy waits until runner's commands of kind are all acked.
@@ -1084,3 +1088,124 @@ func TestContractMacEngineeringPinnedBeforeCommit(t *testing.T) {
}
r.primary.none(wire.FrameDispatch, 100*time.Millisecond)
}
+
+// macPrimaryHello is the rig's primary become a Mac: every tag Mac
+// Engineering needs.
+func macPrimaryHello() wire.Hello {
+ h := primaryHello(0)
+ h.Protocol, h.Platform = wire.ProtocolMacEngineering, &wire.Platform{OS: "darwin", Arch: "arm64"}
+ h.Capabilities.Tags = []string{wire.TagMacOS, wire.TagXcode, wire.TagIOSSimulator, wire.TagClaude}
+ h.Catalog[0].NeedsMacOS = true
+ return h
+}
+
+// macNeedOutlivesPins: the task's Engineering, quarantined on Mac A
+// (step at attempt), re-pins on Recover and Retry to a primary that is a
+// Mac; that primary is removed too, and the Linux primary that replaces
+// it has catalog (one without the repository, or naming it as not
+// needing a Mac). Retry still waits for a Mac:
+// the task's Mac need is its own record, not its current pin or its
+// publications.
+func (r *runnersRig) macNeedOutlivesPins(task, step string, attempt int64, a *peer, catalog []wire.RepoInfo) {
+ r.t.Helper()
+ r.remove(a.fr.Welcome.RunnerID, true)
+ if _, err := r.client.RecoverTask(r.ctx, task); err != nil {
+ r.t.Fatal(err)
+ }
+ r.primary.heartbeat(macPrimaryHello())
+ if acc, err := r.client.RetryTask(r.ctx, task); err != nil || acc.Attempt != attempt+1 {
+ r.t.Fatalf("retry %+v %v", acc, err)
+ }
+ d := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand)
+ if d.StepID != step || d.Attempt != attempt+1 || d.Specialist != wire.SpecialistEngineering {
+ r.t.Fatalf("on the Mac primary %+v", d)
+ }
+ if k := r.task(task); k.EngineeringRunner != r.primary.fr.Welcome.RunnerID {
+ r.t.Fatalf("not re-pinned to the Mac primary: %q", k.EngineeringRunner)
+ }
+ if !r.primary.lease(d.StepID, d.Attempt) {
+ r.t.Fatal("start refused")
+ }
+ r.remove(r.primary.fr.Welcome.RunnerID, true)
+ token := r.inst.EnrolRunner(r.t).Token
+ h := primaryHello(0)
+ h.Protocol, h.Label, h.Catalog = wire.ProtocolMacEngineering, "docs-t2", catalog
+ np, err := DialRunnerHello(r.ctx, r.inst.URL, token, h)
+ if err != nil || np.Welcome.Role != wire.RolePrimary {
+ r.t.Fatalf("replacement %+v %v", np, err)
+ }
+ r.t.Cleanup(np.Close)
+ if _, err := r.client.RecoverTask(r.ctx, task); err != nil {
+ r.t.Fatal(err)
+ }
+ if acc, err := r.client.RetryTask(r.ctx, task); err != nil || acc.Attempt != attempt+2 {
+ r.t.Fatalf("second retry %+v %v", acc, err)
+ }
+ if s := r.newestEngineering(task); s.State != wire.StepQueued || s.Placement != wire.PlacementMac || s.RunnerID != "" {
+ r.t.Fatalf("after the Linux replacement: %+v", s)
+ }
+ time.Sleep(100 * time.Millisecond)
+ if n := r.mailboxHas(np.Welcome.RunnerID, `"specialist":"engineering"`); n != 0 {
+ r.t.Fatalf("%d engineering dispatches to the Linux primary", n)
+ }
+}
+
+// Before anything was published: Mac A removed while its first attempt
+// may run, then the Mac primary that took it over.
+func TestContractMacNeedOutlivesPinsBeforePublication(t *testing.T) {
+ r := newMacRig(t)
+ a := r.newMacEngineer("Mac A", wire.EngineeringReady)
+ task, d := r.macDispatch(a, "iOS twice removed", sha(1))
+ if !a.lease(d.StepID, d.Attempt) {
+ t.Fatal("start refused")
+ }
+ r.macNeedOutlivesPins(task, d.StepID, d.Attempt, a, []wire.RepoInfo{})
+}
+
+// After a published round: Mac A removed during the fix round, then the
+// Mac primary that took it over.
+func TestContractMacNeedOutlivesPinsAfterPublication(t *testing.T) {
+ r := newMacRig(t)
+ a := r.newMacEngineer("Mac A", wire.EngineeringReady)
+ c1 := sha(0xc1)
+ task, _ := r.macCandidate(a, "iOS fixed, twice removed", sha(1), c1)
+ cw, c := r.macChecked(task, a)
+ cw.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: c.StepID, Attempt: c.Attempt, State: wire.StepDone, CandidateSHA: c1, Checks: wire.ChecksFailed, Gate: "xcodebuild test", ExitCode: exit(65), Output: "FAILED", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}})
+ _, body := a.expect(wire.FrameDispatch)
+ fix := body.(*wire.DispatchCommand)
+ r.engineeringTransfer(a, fix)
+ if !a.lease(fix.StepID, fix.Attempt) {
+ t.Fatal("fix round refused")
+ }
+ // The replacement's catalog names the repository, as not needing a
+ // Mac: a catalog only adds needs.
+ r.macNeedOutlivesPins(task, fix.StepID, fix.Attempt, a, primaryHello(0).Catalog)
+}
+
+// A task whose Engineering never needed a Mac records no Mac need, and
+// stays on the Linux primary when the catalog later omits its repository.
+func TestContractNeverMacTaskUnaffected(t *testing.T) {
+ r := newMacRig(t)
+ r.newMacEngineer("Mac A", wire.EngineeringReady)
+ h := primaryHello(0)
+ h.Protocol = wire.ProtocolMacEngineering
+ r.primary.heartbeat(h)
+ task := r.macTask("Linux fix")
+ d := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand)
+ if d.Specialist != wire.SpecialistEngineering || d.RunnerID != r.primary.fr.Welcome.RunnerID {
+ t.Fatalf("engineering %+v", d)
+ }
+ var needs string
+ if err := r.inst.DB.Writer().QueryRow("SELECT coalesce(mac_needs, '') FROM chat_tasks WHERE id = ?", task).Scan(&needs); err != nil || needs != "" {
+ t.Fatalf("mac_needs %q %v", needs, err)
+ }
+ r.primary.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true, TerminationKind: wire.TerminationNamespace, Findings: []wire.Finding{}})
+ h.Catalog = []wire.RepoInfo{}
+ r.primary.heartbeat(h)
+ if acc, err := r.client.RetryTask(r.ctx, task); err != nil || acc.Attempt != 2 {
+ t.Fatalf("retry %+v %v", acc, err)
+ }
+ if d := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand); d.Specialist != wire.SpecialistEngineering || d.Attempt != 2 || d.RunnerID != r.primary.fr.Welcome.RunnerID {
+ t.Fatalf("retry %+v", d)
+ }
+}