oficina / equipo Public

fix: keep the selected families for started bug jobs

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 2259ef808ee8e3aba76f08b7a5925a13f13b5ef5 parent 9bc8d81
3 files changed, +38 −4
  • internal/equipo/task_wait.go +3 −0
  • internal/equipotest/final_wait_test.go +3 −4
  • internal/equipotest/residual_pair_test.go +32 −0
diff --git a/internal/equipo/task_wait.go b/internal/equipo/task_wait.go
index 6b4d924b..f07b0c7a 100644
--- a/internal/equipo/task_wait.go
+++ b/internal/equipo/task_wait.go
@@ -72,6 +72,9 @@ func (s *Store) bugPair(tx *gorm.DB, person string, project int64) (Selection, S
}
func (s *Store) refreshPendingPair(tx *gorm.DB, task Task, out *taskOutbox) error {
+ if task.JobID != 0 {
+ return nil
+ }
project, err := bugAuthority(tx, Actor{Address: task.Requester}, task.ProjectID)
if err != nil {
return err
diff --git a/internal/equipotest/final_wait_test.go b/internal/equipotest/final_wait_test.go
index e22609e4..b52c6054 100644
--- a/internal/equipotest/final_wait_test.go
+++ b/internal/equipotest/final_wait_test.go
@@ -85,12 +85,11 @@ func TestPollSkipsStaleAssignment(t *testing.T) {
t.Fatal("stale assignment has no wait", wait)
}
executionMust(t, f.x.Sync(connectionContext))
- retryCtx, retryCancel := context.WithTimeout(connectionContext, time.Second)
+ retryCtx, retryCancel := context.WithTimeout(connectionContext, 250*time.Millisecond)
defer retryCancel()
aa, err := f.x.Poll(retryCtx, f.principal, "")
- executionMust(t, err)
- if len(aa) != 1 || aa[0].ID == f.a.ID {
- t.Fatal("authorized fenced pending assignment not replaced", aa)
+ if !errors.Is(err, context.DeadlineExceeded) || len(aa) != 0 {
+ t.Fatal("started job silently refreshed stale selection", aa, err)
}
}
diff --git a/internal/equipotest/residual_pair_test.go b/internal/equipotest/residual_pair_test.go
new file mode 100644
index 00000000..df55e648
--- /dev/null
+++ b/internal/equipotest/residual_pair_test.go
@@ -0,0 +1,32 @@
+package equipotest
+
+import (
+ "amadan.net/oficina/equipo/internal/equipo"
+ "encoding/json"
+ "testing"
+)
+
+func TestStartedBugKeepsPairAfterRepin(t *testing.T) {
+ f := runnerFixtureNew(t, false)
+ var beforeEng, beforeReview string
+ executionMust(t, f.d.Writer().QueryRow("SELECT engineering,review FROM task_outboxes WHERE task_id=?", f.a.TaskID).Scan(&beforeEng, &beforeReview))
+ var review equipo.Selection
+ executionMust(t, json.Unmarshal([]byte(beforeReview), &review))
+ // Engineering has already run when the task is between steps.
+ mustSQL(t, f.d, "UPDATE steps SET state='succeeded' WHERE job_id=(SELECT job_id FROM tasks WHERE id=?) AND key IN ('reproduce','implement')", f.a.TaskID)
+ mustSQL(t, f.d, "UPDATE runner_assignments SET state='contained' WHERE task_id=?", f.a.TaskID)
+ executionMust(t, f.s.SaveConnectionChoice(connectionContext, ownerActor, equipo.ConnectionChoice{ProjectID: f.project.ID, Revision: 1, ConnectionIDs: []string{f.ids["claude"], f.ids["codex"]}, PinnedID: review.ConnectionID}))
+ executionMust(t, f.x.Sync(connectionContext))
+ var eng, rev string
+ executionMust(t, f.d.Writer().QueryRow("SELECT engineering,review FROM task_outboxes WHERE task_id=?", f.a.TaskID).Scan(&eng, &rev))
+ if eng != beforeEng || rev != beforeReview {
+ t.Fatalf("repin changed in-flight pair: engineering=%s review=%s", eng, rev)
+ }
+ var assigned string
+ executionMust(t, f.d.Writer().QueryRow("SELECT selection FROM runner_assignments WHERE task_id=? AND step_key='review' AND state='pending'", f.a.TaskID).Scan(&assigned))
+ var selection equipo.Selection
+ executionMust(t, json.Unmarshal([]byte(assigned), &selection))
+ if selection.Family != review.Family {
+ t.Fatalf("review family changed: %s -> %s", review.Family, selection.Family)
+ }
+}