carlos / platform Public

fix: retire completed pool withdrawal fences

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 596127da35101b0cd6ebe0da52ad8abbf24b3e3a parent fc79ad3
8 files changed, +112 −2
  • internal/activator/activator.go +1 −0
  • internal/activator/poolwithdrawal.go +35 −0
  • internal/activator/poolwithdrawal_test.go +59 −0
  • internal/host/agent.go +1 −0
  • internal/host/poolwithdrawal.go +6 −0
  • internal/provision/poolwithdrawal.go +3 −0
  • internal/provision/poolwithdrawal_test.go +5 −1
  • internal/provision/reconcile.go +2 −1

Intent

Human

<task-notification> <task-id>bigy739tt</task-id> <tool-use-id>toolu_019Bo4Af9byLzs1w1GDrgyro</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/bigy739tt.output</output-file> <status>completed</status> <summary>Background command "Run F-A witness live, run 4" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>bn3dlxcq1</task-id> <tool-use-id>toolu_01XkTEF6UDfshoBzGxS3YWQb</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/bn3dlxcq1.output</output-file> <status>completed</status> <summary>Background command "Run F-B witness live, run 16" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index b9af7ea1c..38dbaaedb 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -5434,6 +5434,7 @@ func (a *Service) sweepOnce() {
// spacing; one retry pass at a time, off a.mu.
a.retryOwedMarkers()
a.retryHALostHosts()
+ a.ReapPoolWithdrawals()
// The due query runs before the lock — it's a registry read, and nothing
// under a.mu should wait on SQLite.
dueRoutes, err := a.due.DueInstances(now.Unix())
diff --git a/internal/activator/poolwithdrawal.go b/internal/activator/poolwithdrawal.go
index 1fedda5af..de15a6509 100644
--- a/internal/activator/poolwithdrawal.go
+++ b/internal/activator/poolwithdrawal.go
@@ -27,6 +27,7 @@ type poolWithdrawal struct {
}
func (a *Service) PreparePoolWithdrawal(ctx context.Context, rt registry.Route) error {
+ a.ReapPoolWithdrawals()
pending := provision.PoolWithdrawalPending
if ctx.Err() != nil {
return ctx.Err()
@@ -254,3 +255,37 @@ func (b *ExecBackend) poolWithdrawalEmpty(rt registry.Route) error {
}
return nil
}
+
+func (a *Service) ReapPoolWithdrawals() {
+ if a.Routes == nil {
+ return
+ }
+ a.mu.Lock()
+ jobs := make(map[string]*poolWithdrawal)
+ for host, job := range a.poolWithdrawals {
+ if job.done {
+ jobs[host] = job
+ }
+ }
+ a.mu.Unlock()
+ for host, job := range jobs {
+ current, err := a.Routes.Get(host)
+ if err != nil || (current != nil && samePoolWithdrawalRoute(*current, withdrawalRow(job.route)) && !a.LocalEligible(*current)) {
+ continue
+ }
+ a.mu.Lock()
+ lifted := false
+ if a.poolWithdrawals[host] == job && job.done {
+ delete(a.poolWithdrawals, host)
+ if a.fences[host] == 1 && a.fenceOwners[host] == job.owner && a.seedExclusions[host] == nil {
+ delete(a.fences, host)
+ delete(a.fenceOwners, host)
+ lifted = true
+ }
+ }
+ a.mu.Unlock()
+ if lifted {
+ a.noteHeldAdmissible(host)
+ }
+ }
+}
diff --git a/internal/activator/poolwithdrawal_test.go b/internal/activator/poolwithdrawal_test.go
index 8fcaa773a..4acedf1f5 100644
--- a/internal/activator/poolwithdrawal_test.go
+++ b/internal/activator/poolwithdrawal_test.go
@@ -361,3 +361,62 @@ func TestPoolWithdrawalLogsProofAttempt(t *testing.T) {
})
}
}
+
+func TestPoolWithdrawalFenceRetires(t *testing.T) {
+ for _, mode := range []string{"deleted", "changed", "eligible", "running", "other-owner"} {
+ t.Run(mode, func(t *testing.T) {
+ s, e := haServiceEntry(t, "shop.example.com")
+ rt := withdrawalFixture(t, s)
+ if err := awaitWithdrawal(t, s, rt, true); err != nil {
+ t.Fatal(err)
+ }
+ if !s.stoppedFor(e) {
+ t.Fatal("stop incomplete")
+ }
+ switch mode {
+ case "deleted", "running", "other-owner":
+ if deleted, err := s.b.Registry.DeleteWithdrawnRoute(t.Context(), rt); err != nil || !deleted {
+ t.Fatalf("delete: %v %v", deleted, err)
+ }
+ case "changed":
+ row := withdrawalRow(rt)
+ row.Pool = "other"
+ if err := s.b.Registry.Upsert(row); err != nil {
+ t.Fatal(err)
+ }
+ case "eligible":
+ s.b.ServedPools = eligibleSharedPools
+ }
+ s.a.mu.Lock()
+ if mode == "running" {
+ s.a.poolWithdrawals[rt.Host].done = false
+ }
+ if mode == "other-owner" {
+ s.a.fenceOwners[rt.Host] = "another-operation"
+ }
+ s.a.mu.Unlock()
+ s.a.sweepOnce()
+ wantFence := mode == "running" || mode == "other-owner"
+ if s.a.Fenced(rt.Host) != wantFence {
+ t.Fatalf("fenced=%v want %v", s.a.Fenced(rt.Host), wantFence)
+ }
+ if mode == "deleted" {
+ s.b.ServedPools = eligibleSharedPools
+ if err := s.b.Registry.Upsert(withdrawalRow(rt)); err != nil {
+ t.Fatal(err)
+ }
+ n, err := s.a.beginRequest(t.Context(), withdrawalRow(rt))
+ if err != nil {
+ t.Fatalf("re-minted host refused: %v", err)
+ }
+ if n != nil {
+ n()
+ s.a.mu.Lock()
+ e := s.a.entries[rt.Host]
+ s.a.mu.Unlock()
+ s.stopForTest(e)
+ }
+ }
+ })
+ }
+}
diff --git a/internal/host/agent.go b/internal/host/agent.go
index a420086a1..08a1c5a67 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -2062,6 +2062,7 @@ func reconcileSerializedAuth(ctx context.Context, s release.Store, reg *registry
defer reconcileMu.Unlock()
if cfg.WithdrawPool == nil {
cfg.WithdrawPool = preparePoolWithdrawal
+ cfg.PoolWithdrawn = finishPoolWithdrawal
}
start := auth.passBegin()
defer auth.passEnd() // after the sidecar pass's writes too
diff --git a/internal/host/poolwithdrawal.go b/internal/host/poolwithdrawal.go
index 58575c862..c3d2c9ff8 100644
--- a/internal/host/poolwithdrawal.go
+++ b/internal/host/poolwithdrawal.go
@@ -18,3 +18,9 @@ func preparePoolWithdrawal(ctx context.Context, rt registry.Route) error {
}
return svc.PreparePoolWithdrawal(ctx, rt)
}
+
+func finishPoolWithdrawal() {
+ if svc := armedPoolWithdrawal.Load(); svc != nil {
+ svc.ReapPoolWithdrawals()
+ }
+}
diff --git a/internal/provision/poolwithdrawal.go b/internal/provision/poolwithdrawal.go
index d5f198779..df6f199a0 100644
--- a/internal/provision/poolwithdrawal.go
+++ b/internal/provision/poolwithdrawal.go
@@ -132,6 +132,9 @@ func (cfg ReconcileConfig) withdrawPools(ctx context.Context, s release.Store, r
code = "changed"
break
}
+ if cfg.PoolWithdrawn != nil {
+ cfg.PoolWithdrawn()
+ }
log.Printf("ha_pool_withdrawn host=%s", rt.Host)
}
if code != "" {
diff --git a/internal/provision/poolwithdrawal_test.go b/internal/provision/poolwithdrawal_test.go
index 7e8fb2e46..77ba06e34 100644
--- a/internal/provision/poolwithdrawal_test.go
+++ b/internal/provision/poolwithdrawal_test.go
@@ -27,7 +27,8 @@ func TestPoolWithdrawalRequiresCompleteProof(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- cfg := ReconcileConfig{Region: "ie", Pools: []string{"new"}}
+ finished := 0
+ cfg := ReconcileConfig{Region: "ie", Pools: []string{"new"}, PoolWithdrawn: func() { finished++ }}
cfg.WithdrawPool = func(context.Context, registry.Route) error {
if test == "changed-record-lifetime" || test == "changed-record-pool" {
changed, err := GetRecord(ctx, s, rt.Account, rt.App, rt.Host)
@@ -71,6 +72,9 @@ func TestPoolWithdrawalRequiresCompleteProof(t *testing.T) {
putReplace(t, s, RecordKey(rt.Account, rt.App, rt.Host), []byte("{"))
}
cfg.withdrawPools(ctx, s, reg, false)
+ if (finished == 1) != (test == "success") {
+ t.Fatalf("completion callbacks=%d", finished)
+ }
got, err := reg.Get(rt.Host)
if err != nil {
t.Fatal(err)
diff --git a/internal/provision/reconcile.go b/internal/provision/reconcile.go
index 2c30a0e6f..e7e4799d0 100644
--- a/internal/provision/reconcile.go
+++ b/internal/provision/reconcile.go
@@ -36,7 +36,8 @@ import (
// injection-seam shape domains.Config uses (tests supply fixtures, the host
// agent supplies production values).
type ReconcileConfig struct {
- WithdrawPool func(context.Context, registry.Route) error
+ WithdrawPool func(context.Context, registry.Route) error
+ PoolWithdrawn func()
// HAIngress receives the complete pre-pool record scan; errors revoke its evidence.
HAIngress func([]Record, error)