oficina / equipo Public

fix: let owners reconcile stopped legacy runners after migration

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev faaf477ea82297fc0a21563922c29fa83fa2090c parent 1e54a41
13 files changed, +460 −14
  • docs/live-gate.md +5 −3
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md +167 −0
  • internal/equipo/app.go +1 −0
  • internal/equipo/copy.go +5 −1
  • internal/equipo/migrations/0019_direct_reconcile.sql +18 −0
  • internal/equipo/old_runner.go +80 −0
  • internal/equipo/task_handlers.go +19 −0
  • internal/equipo/task_views.go +2 −0
  • internal/equipo/team/actions.go +18 −0
  • internal/equipo/templates/task.html +1 −0
  • internal/equipotest/direct_cutover_test.go +2 −2
  • internal/equipotest/direct_migration_exit_test.go +134 −0
  • internal/equipotest/execution_schema_test.go +8 −8
diff --git a/docs/live-gate.md b/docs/live-gate.md
index b426fe3d..7a5d6c43 100644
--- a/docs/live-gate.md
+++ b/docs/live-gate.md
@@ -42,9 +42,11 @@ launch evidence.
## Prepare the accounts and bounded inputs
1. Review the branch and pending copy with Paul. Before upgrading an existing
- instance, stop its runner and reconcile every unfinished attempt. Migration
- 0018 retains evidence and charges while fencing unfinished work. Restarting
- does not prove old processes have stopped.
+ instance, stop its old runner and every process it launched. Migrations 0018 and 0019
+ retain evidence and charges while fencing unfinished work. Tasks with claimed
+ old work wait for an owner to use **Old runner stopped** on the task page.
+ Unclaimed tasks return to setup selection, and cancellation requests remain
+ in effect. Confirm the processes have stopped before using the action.
2. Install the pinned dependencies: Claude 2.1.312, Codex 0.165.0, the matching
`codex-code-mode-host`, and bubblewrap 0.11.0. The Go namespace helper is part
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
index e1dfbb8e..ee1bddb6 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
@@ -25259,3 +25259,170 @@ FAIL amadan.net/oficina/equipo/internal/runner 0.042s
FAIL
```
+
+## C-I1
+
+Added additive migration 0019. Only tasks with claimed v1 work or pending containment keep the reconcile wait; other tasks return to setup selection. Recover cancellation requests from their durable task.cancel audits. Added an owner-only scriptless Old runner stopped form. The store rechecks current membership in the same transaction, contains old attempts through Core.Contain, contains v1 assignments, completes cancellation or resumes a fully contained job, updates the outbox and appends the audit. Audit failures roll back containment. Tests seed pre-0018 rows, migrate them and walk each exit. Updated live-gate step 1. Pending copy: task.old_runner_stopped = Old runner stopped; task.old_runner_stopped.help = Confirm that the old runner and all its processes have stopped before continuing this task.
+
+Interpretations: 0018 may already have been applied, so it is unchanged. An unresolved external action remains waiting even after physical containment; stopping a process does not prove the external outcome. Cancel intent erased by 0018 is reconstructed from its audit event. Red command is the same named migrated-task test as green.
+
+### C-I1-red
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (2.11s)
+ --- FAIL: TestMigratedTaskWaitExit/unclaimed (0.30s)
+ direct_migration_exit_test.go:51: unclaimed task trapped
+ --- FAIL: TestMigratedTaskWaitExit/unclaimed-cancel (0.28s)
+ direct_migration_exit_test.go:51: unclaimed task trapped
+ --- FAIL: TestMigratedTaskWaitExit/claimed (0.31s)
+ direct_migration_exit_test.go:58: The information is unavailable. Try again in a minute.
+ --- FAIL: TestMigratedTaskWaitExit/claimed-cancel (0.31s)
+ direct_migration_exit_test.go:58: The information is unavailable. Try again in a minute.
+FAIL
+rastrillo-budget/v1 ran 2.114s
+FAIL amadan.net/oficina/equipo/internal/equipotest 2.154s
+FAIL
+```
+
+### C-I1-green
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/equipotest 1.927s
+```
+
+### C-I1-mut-owner
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (1.93s)
+ --- FAIL: TestMigratedTaskWaitExit/member (0.29s)
+ direct_migration_exit_test.go:107: unauthorized or unaudited containment
+FAIL
+rastrillo-budget/v1 ran 1.928s
+FAIL amadan.net/oficina/equipo/internal/equipotest 1.977s
+FAIL
+```
+
+### C-I1-mut-audit
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (1.93s)
+ --- FAIL: TestMigratedTaskWaitExit/claimed (0.28s)
+ direct_migration_exit_test.go:123: missing audit
+ --- FAIL: TestMigratedTaskWaitExit/claimed-cancel (0.29s)
+ direct_migration_exit_test.go:123: missing audit
+ --- FAIL: TestMigratedTaskWaitExit/audit-failure (0.28s)
+ direct_migration_exit_test.go:107: unauthorized or unaudited containment
+FAIL
+rastrillo-budget/v1 ran 1.935s
+FAIL amadan.net/oficina/equipo/internal/equipotest 1.980s
+FAIL
+```
+
+### C-I1-mut-contain
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (1.87s)
+ --- FAIL: TestMigratedTaskWaitExit/claimed (0.27s)
+ direct_migration_exit_test.go:114: team: state: containment pending
+ --- FAIL: TestMigratedTaskWaitExit/claimed-cancel (0.28s)
+ direct_migration_exit_test.go:120: v1 work not contained
+FAIL
+rastrillo-budget/v1 ran 1.872s
+FAIL amadan.net/oficina/equipo/internal/equipotest 1.919s
+FAIL
+```
+
+### C-I1-mut-assignments
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (1.94s)
+ --- FAIL: TestMigratedTaskWaitExit/claimed (0.30s)
+ direct_migration_exit_test.go:120: v1 work not contained
+ --- FAIL: TestMigratedTaskWaitExit/claimed-cancel (0.28s)
+ direct_migration_exit_test.go:117: task still trapped cancel_requested
+FAIL
+rastrillo-budget/v1 ran 1.939s
+FAIL amadan.net/oficina/equipo/internal/equipotest 1.986s
+FAIL
+```
+
+### C-I1-mut-resume
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (1.91s)
+ --- FAIL: TestMigratedTaskWaitExit/claimed (0.29s)
+ direct_migration_exit_test.go:129: job not resumed waiting
+FAIL
+rastrillo-budget/v1 ran 1.91s
+FAIL amadan.net/oficina/equipo/internal/equipotest 1.956s
+FAIL
+```
+
+### C-I1-mut-cancel
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (1.90s)
+ --- FAIL: TestMigratedTaskWaitExit/unclaimed-cancel (0.26s)
+ direct_migration_exit_test.go:88: cancel request lost waiting
+ --- FAIL: TestMigratedTaskWaitExit/claimed-cancel (0.28s)
+ direct_migration_exit_test.go:117: task still trapped waiting task.wait.setup
+FAIL
+rastrillo-budget/v1 ran 1.899s
+FAIL amadan.net/oficina/equipo/internal/equipotest 1.947s
+FAIL
+```
+
+### C-I1-mut-unclaimed
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^TestMigratedTaskWaitExit$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestMigratedTaskWaitExit (1.91s)
+ --- FAIL: TestMigratedTaskWaitExit/unclaimed (0.25s)
+ direct_migration_exit_test.go:85: unclaimed task trapped
+FAIL
+rastrillo-budget/v1 ran 1.912s
+FAIL amadan.net/oficina/equipo/internal/equipotest 1.958s
+FAIL
+```
+
+### C-I1-migration-green
+
+`CGO_ENABLED=0 go test ./internal/equipotest -run '^Test(MigratedTaskWaitExit|DirectCutoverPreservesHistory|ExecutionSchemaParity|CancelTaskFencesBeforeAcknowledgement)$' -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/equipotest 4.983s
+```
+
diff --git a/internal/equipo/app.go b/internal/equipo/app.go
index f782cc99..cb56e68e 100644
--- a/internal/equipo/app.go
+++ b/internal/equipo/app.go
@@ -184,6 +184,7 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg
r.Get("/runners/enrol", a.enrolmentPage)
r.Post("/tasks", a.createBug)
r.Post("/tasks/{id}/cancel", a.cancelTask)
+ r.Post("/tasks/{id}/old-runner-stopped", a.oldRunnerStopped)
r.Post("/tasks/{id}/questions/{question}/answer", a.answerQuestion)
r.Post("/runners/enrol", a.approveEnrolment)
r.Post("/runners/{id}/revoke", a.revokeRunner)
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index ed477556..8db84ab4 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -251,7 +251,11 @@ var runnerDraftCopy = map[string]string{
// COPY REVIEW REQUIRED: task.answer
"task.answer": "Answer question",
// COPY REVIEW REQUIRED: task.cancel
- "task.cancel": "Cancel task",
+ // Pending copy review: task.old_runner_stopped.
+ "task.old_runner_stopped": "Old runner stopped",
+ // Pending copy review: task.old_runner_stopped.help.
+ "task.old_runner_stopped.help": "Confirm that the old runner and all its processes have stopped before continuing this task.",
+ "task.cancel": "Cancel task",
// COPY REVIEW REQUIRED: task.merge
"task.merge": "Acknowledge merge",
// COPY REVIEW REQUIRED: task.merge.reference
diff --git a/internal/equipo/migrations/0019_direct_reconcile.sql b/internal/equipo/migrations/0019_direct_reconcile.sql
new file mode 100644
index 00000000..fb38c1e6
--- /dev/null
+++ b/internal/equipo/migrations/0019_direct_reconcile.sql
@@ -0,0 +1,18 @@
+UPDATE tasks SET state='cancel_requested'
+ WHERE wait_code='task.wait.reconcile' AND EXISTS (
+ SELECT 1 FROM audit_events a WHERE a.record_id=tasks.id AND a.kind='task.cancel');
+UPDATE tasks SET state=CASE WHEN state='cancel_requested' THEN 'cancelled' ELSE 'waiting' END,
+ wait_code=CASE WHEN state='cancel_requested' THEN '' ELSE 'task.wait.setup' END, revision=revision+1
+ WHERE wait_code='task.wait.reconcile'
+ AND NOT EXISTS (SELECT 1 FROM runner_assignments a WHERE a.task_id=tasks.id AND a.protocol_version=1 AND a.claim_request!='' AND a.state!='contained')
+ AND NOT EXISTS (SELECT 1 FROM attempts a WHERE a.job_id=tasks.job_id AND a.containment='pending');
+UPDATE jobs SET state=CASE WHEN EXISTS (SELECT 1 FROM tasks t WHERE t.job_id=jobs.id AND t.state='cancelled') THEN 'cancelled' ELSE 'running' END,
+ wait='',revision=revision+1
+ WHERE state='waiting' AND wait='uncertain_external_outcome'
+ AND EXISTS (SELECT 1 FROM tasks t WHERE t.job_id=jobs.id AND t.wait_code!='task.wait.reconcile')
+ AND NOT EXISTS (SELECT 1 FROM attempts a WHERE a.job_id=jobs.id AND a.containment='pending')
+ AND NOT EXISTS (SELECT 1 FROM actions a WHERE a.job_id=jobs.id AND a.state IN ('dispatching','uncertain'));
+UPDATE task_outboxes SET state=CASE WHEN EXISTS(SELECT 1 FROM tasks t WHERE t.id=task_outboxes.task_id AND t.job_id!=0) THEN 'done' ELSE 'prepare' END
+ WHERE state='reconcile' AND EXISTS (SELECT 1 FROM tasks t WHERE t.id=task_outboxes.task_id AND t.wait_code!='task.wait.reconcile');
+INSERT INTO audit_events(actor,kind,record_id,at)
+ VALUES('system','system.migration.direct_reconcile','equipo/0019_direct_reconcile',CURRENT_TIMESTAMP);
diff --git a/internal/equipo/old_runner.go b/internal/equipo/old_runner.go
new file mode 100644
index 00000000..da19c76f
--- /dev/null
+++ b/internal/equipo/old_runner.go
@@ -0,0 +1,80 @@
+package equipo
+
+import (
+ "amadan.net/oficina/equipo/internal/equipo/team"
+ "context"
+ "gorm.io/gorm"
+)
+
+func (s *Store) OldRunnerStopped(ctx context.Context, actor Actor, id string) error {
+ if s.execution == nil {
+ return ErrUnavailable
+ }
+ return s.execution.atomic(ctx, func(ctx context.Context, tx *gorm.DB) error {
+ member, err := currentRunnerMember(tx, actor.Address)
+ if err != nil {
+ return err
+ }
+ if member.Role != RoleOwner {
+ return ErrForbidden
+ }
+ var task Task
+ if err = tx.First(&task, "id=?", id).Error; err != nil {
+ return storeError(err)
+ }
+ if task.WaitCode != "task.wait.reconcile" {
+ return ErrConflict
+ }
+ if task.JobID != 0 {
+ scope := Scope{Account: team.AccountID(task.TeamID), Job: task.JobID}
+ attempts, err := s.execution.Core.Attempts(ctx, scope)
+ if err != nil {
+ return err
+ }
+ for _, attempt := range attempts {
+ var direct int64
+ if err = tx.Model(&runnerAssignment{}).Where("task_id=? AND attempt_id=? AND protocol_version!=1", id, attempt.ID).Count(&direct).Error; err != nil {
+ return storeError(err)
+ }
+ if direct != 0 && attempt.Containment != team.ContainmentContained {
+ return ErrConflict
+ }
+ if direct == 0 {
+ if err = s.execution.Core.Contain(ctx, scope, attempt.ID, actor.Address); err != nil {
+ return err
+ }
+ }
+ }
+ if task.State == "cancel_requested" {
+ if _, err = s.execution.Core.Cancel(ctx, scope, actor.Address, "person_cancelled"); err != nil {
+ return err
+ }
+ } else {
+ if err = s.execution.Core.ResumeContained(ctx, scope); err != nil {
+ return err
+ }
+ }
+ }
+ if err = tx.Model(&runnerAssignment{}).Where("task_id=? AND protocol_version=1", id).Select("State").Updates(&runnerAssignment{State: "contained"}).Error; err != nil {
+ return storeError(err)
+ }
+ state, wait := "waiting", "task.wait.setup"
+ if task.State == "cancel_requested" {
+ state, wait = "cancel_requested", ""
+ }
+ if err = tx.Model(&Task{}).Where("id=?", id).Select("State", "WaitCode", "Revision").Updates(&Task{State: state, WaitCode: wait, Revision: task.Revision + 1}).Error; err != nil {
+ return storeError(err)
+ }
+ out := "prepare"
+ if task.JobID != 0 {
+ out = "done"
+ }
+ if err = tx.Model(&taskOutbox{}).Where("task_id=?", id).Select("State").Updates(&taskOutbox{State: out}).Error; err != nil {
+ return storeError(err)
+ }
+ if err = finishTaskCancellation(tx, id); err != nil {
+ return err
+ }
+ return appendAudit(tx, actor, "task.old_runner_stopped", id)
+ })
+}
diff --git a/internal/equipo/task_handlers.go b/internal/equipo/task_handlers.go
index 29b67141..c724ebc6 100644
--- a/internal/equipo/task_handlers.go
+++ b/internal/equipo/task_handlers.go
@@ -56,3 +56,22 @@ func (a *application) cancelTask(w http.ResponseWriter, r *http.Request) {
}
http.Redirect(w, r, "/tasks/"+id, http.StatusSeeOther)
}
+
+func (a *application) oldRunnerStopped(w http.ResponseWriter, r *http.Request) {
+ r.Body = http.MaxBytesReader(w, r.Body, 8192)
+ if r.ParseForm() != nil || len(r.URL.Query()) != 0 || len(r.PostForm) != 0 {
+ a.failure(w, r, ErrInvalid)
+ return
+ }
+ actor, ok := auth.From(r)
+ if !ok {
+ a.failure(w, r, ErrForbidden)
+ return
+ }
+ id := chi.URLParam(r, "id")
+ if err := a.store.OldRunnerStopped(r.Context(), Actor{Address: actor.Address}, id); err != nil {
+ a.failure(w, r, err)
+ return
+ }
+ http.Redirect(w, r, "/tasks/"+id, http.StatusSeeOther)
+}
diff --git a/internal/equipo/task_views.go b/internal/equipo/task_views.go
index 92adcd83..a6e280a5 100644
--- a/internal/equipo/task_views.go
+++ b/internal/equipo/task_views.go
@@ -41,6 +41,7 @@ type TaskEvidence struct {
Unconfined bool
}
type TaskViewData struct {
+ CanStopOldRunner bool
Isolation team.IsolationSnapshot
Task Task
Project Project
@@ -190,6 +191,7 @@ func (s *Store) taskViewAt(tx *gorm.DB, actor Actor, task Task) (TaskViewData, e
if err != nil {
return v, err
}
+ v.CanStopOldRunner = member.Role == RoleOwner && task.WaitCode == "task.wait.reconcile"
v.CanCancel = member.Address == task.Requester || member.Role == RoleOwner
var outbox taskOutbox
if err = tx.First(&outbox, "task_id=?", task.ID).Error; err != nil {
diff --git a/internal/equipo/team/actions.go b/internal/equipo/team/actions.go
index 0e1f97ec..d8119afb 100644
--- a/internal/equipo/team/actions.go
+++ b/internal/equipo/team/actions.go
@@ -710,3 +710,21 @@ func unresolvedTurn(ctx context.Context, tx *sql.Tx, job JobID, except ActionID)
func notDispatchedReceipt(d Dispatch) Receipt {
return Receipt{ID: "not-dispatched-" + strconv.FormatInt(int64(d.Action), 10) + "-" + d.Hash, Outcome: OutcomeFailure, Usage: &Usage{}}
}
+
+// ResumeContained leaves unresolved external outcomes waiting for reconciliation.
+func (s *Store) ResumeContained(ctx context.Context, scope Scope) error {
+ return s.tx(ctx, func(tx *sql.Tx) error {
+ j, err := loadJob(ctx, tx, scope)
+ if err != nil {
+ return err
+ }
+ var pending int
+ if err = tx.QueryRowContext(ctx, "SELECT count(*) FROM attempts WHERE job_id=? AND containment='pending'", j.ID).Scan(&pending); err != nil {
+ return err
+ }
+ if pending != 0 {
+ return fail(CodeState, "containment pending")
+ }
+ return resumeIfResolved(ctx, tx, j, s.clock.Now())
+ })
+}
diff --git a/internal/equipo/templates/task.html b/internal/equipo/templates/task.html
index 03ca4f7d..9ed49714 100644
--- a/internal/equipo/templates/task.html
+++ b/internal/equipo/templates/task.html
@@ -2,6 +2,7 @@
{{define "region:activity"}}<div id="activity" {{.Live.Attrs .Topic}}>{{with .TaskView}}
{{template "task-card" .}}
<p>{{.Task.ReviewRef}}</p><p>{{.Task.MergeOwner}}</p>{{if .MergeReference}}<p>{{.MergeReference}}</p>{{end}}
+{{if .CanStopOldRunner}}<form method="post" action="/tasks/{{.Task.ID}}/old-runner-stopped"><p>{{copy "task.old_runner_stopped.help"}}</p><button rst-btn type="submit">{{copy "task.old_runner_stopped"}}</button></form>{{end}}
{{if .CanCancel}}<form method="post" action="/tasks/{{.Task.ID}}/cancel"><button rst-btn type="submit">{{copy "task.cancel"}}</button></form>{{end}}
{{if .CanMerge}}<a rst-btn href="/tasks/{{.Task.ID}}/merge">{{copy "task.merge"}}</a>{{end}}
<h2>{{copy "task.selected"}}</h2>{{range .Steps}}<p>{{copy (printf "step.%s" .Key)}}: {{.Model}} {{.Account}}</p>{{if .Actual}}<p>{{copy "task.actual"}}: {{.Actual}}</p>{{end}}{{if .AllowanceKnown}}<p>{{copy "usage.allowance"}}: {{.AllowanceRemaining}}</p>{{else}}{{if .Model}}<p>{{copy "usage.allowance_unknown"}}</p>{{end}}{{end}}{{template "isolation-history" .Isolation}}{{end}}
diff --git a/internal/equipotest/direct_cutover_test.go b/internal/equipotest/direct_cutover_test.go
index 6ec6f27e..bee78116 100644
--- a/internal/equipotest/direct_cutover_test.go
+++ b/internal/equipotest/direct_cutover_test.go
@@ -82,7 +82,7 @@ func TestDirectCutoverPreservesHistory(t *testing.T) {
defer d.Close()
before := &migrate.Set{}
for _, m := range equipo.BootSchema.All() {
- if m.ID != "equipo/0018_direct_launch" {
+ if m.ID != "equipo/0019_direct_reconcile" && m.ID != "equipo/0018_direct_launch" {
before.Add(m)
}
}
@@ -118,7 +118,7 @@ func TestDirectCutoverPreservesHistory(t *testing.T) {
return
}
executionMust(t, err)
- if len(result.Applied) != 1 || result.Applied[0] != "equipo/0018_direct_launch" {
+ if len(result.Applied) != 2 || result.Applied[0] != "equipo/0018_direct_launch" {
t.Fatalf("missing cutover: %v", result.Applied)
}
for _, table := range []string{"supervised_trials", "isolation_acknowledgements"} {
diff --git a/internal/equipotest/direct_migration_exit_test.go b/internal/equipotest/direct_migration_exit_test.go
new file mode 100644
index 00000000..531dcae5
--- /dev/null
+++ b/internal/equipotest/direct_migration_exit_test.go
@@ -0,0 +1,134 @@
+package equipotest
+
+import (
+ "amadan.net/oficina/equipo/internal/equipo"
+ "amadan.net/oficina/equipo/internal/equipo/team"
+ "amadan.net/rastrillo/rastrillo/db"
+ "amadan.net/rastrillo/rastrillo/migrate"
+ "context"
+ "fmt"
+ "io"
+ "log/slog"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+func migratedExitFixture(t *testing.T, claimed, cancelled bool) (*equipo.Store, *equipo.Execution, *db.DB, string) {
+ t.Helper()
+ ctx := context.Background()
+ path := filepath.Join(t.TempDir(), "old.db")
+ d, err := db.Open(path, slog.New(slog.NewTextHandler(io.Discard, nil)))
+ executionMust(t, err)
+ t.Cleanup(func() { d.Close() })
+ before := &migrate.Set{}
+ for _, m := range equipo.BootSchema.All() {
+ if !strings.HasPrefix(m.ID, "equipo/0018") && !strings.HasPrefix(m.ID, "equipo/0019") {
+ before.Add(m)
+ }
+ }
+ _, err = migrate.Apply(ctx, d, before)
+ executionMust(t, err)
+ s := equipo.NewStore(d)
+ executionMust(t, s.Bootstrap(ctx, []string{ownerAddress}))
+ executionMust(t, s.SetMember(ctx, ownerActor, "member@example.com", equipo.RoleMember, true, 0))
+ options := executionOptions()
+ options.Authority.(*team.FakeAuthority).Issue("old-grant", team.Grant{Account: "team", Operations: map[team.Operation]bool{team.OpJobContinue: true, team.OpAttemptContinue: true}})
+ core, err := team.OpenShared(ctx, d.Writer(), path, options)
+ executionMust(t, err)
+ x := &equipo.Execution{Core: core}
+ _, err = x.Core.Resume(ctx)
+ executionMust(t, err)
+ job, err := x.Core.CreateJob(ctx, team.JobSpec{Account: "team", Requester: ownerAddress, GrantRef: "old-grant", Target: team.TargetBinding{Kind: team.TargetRepository, Repository: "example/shop", Ref: "team/old", DefaultRef: "main", BaseRevision: fmt.Sprintf("%064x", 1)}, Evidence: team.EvidenceRequirement{Predicate: team.PredicateSoftwareFix, ExpectedSymptom: team.FixtureSymptom, CheckDefinitionHash: team.CheckDefinitionHash}, Policy: team.DefaultPolicy(5000000, team.Rates{Version: 1}), Steps: team.SoftwareSteps(false)})
+ executionMust(t, err)
+ var instance equipo.Team
+ executionMust(t, d.G.First(&instance).Error)
+ // The job's authority account matches the migrated task's team.
+ _, err = d.Writer().Exec("UPDATE jobs SET account=? WHERE id=?", instance.ID, job.ID)
+ executionMust(t, err)
+ state := "queued"
+ if cancelled {
+ state = "cancel_requested"
+ }
+ cutoverRow(t, d, "tasks", map[string]any{"id": "old", "team_id": instance.ID, "job_id": job.ID, "state": state, "request_id": "old", "requester": ownerAddress})
+ cutoverRow(t, d, "task_outboxes", map[string]any{"task_id": "old", "state": "done", "engineering": "{}", "review": "{}"})
+ if cancelled {
+ cutoverRow(t, d, "audit_events", map[string]any{"actor": ownerAddress, "kind": "task.cancel", "record_id": "old", "at": time.Now().UTC()})
+ }
+ if claimed {
+ stamp := "2026-11-02T11:59:00Z"
+ cutoverRow(t, d, "attempts", map[string]any{"id": 1, "job_id": job.ID, "step_id": 1, "number": 1, "state": "active", "containment": "pending", "fence": 7, "created_at": stamp, "updated_at": stamp, "lease_deadline": "2026-11-02T12:01:00Z"})
+ _, err = d.Writer().Exec("UPDATE steps SET holder=1,state='running',fence=7 WHERE id=1")
+ executionMust(t, err)
+ cutoverRow(t, d, "time_reservations", map[string]any{"attempt_id": 1, "job_id": job.ID, "state": "open", "reserved_seconds": 120, "started_at": stamp})
+ cutoverRow(t, d, "runner_assignments", map[string]any{"id": "v1", "task_id": "old", "team_id": instance.ID, "state": "claimed", "claim_request": "old-claim", "attempt_id": 1, "job_id": job.ID, "fence": 7})
+ }
+ executionMust(t, core.Close())
+ _, err = migrate.Apply(ctx, d, equipo.BootSchema)
+ executionMust(t, err)
+ x, err = s.AttachExecution(ctx, path, options)
+ executionMust(t, err)
+ t.Cleanup(func() { x.Core.Close() })
+ return s, x, d, "old"
+}
+func TestMigratedTaskWaitExit(t *testing.T) {
+ for _, kind := range []string{"unclaimed", "unclaimed-cancel", "claimed", "claimed-cancel", "member", "removed-owner", "audit-failure"} {
+ t.Run(kind, func(t *testing.T) {
+ claimed := !strings.HasPrefix(kind, "unclaimed")
+ cancelled := strings.HasSuffix(kind, "cancel")
+ s, _, d, id := migratedExitFixture(t, claimed, cancelled)
+ var state, wait string
+ executionMust(t, d.Writer().QueryRow("SELECT state,wait_code FROM tasks WHERE id=?", id).Scan(&state, &wait))
+ if !claimed {
+ if wait == "task.wait.reconcile" {
+ t.Fatal("unclaimed task trapped")
+ }
+ if cancelled && state != "cancelled" {
+ t.Fatal("cancel request lost", state)
+ }
+ return
+ }
+ actor := ownerActor
+ if kind == "member" {
+ actor = equipo.Actor{Address: "member@example.com"}
+ }
+ if kind == "removed-owner" {
+ _, err := d.Writer().Exec("UPDATE members SET active=0 WHERE address=?", ownerAddress)
+ executionMust(t, err)
+ }
+ if kind == "audit-failure" {
+ _, err := d.Writer().Exec("CREATE TRIGGER stop_audit_failure BEFORE INSERT ON audit_events BEGIN SELECT RAISE(ABORT,'audit unavailable'); END")
+ executionMust(t, err)
+ }
+ err := s.OldRunnerStopped(context.Background(), actor, id)
+ if kind == "member" || kind == "removed-owner" || kind == "audit-failure" {
+ if err == nil {
+ t.Fatal("unauthorized or unaudited containment")
+ }
+ if scalar(t, d, "SELECT count(*) FROM attempts WHERE containment='pending'") != 1 {
+ t.Fatal("failed transaction changed containment")
+ }
+ return
+ }
+ executionMust(t, err)
+ executionMust(t, d.Writer().QueryRow("SELECT state,wait_code FROM tasks WHERE id=?", id).Scan(&state, &wait))
+ if wait == "task.wait.reconcile" || cancelled && state != "cancelled" {
+ t.Fatal("task still trapped", state, wait)
+ }
+ if scalar(t, d, "SELECT count(*) FROM runner_assignments WHERE state='contained'") != 1 || scalar(t, d, "SELECT count(*) FROM attempts WHERE containment='contained'") != 1 {
+ t.Fatal("v1 work not contained")
+ }
+ if scalar(t, d, "SELECT count(*) FROM audit_events WHERE kind='task.old_runner_stopped'") != 1 {
+ t.Fatal("missing audit")
+ }
+ if !cancelled {
+ var jobState string
+ executionMust(t, d.Writer().QueryRow("SELECT state FROM jobs LIMIT 1").Scan(&jobState))
+ if jobState != "running" {
+ t.Fatal("job not resumed", jobState)
+ }
+ }
+ })
+ }
+}
diff --git a/internal/equipotest/execution_schema_test.go b/internal/equipotest/execution_schema_test.go
index 75c48a17..f9439757 100644
--- a/internal/equipotest/execution_schema_test.go
+++ b/internal/equipotest/execution_schema_test.go
@@ -145,7 +145,7 @@ func TestExecutionSchemaParity(t *testing.T) {
defer old.Close()
before := &migrate.Set{}
for _, m := range equipo.BootSchema.All() {
- if m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" && m.ID != "equipo/0007_execution" && m.ID != "equipo/0008_recovery" && m.ID != "equipo/0009_runner_policy" {
+ if m.ID != "equipo/0019_direct_reconcile" && m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" && m.ID != "equipo/0007_execution" && m.ID != "equipo/0008_recovery" && m.ID != "equipo/0009_runner_policy" {
before.Add(m)
}
}
@@ -154,7 +154,7 @@ func TestExecutionSchemaParity(t *testing.T) {
executionMust(t, old.G.Create(&equipo.Account{Label: "existing account"}).Error)
result, err := migrate.Apply(ctx, old, equipo.BootSchema)
executionMust(t, err)
- if !reflect.DeepEqual(result.Applied, []string{"equipo/0007_execution", "equipo/0008_recovery", "equipo/0009_runner_policy", "equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch"}) {
+ if !reflect.DeepEqual(result.Applied, []string{"equipo/0007_execution", "equipo/0008_recovery", "equipo/0009_runner_policy", "equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch", "equipo/0019_direct_reconcile"}) {
t.Fatalf("upgrade migrations: %v", result.Applied)
}
var account equipo.Account
@@ -174,7 +174,7 @@ func TestExecutionSchemaParity(t *testing.T) {
defer old.Close()
before := &migrate.Set{}
for _, m := range equipo.BootSchema.All() {
- if m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" && m.ID != "equipo/0008_recovery" && m.ID != "equipo/0009_runner_policy" {
+ if m.ID != "equipo/0019_direct_reconcile" && m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" && m.ID != "equipo/0008_recovery" && m.ID != "equipo/0009_runner_policy" {
before.Add(m)
}
}
@@ -185,7 +185,7 @@ func TestExecutionSchemaParity(t *testing.T) {
executionMust(t, err)
result, err := migrate.Apply(ctx, old, equipo.BootSchema)
executionMust(t, err)
- if !reflect.DeepEqual(result.Applied, []string{"equipo/0008_recovery", "equipo/0009_runner_policy", "equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch"}) {
+ if !reflect.DeepEqual(result.Applied, []string{"equipo/0008_recovery", "equipo/0009_runner_policy", "equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch", "equipo/0019_direct_reconcile"}) {
t.Fatalf("task one upgrade migrations: %v", result.Applied)
}
var evidence string
@@ -207,7 +207,7 @@ func TestExecutionSchemaParity(t *testing.T) {
defer old.Close()
before := &migrate.Set{}
for _, m := range equipo.BootSchema.All() {
- if m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" && m.ID != "equipo/0009_runner_policy" {
+ if m.ID != "equipo/0019_direct_reconcile" && m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" && m.ID != "equipo/0009_runner_policy" {
before.Add(m)
}
}
@@ -233,7 +233,7 @@ func TestExecutionSchemaParity(t *testing.T) {
return
}
executionMust(t, err)
- if !reflect.DeepEqual(result.Applied, []string{"equipo/0009_runner_policy", "equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch"}) {
+ if !reflect.DeepEqual(result.Applied, []string{"equipo/0009_runner_policy", "equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch", "equipo/0019_direct_reconcile"}) {
t.Fatal("wrong task two upgrade", result.Applied)
}
var project, input, cost int
@@ -256,7 +256,7 @@ func TestExecutionSchemaParity(t *testing.T) {
defer old.Close()
before := &migrate.Set{}
for _, m := range equipo.BootSchema.All() {
- if m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" {
+ if m.ID != "equipo/0019_direct_reconcile" && m.ID != "equipo/0018_direct_launch" && m.ID != "equipo/0013_runner_assignments" && m.ID != "equipo/0012_tasks" {
before.Add(m)
}
}
@@ -265,7 +265,7 @@ func TestExecutionSchemaParity(t *testing.T) {
executionMust(t, seedExecutionJob(old.Writer()))
result, err := migrate.Apply(ctx, old, equipo.BootSchema)
executionMust(t, err)
- if !reflect.DeepEqual(result.Applied, []string{"equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch"}) {
+ if !reflect.DeepEqual(result.Applied, []string{"equipo/0012_tasks", "equipo/0013_runner_assignments", "equipo/0018_direct_launch", "equipo/0019_direct_reconcile"}) {
t.Fatal("task six upgrade migrations", result.Applied)
}
var key, hash string