carlos / platform Public

region-ha p1b-2: holder review fixes: through the agent's SplitBackend, and a sidecar refusal says none

ForwardTarget and NoteForward found the exec backend only by a direct
type assertion, so the agent's SplitBackend forwarded nothing: holder
discovery now goes to the half that serves the route, and this box's
identity is the exec half's. A forwarded HA sidecar request refused
asleep or fenced now carries X-Carlos-Holder: none under today's answer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev d364d32ae27dd1e9d5cb6b81374f491fdecfbc36 parent 5418a27
3 files changed, +124 −5
  • internal/activator/activator.go +2 −0
  • internal/activator/haforward.go +48 −5
  • internal/activator/haforward_test.go +74 −0

Intent

Human

<task-notification> <task-id>a2c8cf94f002a27be</task-id> <tool-use-id>toolu_015ubgigbNWfhEzsv92mSc4A</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/a2c8cf94f002a27be.output</output-file> <status>completed</status> <summary>Agent "Implement Task 3: activator holder cache" 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>Status: DONE. The activator now tells the edge which box to forward to, follows how each forward went, and answers forwarded HA requests it cannot serve with an `X-Carlos-Holder` diagnostic. Commit: 5418a27a `region-ha p1b-2: the activator names a holder to forward to`. Git printed a `packed-refs.lock` error during the commit, but the commit and branch ref did land. Tests: the brief's command passes (also with `-race`), and so do `HA|SameBox|Takeover|Lease`, related serve and fence tests, gofmt, vet and the linux, darwin and windows builds. I wrote the code before the tests, so they never failed first; to make up for it, I removed three behaviours one at a time and the matching tests failed each time. Concerns: - A holder that is out of view or unreachable is dropped, not cached as "not held elsewhere", as the brief says. While its lock is unexpired, every request does one lock GET (plus a 2 s dial when it can't be reached), so the 10 s cap doesn't apply there. - A failed lock read caches nothing, so if S3 is failing, every request does one GET. - A legacy-format owner on an HA route gets today's answer plus `none`, because there is no box ref to name. - `forwardedHop` and `readHolderLock` are package-level test hooks: tests in the activator package have no other way to mark a request as a verified hop. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b2/.superpowers/sdd/2026-10-29-region-ha-p1b2-forwarding/task-3-report.md</result> <usage><subagent_tokens>133236</subagent_tokens><tool_uses>41</tool_uses><duration_ms>640056</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bypkb1gmr</task-id> <tool-use-id>toolu_01XHzmByLLSk8g6oC8xjLJ74</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/bypkb1gmr.output</output-file> <status>completed</status> <summary>Background command "Package Task 3 and run its Astra review" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 33.6 g CO₂e (4,429,723 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-p1b2-forwarding, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index b4a9b0412..994d6a85d 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -6005,6 +6005,8 @@ func (a *Service) serve(w http.ResponseWriter, r *http.Request, rt registry.Rout
// could spoof.
r.Header.Del(SidecarHeader)
if err := a.BeginSidecarRequest(r.Context(), rt); err != nil {
+ // A forwarded request's answer says none (haforward.go).
+ noteNoHolder(w, r, rt, err)
if errors.Is(err, ErrFenced) {
maintenanceResponse(w, r)
return true
diff --git a/internal/activator/haforward.go b/internal/activator/haforward.go
index fb898471c..b07c72ce5 100644
--- a/internal/activator/haforward.go
+++ b/internal/activator/haforward.go
@@ -59,6 +59,33 @@ func (b *ExecBackend) readHolderView(ctx context.Context, rt registry.Route) (ha
return readHolderLock(ctx, b.Cfg.Bucket, b.Cfg.hibernatePrefix(rt.Host), b.Cfg.Region)
}
+// holderReaderFor is the backend that reads rt's holder, nil for none. The
+// agent's backend is a SplitBackend (host/agent.go): rt goes to the half
+// that serves it, as every other call does, and the unit half (which never
+// wakes a born-HA host) reads nothing.
+func holderReaderFor(b Backend, rt registry.Route) holderLockReader {
+ switch b := b.(type) {
+ case *SplitBackend:
+ return holderReaderFor(b.pick(rt), rt)
+ case holderLockReader:
+ return b
+ }
+ return nil
+}
+
+// boxSelfRef is this box's reference as its HA leases name it: the exec
+// backend's identity, through a SplitBackend too. ok is false for a
+// backend that takes no HA lease.
+func boxSelfRef(b Backend) (string, bool) {
+ switch b := b.(type) {
+ case *SplitBackend:
+ return boxSelfRef(b.Exec)
+ case holderLockReader:
+ return b.self().Ref, true
+ }
+ return "", false
+}
+
// holderReadErrLogged is when a failed lock read was last logged (unix
// nanos): at most one line a minute for the box, since every request of
// a host whose read fails reads again.
@@ -74,8 +101,8 @@ func (a *Service) ForwardTarget(ctx context.Context, rt registry.Route) string {
if !rt.HA {
return ""
}
- r, ok := a.backend.(holderLockReader)
- if !ok {
+ r := holderReaderFor(a.backend, rt)
+ if r == nil {
return ""
}
a.mu.Lock()
@@ -99,7 +126,8 @@ func (a *Service) ForwardTarget(ctx context.Context, rt registry.Route) string {
}
return "", false
}
- return otherHolder(v, r.self().Ref, a.holders.clock()), true
+ self, _ := boxSelfRef(a.backend)
+ return otherHolder(v, self, a.holders.clock()), true
})
}
@@ -129,7 +157,7 @@ func (a *Service) NoteForward(host string, res edge.ForwardResult) {
case res.Holder == holderNone:
a.holders.drop(host)
case res.Holder != "":
- if r, ok := a.backend.(holderLockReader); ok && res.Holder == r.self().Ref {
+ if self, ok := boxSelfRef(a.backend); ok && res.Holder == self {
a.holders.drop(host)
return
}
@@ -148,7 +176,7 @@ func (a *Service) NoteForward(host string, res edge.ForwardResult) {
// the caller writes today's answer under it. A cancelled request, a legacy
// route and a request that was not forwarded are left as they are.
func (a *Service) answerForwarded(w http.ResponseWriter, r *http.Request, rt registry.Route, err error) bool {
- if !rt.HA || !forwardedHop(r) || errors.Is(err, context.Canceled) {
+ if !forwardedHA(r, rt, err) {
return false
}
var held *errLeaseHeld
@@ -164,3 +192,18 @@ func (a *Service) answerForwarded(w http.ResponseWriter, r *http.Request, rt reg
w.Header().Set(holderHeader, holderNone)
return false
}
+
+// noteNoHolder is answerForwarded for a refusal that never names a holder
+// (a sidecar request's: asleep, or fenced): X-Carlos-Holder: none on a
+// forwarded HA request, and the caller's answer as today.
+func noteNoHolder(w http.ResponseWriter, r *http.Request, rt registry.Route, err error) {
+ if forwardedHA(r, rt, err) {
+ w.Header().Set(holderHeader, holderNone)
+ }
+}
+
+// forwardedHA is whether the refusal err of r is owed the holder
+// diagnostic: r is a verified hop for an HA route, and was not cancelled.
+func forwardedHA(r *http.Request, rt registry.Route, err error) bool {
+ return rt.HA && forwardedHop(r) && !errors.Is(err, context.Canceled)
+}
diff --git a/internal/activator/haforward_test.go b/internal/activator/haforward_test.go
index 9c2d84acd..671b1fee0 100644
--- a/internal/activator/haforward_test.go
+++ b/internal/activator/haforward_test.go
@@ -396,3 +396,77 @@ func TestScheduledTickNeverForwards(t *testing.T) {
t.Fatal("the tick set a holder entry")
}
}
+
+// The production backend is a SplitBackend over the exec backend
+// (host/agent.go): holder discovery goes through it to the exec half, and a
+// unit-backed row, which cannot be born HA here, reads nothing.
+func TestForwardTargetThroughSplitBackend(t *testing.T) {
+ s := haHeldByB(t)
+ a := New(Config{Bucket: s.b.Cfg.Bucket, Idle: time.Hour}, &SplitBackend{Exec: s.b, Unit: &UnitBackend{}}, s.b.Registry)
+ if got := a.ForwardTarget(context.Background(), s.rt); got != "b" {
+ t.Fatalf("ForwardTarget through the split backend = %q, want b", got)
+ }
+ if n := lockGets(s.b, s.rt); n != 1 {
+ t.Fatalf("%d lock reads on a miss, want 1", n)
+ }
+ if got := a.ForwardTarget(context.Background(), s.rt); got != "b" || lockGets(s.b, s.rt) != 1 {
+ t.Fatalf("a hit: %q with %d reads, want b and 1", got, lockGets(s.b, s.rt))
+ }
+ // This box's identity is the exec half's: an answer naming it drops.
+ a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardDone, Status: 503, Holder: "a"})
+ if _, _, found := a.holders.get(s.rt.Host); found {
+ t.Fatal("X-Carlos-Holder naming this box set an entry through the split backend")
+ }
+ unit := s.rt
+ unit.Host, unit.Backing = "unit.example.com", registry.BackingUnit
+ if got := a.ForwardTarget(context.Background(), unit); got != "" {
+ t.Fatalf("a unit-backed row = %q", got)
+ }
+}
+
+// A forwarded sidecar request on an HA route is refused as today, asleep or
+// fenced, and says none; a legacy route's says nothing.
+func TestHoppedSidecarRefusalsSayNone(t *testing.T) {
+ asForwarded(t)
+ cases := []struct {
+ name string
+ setup func(*Service, *fakeBackend)
+ }{
+ {"asleep", func(*Service, *fakeBackend) {}},
+ // BeginSidecarRequest's own fence, past serve's: a held recovery
+ // probe's entry.
+ {"fenced", func(a *Service, _ *fakeBackend) {
+ a.mu.Lock()
+ a.entries["shop.example.com"] = &actEntry{host: "shop.example.com", state: actWaking, ready: make(chan struct{}), probeHeld: true}
+ a.mu.Unlock()
+ }},
+ }
+ sidecar := func(t *testing.T, ha bool, setup func(*Service, *fakeBackend)) *httptest.ResponseRecorder {
+ a, b, _, _ := testActivator(t, time.Minute)
+ setup(a, b)
+ rt := testRoute("shop.example.com")
+ rt.HA = ha
+ req := httptest.NewRequest("GET", "http://shop.example.com/", nil)
+ req.Header.Set(SidecarHeader, "1")
+ rec := httptest.NewRecorder()
+ a.ServeHTTP(rec, req, rt, mustNotProxy(t))
+ return rec
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ today := sidecar(t, false, c.setup)
+ got := sidecar(t, true, c.setup)
+ if got.Code != 503 || got.Code != today.Code || got.Header().Get("Retry-After") != "5" ||
+ today.Header().Get("Retry-After") != "5" || got.Body.String() != today.Body.String() {
+ t.Fatalf("HA %d %q %q, today %d %q %q", got.Code, got.Header().Get("Retry-After"), got.Body,
+ today.Code, today.Header().Get("Retry-After"), today.Body)
+ }
+ if h := got.Header().Get(holderHeader); h != "none" {
+ t.Fatalf("X-Carlos-Holder %q, want none", h)
+ }
+ if _, ok := today.Header()[holderHeader]; ok {
+ t.Fatal("a legacy route's sidecar refusal names a holder")
+ }
+ })
+ }
+}