oficina / equipo Public

fix: reconcile stale grants during runtime supervision

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 36932ac1e868e0727ec5da11096e4e7e9b4273e9 parent 1215b58
2 files changed, +40 −1
  • internal/equipo/execution_startup.go +5 −1
  • internal/equipotest/final_reconcile_test.go +35 −0
diff --git a/internal/equipo/execution_startup.go b/internal/equipo/execution_startup.go
index cf8adce5..efb307fd 100644
--- a/internal/equipo/execution_startup.go
+++ b/internal/equipo/execution_startup.go
@@ -104,7 +104,11 @@ func (e *Execution) Reconcile(ctx context.Context) error {
if status.Quarantine {
return nil
}
- if status.AdmissionPaused {
+ var stale bool
+ if err = e.db.G.WithContext(ctx).Raw(`SELECT EXISTS(SELECT 1 FROM jobs WHERE grant_stale=1 AND state NOT IN ('succeeded','failed','cancelled'))`).Row().Scan(&stale); err != nil {
+ return err
+ }
+ if status.AdmissionPaused || stale {
if _, err = e.Core.Resume(ctx); err != nil {
return err
}
diff --git a/internal/equipotest/final_reconcile_test.go b/internal/equipotest/final_reconcile_test.go
new file mode 100644
index 00000000..5f79541d
--- /dev/null
+++ b/internal/equipotest/final_reconcile_test.go
@@ -0,0 +1,35 @@
+package equipotest
+
+import (
+ "context"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/equipo"
+ "amadan.net/oficina/equipo/internal/equipo/team"
+)
+
+func TestReconcileRuntimeStaleGrants(t *testing.T) {
+ for _, revoked := range []bool{false, true} {
+ t.Run(map[bool]string{false: "authorized", true: "revoked"}[revoked], func(t *testing.T) {
+ s, d, x, _, _, req := recoveryRuntime(t)
+ ctx := context.Background()
+ scope, h, _ := recoveryJob(t, x, req, "runtime")
+ executionMust(t, s.SetMember(ctx, ownerActor, "new@example.com", equipo.RoleMember, true, 0))
+ executionMust(t, x.Core.Contain(ctx, scope, h.Attempt, "supervisor"))
+ if revoked {
+ mustSQL(t, d, "UPDATE members SET active=0 WHERE address=?", "member@example.com")
+ }
+ executionMust(t, x.Reconcile(ctx))
+ job, err := x.Core.GetJob(ctx, scope)
+ executionMust(t, err)
+ if revoked {
+ if job.State != team.JobCancelled {
+ t.Fatal("reconcile left revoked job runnable", job.State)
+ }
+ } else {
+ _, err = x.Core.Claim(ctx, scope, "reproduce", "next", "next")
+ executionMust(t, err)
+ }
+ })
+ }
+}