carlos / platform Public

fix: preserve explicit placement outside managed pool gates

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev fc79ad34cb82186c3c70ef70d0edab084e78961e parent b0093ac
7 files changed, +80 −8
  • internal/activator/backend_exec.go +1 −1
  • internal/activator/backend_unit.go +3 −3
  • internal/activator/ha_pool_test.go +68 −0
  • internal/activator/haduties.go +1 −1
  • internal/activator/haforward.go +3 −0
  • internal/activator/hawake.go +1 −1
  • internal/activator/pools_test.go +3 −2

Intent

Human

<task-notification> <task-id>a87bb269c68453220</task-id> <tool-use-id>toolu_01PurWXUkZHea3N5syu9koqd</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/a87bb269c68453220.output</output-file> <status>completed</status> <summary>Agent "Whole-branch final review (Opus)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Verdict: READY AFTER FIXES.** P1: 0, P2: 2, P3: 5. - **P2-1:** `internal/activator/haforward.go:126-150` with `haleaseloss.go:106-117,143`. Take a box that leaves a pool and restarts with an owed release marker for host H. The first request for H latches H from the startup obligations, and `forwardTarget` answers Unavailable. Recovery needs the box to be in the pool, so it never runs, and nothing clears the latch. That box then refuses H with the reused "cannot wake" 503 (holder header `none`) until it restarts, even after an eligible peer holds H. This breaks the F-B rule that such a box forwards. Fix: don't latch or refuse from startup obligations on an ineligible box, or drop startup-only latches once the marker is settled. Add a test for it. - **P2-2:** a tenant name ("adi-knitting", "adi's CARLOS_POOLS") is in the follow-up note (line 106) and the plan (lines 682 and 687). Doc-only fix. The review file also covers the five P3s, the triage of every deferred minor (all follow-up or accept, none must-fix), and the unreviewed commits checked with no finding. No tests were run. Path: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-g2-fixes/.superpowers/sdd/2026-11-06-region-ha-g2-fixes/final-review-r1.md`</result> <usage><subagent_tokens>222364</subagent_tokens><tool_uses>62</tool_uses><duration_ms>835882</duration_ms></usage> </task-notification>

diff --git a/internal/activator/backend_exec.go b/internal/activator/backend_exec.go
index 683b37833..516a4a456 100644
--- a/internal/activator/backend_exec.go
+++ b/internal/activator/backend_exec.go
@@ -817,7 +817,7 @@ func (b *ExecBackend) Acquire(ctx context.Context, rt registry.Route) (Lease, er
if err := b.tenantStartRefusal(rt); err != nil {
return nil, err
}
- if !b.poolEligible(rt) {
+ if (rt.HA || rt.Provisioned) && !b.poolEligible(rt) {
return nil, &errLeaseRefused{reason: hafresh.ReasonPoolIneligible}
}
// Admission before the lease: the instance's config has to be
diff --git a/internal/activator/backend_unit.go b/internal/activator/backend_unit.go
index ea175b16c..7073e7d0c 100644
--- a/internal/activator/backend_unit.go
+++ b/internal/activator/backend_unit.go
@@ -303,7 +303,7 @@ func (b *SplitBackend) pick(rt registry.Route) Backend {
}
func (b *SplitBackend) Acquire(ctx context.Context, rt registry.Route) (Lease, error) {
- if !b.poolEligible(rt) {
+ if (rt.HA || rt.Provisioned) && !b.poolEligible(rt) {
return nil, &errLeaseRefused{reason: hafresh.ReasonPoolIneligible}
}
// A unit-backed row never reaches ExecBackend.Acquire, where the region
@@ -473,7 +473,7 @@ func (b *SplitBackend) Seed(ctx context.Context, rt registry.Route) error {
return b.pick(rt).Seed(ctx, rt)
}
func (b *SplitBackend) Start(ctx context.Context, rt registry.Route) (Proc, string, error) {
- if !b.poolEligible(rt) {
+ if (rt.HA || rt.Provisioned) && !b.poolEligible(rt) {
return nil, "", &errLeaseRefused{reason: hafresh.ReasonPoolIneligible}
}
return b.pick(rt).Start(ctx, rt)
@@ -487,7 +487,7 @@ func (b *SplitBackend) HasSidecar(rt registry.Route) bool { return b.pick(rt).Ha
// unit side: systemd binds a unit tenant's canonical socket) is started
// with Start and gets the canonical handle.
func (b *SplitBackend) StartGen(ctx context.Context, rt registry.Route, n uint64, perGen bool) (Proc, Gen, error) {
- if !b.poolEligible(rt) {
+ if (rt.HA || rt.Provisioned) && !b.poolEligible(rt) {
return nil, Gen{}, &errLeaseRefused{reason: hafresh.ReasonPoolIneligible}
}
if g, ok := b.pick(rt).(GenBackend); ok {
diff --git a/internal/activator/ha_pool_test.go b/internal/activator/ha_pool_test.go
index 716cde1f1..2ad10a1a8 100644
--- a/internal/activator/ha_pool_test.go
+++ b/internal/activator/ha_pool_test.go
@@ -196,3 +196,71 @@ func TestPoolGateRouteIdentityDrift(t *testing.T) {
})
}
}
+
+func TestPoolGatePreservesExplicitPlacement(t *testing.T) {
+ for _, shape := range []string{"manual", "platform", "provisioned", "ha"} {
+ t.Run(shape, func(t *testing.T) {
+ a, b, _, reg := testActivator(t, time.Hour)
+ defer reg.Close()
+ defer a.Shutdown(context.Background())
+ a.backend = poolDeniedBackend{Backend: b}
+ rt := testRoute("manual.example.com")
+ rt.Platform = shape == "platform"
+ rt.Provisioned = shape == "provisioned"
+ rt.HA = shape == "ha"
+ if err := reg.Upsert(rt); err != nil {
+ t.Fatal(err)
+ }
+ allowed := shape == "manual" || shape == "platform"
+ for i := 0; i < 2; i++ {
+ w := httptest.NewRecorder()
+ called := false
+ a.ServeHTTP(w, httptest.NewRequest("GET", "https://"+rt.Host+"/", nil), rt, http.HandlerFunc(func(http.ResponseWriter, *http.Request) { called = true }))
+ if called != allowed {
+ t.Fatalf("proxy=%v status=%d", called, w.Code)
+ }
+ }
+ if allowed && !a.HeldAdmissible(rt.Host) {
+ t.Fatal("explicit placement lost held admission")
+ }
+ b.mu.Lock()
+ acquires := b.acquires
+ b.mu.Unlock()
+ if (acquires != 0) != allowed {
+ t.Fatalf("acquires=%d", acquires)
+ }
+ })
+ }
+}
+
+func TestPoolGateExplicitBackendAdmission(t *testing.T) {
+ for _, managed := range []bool{false, true} {
+ rt := registry.Route{Host: "manual.example.com", Provisioned: managed}
+ stop := errors.New("config gate reached")
+ b := &ExecBackend{ServedPools: func() edgesfile.PoolEvidence { return edgesfile.PoolEvidence(`["ha"]`) }, ConfigGate: func(context.Context, registry.Route) error { return stop }}
+ _, err := b.Acquire(t.Context(), rt)
+ if errors.Is(err, stop) == managed {
+ t.Fatalf("managed=%v acquire=%v", managed, err)
+ }
+ if err := b.haSpawnGate(rt); (err == nil) == managed {
+ t.Fatalf("managed=%v spawn=%v", managed, err)
+ }
+ fake := &fakeBackend{}
+ split := &SplitBackend{Exec: b, Unit: fake}
+ rt.Backing = registry.BackingUnit
+ l, err := split.Acquire(t.Context(), rt)
+ if (err == nil) == managed {
+ t.Fatalf("managed=%v split acquire=%v", managed, err)
+ }
+ if l != nil {
+ _ = l.Release(t.Context())
+ }
+ p, _, err := split.Start(t.Context(), rt)
+ if (err == nil) == managed {
+ t.Fatalf("managed=%v split start=%v", managed, err)
+ }
+ if p != nil {
+ _ = p.Stop(t.Context())
+ }
+ }
+}
diff --git a/internal/activator/haduties.go b/internal/activator/haduties.go
index 91a0bb2ff..fe3850b52 100644
--- a/internal/activator/haduties.go
+++ b/internal/activator/haduties.go
@@ -198,7 +198,7 @@ func (a *Service) saveDuty(ctx context.Context, host, life string, old DutyState
func (a *Service) dutyInput(ctx context.Context, rt registry.Route) (DutyInput, DutyState, error) {
i := DutyInput{Host: rt.Host}
- if gate, ok := a.backend.(interface{ poolEligible(registry.Route) bool }); ok && !gate.poolEligible(rt) {
+ if !a.LocalEligible(rt) {
i.LocalDenied = true
return i, DutyState{}, nil
}
diff --git a/internal/activator/haforward.go b/internal/activator/haforward.go
index b4bb2209a..58663b8a0 100644
--- a/internal/activator/haforward.go
+++ b/internal/activator/haforward.go
@@ -343,6 +343,9 @@ func forwardedHA(r *http.Request, rt registry.Route, err error) bool {
// LocalEligible reads the configured pool boundary, independently of peer evidence.
func (a *Service) LocalEligible(rt registry.Route) bool {
+ if !rt.HA && !rt.Provisioned {
+ return true
+ }
if gate, ok := a.backend.(interface{ poolEligible(registry.Route) bool }); ok {
return gate.poolEligible(rt)
}
diff --git a/internal/activator/hawake.go b/internal/activator/hawake.go
index aeb8f7a37..b21afa856 100644
--- a/internal/activator/hawake.go
+++ b/internal/activator/hawake.go
@@ -441,7 +441,7 @@ func (b *ExecBackend) haAcquired(host string) (haWake, bool) {
// co-spawned sidecar, a seed): a layout change mid-life refuses the next
// spawn instead of running it uncontained.
func (b *ExecBackend) haSpawnGate(rt registry.Route) error {
- if !b.poolEligible(rt) {
+ if (rt.HA || rt.Provisioned) && !b.poolEligible(rt) {
return &errLeaseRefused{reason: hafresh.ReasonPoolIneligible}
}
if err := b.tenantStartRefusal(rt); err != nil {
diff --git a/internal/activator/pools_test.go b/internal/activator/pools_test.go
index f7e3dfe5d..e1b4ef5b5 100644
--- a/internal/activator/pools_test.go
+++ b/internal/activator/pools_test.go
@@ -12,7 +12,7 @@ import (
)
func TestAcquireHAPoolEligibility(t *testing.T) {
- for _, state := range []string{"absent", "clean", "unclean", "lifted", "own expired", "foreign terminated", "unexpired", "stale non-HA", "legacy row"} {
+ for _, state := range []string{"absent", "clean", "unclean", "lifted", "own expired", "foreign terminated", "unexpired", "stale non-HA", "hand-added HA row"} {
t.Run(state, func(t *testing.T) {
makeBackend := haBackend
if state == "stale non-HA" {
@@ -34,8 +34,9 @@ func TestAcquireHAPoolEligibility(t *testing.T) {
expires = time.Now().Add(time.Hour)
}
putLockFor(t, b, rt, leaseBody(t, hafresh.OwnerFor(hafresh.Self{Ref: "b", IID: "i-b"}, 1, true), expires))
- case "legacy row":
+ case "hand-added HA row":
rt.Provisioned = false
+ rt.HA = true
}
terms := 0
b.OwnerTerminated = func(context.Context, string) (bool, error) { terms++; return true, nil }