carlos / platform Public

fix: back off pool withdrawal only on terminal pending causes

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2e6e5cd53f7d5170ef74ef36d87f12706e785420 parent a94d77c
6 files changed, +48 −13
  • docs/superpowers/notes/census-proposal-region-ha-g2-fixes.md +1 −1
  • internal/host/poolwithdrawal_live_test.go +1 −6
  • internal/provision/poolwithdrawal.go +4 −1
  • internal/provision/poolwithdrawal_test.go +38 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-region-ha-g2-fixes.tsv +3 −3

Intent

Human

<task-notification> <task-id>bxjl9ric0</task-id> <tool-use-id>toolu_01AQPZe4HYkpvdHQgEjCXaPF</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/bxjl9ric0.output</output-file> <status>completed</status> <summary>Background command "Run both final witnesses in parallel" completed (exit code 0)</summary> </task-notification>

Human

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

diff --git a/docs/superpowers/notes/census-proposal-region-ha-g2-fixes.md b/docs/superpowers/notes/census-proposal-region-ha-g2-fixes.md
index cf6e79232..b433d5fb9 100644
--- a/docs/superpowers/notes/census-proposal-region-ha-g2-fixes.md
+++ b/docs/superpowers/notes/census-proposal-region-ha-g2-fixes.md
@@ -141,6 +141,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the
- reads `internal/edge/wakeplacement.go:homeMap.dutySnapshot`: +registry:Pool ×2; keeps legacy, task accepted-legacy
- reads `internal/host/edgesfile.go:edgesFileWriteClaims`: +registry:Host, +registry:Pool; keeps authority, task F,J1
-Seal: `ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939` → `b40b4f5ea308f662e586909ecb049188eb1076d2ba1600e69e6739be9b53e85e`.
+Seal: `ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939` → `02d64a854b1bcbc2e20e032a0bf065d62ba4b5b197f3faa98be26b6007ddba19`.
Overlay: `internal/provision/testdata/plan14-root-reads-region-ha-g2-fixes.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/host/poolwithdrawal_live_test.go b/internal/host/poolwithdrawal_live_test.go
index cdf7af7c5..95974a419 100644
--- a/internal/host/poolwithdrawal_live_test.go
+++ b/internal/host/poolwithdrawal_live_test.go
@@ -131,13 +131,8 @@ func testPoolWithdrawalLiveAgentTicks(t *testing.T, during bool) {
bs.refreshAll(t.Context())
}
tick()
- if row, err := reg.Get(rt.Host); err != nil || row == nil || logs.starts.Load() != 1 {
- t.Fatalf("pending backoff did not retain row and proof: row=%+v err=%v starts=%d", row, err, logs.starts.Load())
- }
- clock = clock.Add(5 * time.Minute)
- tick()
if row, err := reg.Get(rt.Host); err != nil || row != nil {
- t.Fatalf("completed proof did not remove row after backoff: row=%+v err=%v starts=%d", row, err, logs.starts.Load())
+ t.Fatalf("completed proof did not remove row on next tick: row=%+v err=%v starts=%d", row, err, logs.starts.Load())
}
if logs.starts.Load() != 1 {
t.Fatalf("proof restarted %d times", logs.starts.Load())
diff --git a/internal/provision/poolwithdrawal.go b/internal/provision/poolwithdrawal.go
index 55a82adfe..939fc1b17 100644
--- a/internal/provision/poolwithdrawal.go
+++ b/internal/provision/poolwithdrawal.go
@@ -151,7 +151,10 @@ func (cfg ReconcileConfig) withdrawPools(ctx context.Context, s release.Store, r
log.Printf("ha_pool_withdrawn host=%s", rt.Host)
}
if code != "" {
- cfg.WithdrawalBackoff.pending(row, pools, now)
+ switch code {
+ case "ownership", "hook", "record", "proof", "changed", "shutdown", "fence", "stop", "startup", "cgroup", "release", "lifetime", "duties":
+ cfg.WithdrawalBackoff.pending(row, pools, now)
+ }
if err == nil {
err = PoolWithdrawalPending(code)
}
diff --git a/internal/provision/poolwithdrawal_test.go b/internal/provision/poolwithdrawal_test.go
index 79e1bb888..11b02299a 100644
--- a/internal/provision/poolwithdrawal_test.go
+++ b/internal/provision/poolwithdrawal_test.go
@@ -187,7 +187,7 @@ func TestPoolWithdrawalLogsCause(t *testing.T) {
}
func TestPoolWithdrawalPendingBackoffBeforeReads(t *testing.T) {
- for _, code := range []string{"duties", "ownership", "release", "stopping"} {
+ for _, code := range []string{"ownership", "hook", "record", "proof", "changed", "shutdown", "fence", "stop", "startup", "cgroup", "release", "lifetime", "duties"} {
t.Run(code, func(t *testing.T) {
rt := registry.Route{Host: "shop.example.com", Account: "bbw", App: "shop", Kind: "instance", Status: "ready", Provisioned: true, Hibernate: true, Pool: "old", Region: "ie", BuildState: `{"read_at":"before","version":"v1"}`}
reg := regWith(t, rt)
@@ -245,6 +245,43 @@ func TestPoolWithdrawalPendingBackoffBeforeReads(t *testing.T) {
}
}
+func TestPoolWithdrawalRunningProofDoesNotBackoff(t *testing.T) {
+ rt := registry.Route{Host: "shop.example.com", Account: "bbw", App: "shop", Kind: "instance", Status: "ready", Provisioned: true, Hibernate: true, Pool: "old", Region: "ie"}
+ reg := regWith(t, rt)
+ defer reg.Close()
+ s := dirStore(t)
+ if err := CreateRecord(ctx, s, Record{Host: rt.Host, Account: rt.Account, App: rt.App, Pool: rt.Pool, Region: rt.Region, Channel: "stable"}); err != nil {
+ t.Fatal(err)
+ }
+ now := time.Now()
+ complete := false
+ proofs, withdrawn := 0, 0
+ cfg := ReconcileConfig{
+ Region: "ie", Pools: []string{"new"}, Now: func() time.Time { return now },
+ WithdrawalBackoff: &PoolWithdrawalBackoff{},
+ WithdrawPool: func(context.Context, registry.Route) error {
+ proofs++
+ if !complete {
+ return fmt.Errorf("withdrawal inspection: %w", PoolWithdrawalPending("stopping"))
+ }
+ return nil
+ },
+ PoolWithdrawn: func() { withdrawn++ },
+ }
+ for i := 0; i < 2; i++ {
+ cfg.withdrawPools(ctx, s, reg, false)
+ if row, err := reg.Get(rt.Host); err != nil || row == nil || withdrawn != 0 {
+ t.Fatalf("running proof removed row: row=%+v err=%v callbacks=%d", row, err, withdrawn)
+ }
+ now = now.Add(2 * time.Second)
+ }
+ complete = true
+ cfg.withdrawPools(ctx, s, reg, false)
+ if row, err := reg.Get(rt.Host); err != nil || row != nil || proofs != 3 || withdrawn != 1 {
+ t.Fatalf("completed proof was not consumed on next tick: row=%+v err=%v proofs=%d callbacks=%d", row, err, proofs, withdrawn)
+ }
+}
+
type withdrawalCountingStore struct {
release.Store
reads int
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 8832d5fd4..3704b5729 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -107,4 +107,4 @@ plan14-root-reads-restart-new-box-gap.tsv 18e4df5f599a48a881526fc2f85a9b591e3ea8
plan14-root-reads-agent-start-demo-3.tsv ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939
plan14-root-reads-lease-renew-after-pause.tsv ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939
plan14-root-reads-demo-api-claim-paths.tsv ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939
-plan14-root-reads-region-ha-g2-fixes.tsv b40b4f5ea308f662e586909ecb049188eb1076d2ba1600e69e6739be9b53e85e
+plan14-root-reads-region-ha-g2-fixes.tsv 02d64a854b1bcbc2e20e032a0bf065d62ba4b5b197f3faa98be26b6007ddba19
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-g2-fixes.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-g2-fixes.tsv
index aa5457d05..c02771af4 100644
--- a/internal/provision/testdata/plan14-root-reads-region-ha-g2-fixes.tsv
+++ b/internal/provision/testdata/plan14-root-reads-region-ha-g2-fixes.tsv
@@ -59,7 +59,7 @@
@legacy d6afcf5f9b2ff25ebd7c84c6ae3804c3907be5360f49b3bd66269a0085582150 internal/provision/poolwithdrawal.go PoolWithdrawalBackoff.prune legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Compare current registry-list snapshots and configured pool evidence to pending retry rows; remove missing or changed entries in memory; no direct I/O. registry:Host@196,whole:Route@151,whole:Route@180,whole:Route@191,whole:Route@230,whole:Route@323,whole:Route@342,whole:Route@355 490a76347b2ca0f64c1a5735f48ab193fc3679dea51be3ccabc4be5cdaf255ae
@legacy 2344acd2d7ec7d3f87807f22a6d377b5b7d97e60df2b820ddedde3b7bcb933df internal/provision/poolwithdrawal.go ReconcileConfig.poolWithdrawalCandidate legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Limit withdrawal to own scope, claims disabled, supported row shapes, and no retained participant; supplied route Host only, no direct external read. registry:Host@246,whole:Route@124 c45f80cec5c837e29817811f8fad91867b52714417b9b394eae715da3a9f1897
@legacy b7b96d5f521d7c7821fbd7ebbe05e45eb0222a9c73ee4ad2d6a46314cbf576c2 internal/provision/poolwithdrawal.go ReconcileConfig.poolWithdrawalScope legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Restrict withdrawal to provisioned rows of the pass kind, its region/fleet/policy scope and pools no longer served; supplied route fields and existing policy callback, no direct new I/O. registry:Account@136,registry:App@148,registry:FleetBox@374,registry:FleetBox@395,registry:Pool@252,registry:Provisioned@161,registry:Region@285,registry:Region@553,whole:Route@495 3e5a9c32bb9435afdef72fcb11d011ce58a5a4aff9f954d97b253001ff2858eb
-@legacy 9b32f34ca9c9a9caf2ba6357519517cf4f249bfc1cd006892e6a624aa2488a26 internal/provision/poolwithdrawal.go ReconcileConfig.withdrawPools legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=List local routes and check per-host five-minute pending backoff before fresh record reads or proof callback; row and membership changes reset it. Retain fresh record checks before and after proof and guarded SQL deletion; invoke fence cleanup only after successful deletion. No object writes. registry:Host@1556,registry:Host@1774,registry:Host@910,whole:ImportJournal@940,whole:Route@1044,whole:Route@1259,whole:Route@1380,whole:Route@1620,whole:Route@371,whole:Route@406,whole:Route@445,whole:Route@513,whole:Route@556,whole:Route@635,whole:Route@814 7d81e034dedf90f804a52773a1e735cdf8e053dd56672955b9dd81a5951a075e
+@legacy c013e70674a5f2f3c9f456c3f05e4bc7df6af43c2543f34947e772898e7437ff internal/provision/poolwithdrawal.go ReconcileConfig.withdrawPools legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=List local routes and apply the five-minute pre-read backoff only to enumerated terminal pending causes; stopping and successful completed proofs proceed on the next tick. Row and membership changes still reset it. Retain fresh record checks before and after proof and guarded SQL deletion; invoke fence cleanup only after successful deletion. No new reads, object writes or authority. registry:Host@1556,registry:Host@1939,registry:Host@910,whole:ImportJournal@940,whole:Route@1044,whole:Route@1259,whole:Route@1380,whole:Route@1780,whole:Route@371,whole:Route@406,whole:Route@445,whole:Route@513,whole:Route@556,whole:Route@635,whole:Route@814 19a5ec4dd06a5ab17e5f268805a26d9ee58817d654d91210889edc62c0638aa3
@legacy 34a7c714abb155152fcb1bd3bfc456158b26cdabd0cf2cebf7b0738bdfef23ee internal/provision/poolwithdrawal.go ReconcileConfig.withdrawalRecord legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Freshly read sidecar record or lifetime-judged instance record and compare shape, ownership, pool, region and lifetime; refuse held/moving/importing/replica/demo/seed/run cases. New read via existing typed record/judge APIs, no writes. registry:Account@171,registry:Account@302,registry:Account@821,registry:App@163,registry:App@314,registry:App@833,registry:Host@154,registry:Host@249,registry:Host@418,registry:Host@841,registry:Incarnation@1265,registry:Incarnation@479,registry:Kind@1185,registry:Pool@1235,registry:Pool@468,registry:Region@1210,registry:Region@443,registry:ServingSeq@1298,registry:ServingSeq@502,registry:WakeIncarnation@1693,registry:WakeIncarnation@1721,registry:WakeIncarnation@1788,registry:WakeIncarnation@644,registry:WakeIncarnation@672,registry:WakeIncarnation@742 0267f637152ed67231181eb275a3bdfda44bae121a23e35b41bc2448f29b48aa
@legacy b7437b53fa7c973188ba5ea869ac3a0c0a6ac0c005cdfe531a44dea4742cb29b internal/provision/poolwithdrawal.go poolWithdrawalRetryRow legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Normalize only BuildState.read_at out of an in-memory row copy for retry identity; all other fields still reset backoff; no I/O. registry:BuildState@128,registry:BuildState@259,whole:Route@303 9287fc77efef6c2fa82de670c746b5fa325a0a59f85d634f0bc1f68e258ab714
@legacy fb756ce3a76346cbe4058714c9057c0f4f428bdee23d99e85d2f146803248d13 internal/registry/poolwithdrawal.go Registry.DeleteWithdrawnRoute legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=New local SQL transaction rereads the full route and timer/import-journal existence; delete only an unchanged supported non-forward row with no duties. Two new SQL queries and one route DELETE, remote calls refused, no object-store record write. file:QueryRowContext@339,file:QueryRowContext@663,registry:Host@412,registry:Host@792,registry:Host@807,registry:Host@982,registry:NextDue@590,registry:WakeIncarnation@533,registry:remote@97,registry:sql@227,whole:Route@567,whole:Route@578,whole:remoteClient@99 6eee55ea85213114368e009ae3002fa0bf850b928b3068c0ba1b243b8034ec9a
@@ -151,7 +151,7 @@ internal/provision/poolwithdrawal.go PoolWithdrawalBackoff.pending legacy accept
internal/provision/poolwithdrawal.go PoolWithdrawalBackoff.prune legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Compare current registry-list snapshots and configured pool evidence to pending retry rows; remove missing or changed entries in memory; no direct I/O. registry:Host@196,whole:Route@151,whole:Route@180,whole:Route@191,whole:Route@230,whole:Route@323,whole:Route@342,whole:Route@355 490a76347b2ca0f64c1a5735f48ab193fc3679dea51be3ccabc4be5cdaf255ae
internal/provision/poolwithdrawal.go ReconcileConfig.poolWithdrawalCandidate legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Limit withdrawal to own scope, claims disabled, supported row shapes, and no retained participant; supplied route Host only, no direct external read. registry:Host@246,whole:Route@124 c45f80cec5c837e29817811f8fad91867b52714417b9b394eae715da3a9f1897
internal/provision/poolwithdrawal.go ReconcileConfig.poolWithdrawalScope legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Restrict withdrawal to provisioned rows of the pass kind, its region/fleet/policy scope and pools no longer served; supplied route fields and existing policy callback, no direct new I/O. registry:Account@136,registry:App@148,registry:FleetBox@374,registry:FleetBox@395,registry:Pool@252,registry:Provisioned@161,registry:Region@285,registry:Region@553,whole:Route@495 3e5a9c32bb9435afdef72fcb11d011ce58a5a4aff9f954d97b253001ff2858eb
-internal/provision/poolwithdrawal.go ReconcileConfig.withdrawPools legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=List local routes and check per-host five-minute pending backoff before fresh record reads or proof callback; row and membership changes reset it. Retain fresh record checks before and after proof and guarded SQL deletion; invoke fence cleanup only after successful deletion. No object writes. registry:Host@1556,registry:Host@1774,registry:Host@910,whole:ImportJournal@940,whole:Route@1044,whole:Route@1259,whole:Route@1380,whole:Route@1620,whole:Route@371,whole:Route@406,whole:Route@445,whole:Route@513,whole:Route@556,whole:Route@635,whole:Route@814 7d81e034dedf90f804a52773a1e735cdf8e053dd56672955b9dd81a5951a075e
+internal/provision/poolwithdrawal.go ReconcileConfig.withdrawPools legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=List local routes and apply the five-minute pre-read backoff only to enumerated terminal pending causes; stopping and successful completed proofs proceed on the next tick. Row and membership changes still reset it. Retain fresh record checks before and after proof and guarded SQL deletion; invoke fence cleanup only after successful deletion. No new reads, object writes or authority. registry:Host@1556,registry:Host@1939,registry:Host@910,whole:ImportJournal@940,whole:Route@1044,whole:Route@1259,whole:Route@1380,whole:Route@1780,whole:Route@371,whole:Route@406,whole:Route@445,whole:Route@513,whole:Route@556,whole:Route@635,whole:Route@814 19a5ec4dd06a5ab17e5f268805a26d9ee58817d654d91210889edc62c0638aa3
internal/provision/poolwithdrawal.go ReconcileConfig.withdrawalRecord legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Freshly read sidecar record or lifetime-judged instance record and compare shape, ownership, pool, region and lifetime; refuse held/moving/importing/replica/demo/seed/run cases. New read via existing typed record/judge APIs, no writes. registry:Account@171,registry:Account@302,registry:Account@821,registry:App@163,registry:App@314,registry:App@833,registry:Host@154,registry:Host@249,registry:Host@418,registry:Host@841,registry:Incarnation@1265,registry:Incarnation@479,registry:Kind@1185,registry:Pool@1235,registry:Pool@468,registry:Region@1210,registry:Region@443,registry:ServingSeq@1298,registry:ServingSeq@502,registry:WakeIncarnation@1693,registry:WakeIncarnation@1721,registry:WakeIncarnation@1788,registry:WakeIncarnation@644,registry:WakeIncarnation@672,registry:WakeIncarnation@742 0267f637152ed67231181eb275a3bdfda44bae121a23e35b41bc2448f29b48aa
internal/provision/poolwithdrawal.go poolWithdrawalRetryRow legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=Normalize only BuildState.read_at out of an in-memory row copy for retry identity; all other fields still reset backoff; no I/O. registry:BuildState@128,registry:BuildState@259,whole:Route@303 9287fc77efef6c2fa82de670c746b5fa325a0a59f85d634f0bc1f68e258ab714
internal/registry/poolwithdrawal.go Registry.DeleteWithdrawnRoute legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-g2-fixes;basis=New local SQL transaction rereads the full route and timer/import-journal existence; delete only an unchanged supported non-forward row with no duties. Two new SQL queries and one route DELETE, remote calls refused, no object-store record write. file:QueryRowContext@339,file:QueryRowContext@663,registry:Host@412,registry:Host@792,registry:Host@807,registry:Host@982,registry:NextDue@590,registry:WakeIncarnation@533,registry:remote@97,registry:sql@227,whole:Route@567,whole:Route@578,whole:remoteClient@99 6eee55ea85213114368e009ae3002fa0bf850b928b3068c0ba1b243b8034ec9a
@@ -191,6 +191,6 @@ internal/host/hadepartures.go Controller.step legacy accepted-legacy accepted-le
@coverage internal/hafresh 5a10a9c971ba3a811e4bfdd2f59bd5715c41f991c872593d4ba42d4dfbfe6b21
@coverage internal/host c90e13ee3f67f655edc20cf2037f687d7e1c35ddbf0272894eaedf8b3058f3cb
@coverage internal/lease 4c730668ace9bf2f7ea3fbbffae2bc7113253ce2a089b00f46c0651904dc8450
-@coverage internal/provision 639900e0c5320614a0345590ffc1b19d85f10369467d2bf59de60709306f0ce1
+@coverage internal/provision a8c0f86e654fda131d5f2636125bb5c84aad234ebe94f3382f9e2ed85ba2cbe5
@coverage internal/registry bcbd1fb23f5d3b809d53d11c58f58bbb2cbcf2065d811f4cc8a7a0fa8cb90000
@coverage internal/termfence 1157dc8710325f35219ef59abf1702fc3688082c5080da48c25e129622ad77fb