carlos / platform Public

host: keep group members out of the housekeeper election

Apply the election-level W2b ruling from 2026-11-07. Select never for group references before considering the deployment bucket, and log the reason once at startup.

Exercise the real lease client over a directory store and retain fixed-box acquisition and mesh-key duties. Amend the spec and runbook for fixed contenders.
Implemented-by: Astra (codex)
claude pushed by paul@keymail.dev 938991aa04a53828aaf29d65bd356be55306794b parent 36bff57
4 files changed, +168 −2
  • docs/region-ha-runbook.md +2 −0
  • docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md +2 −2
  • internal/host/housekeeper.go +3 −0
  • internal/host/housekeeper_group_test.go +161 −0

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="d9161f43-a340-47d7-bb14-e237130d6b69"> Agent manager 8a3d302: Paul ruled W2b = A, election-level (00:22Z): group members never contend for the housekeeper lease. Amend spec §7.2/§17, and state in the runbook that at least one fixed box must contend (the platform box is always fixed). Build it as the final step on your branch, record the ruling on #421, and merge with the rest under the standing approval. </paseo-system>

Human

<task-notification> <task-id>a93c7b29ea8c5d53a</task-id> <tool-use-id>toolu_0192MBZdvTHYbKrgcUqJaWuF</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/87a21814-5655-4016-9e7e-41935ee8e96e/tasks/a93c7b29ea8c5d53a.output</output-file> <status>completed</status> <summary>Agent "Census approval review" 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>**Census: approved.** The tip is 36bff577 and the merge base is 3e1a3752. I read every changed non-test function in the four envelopes and what each one reaches. `TestPlan14RootReadCensus` passes at the tip. | unit / envelope | verdict | reason | |---|---|---| | activator `PreparePoolWithdrawal` | approve | Only adds the underlying cause to the pending error. The reads, fence, ownership checks and once-only failure report are unchanged, and the returned error is still non-nil. | | activator `poolWithdrawalProof` | approve | Each pending return now carries its cause (`errors.Join`; a nil cause still gives a pending error). It reaches the same readers and the proof conditions are the same. | | activator `provePoolWithdrawal` | approve | Adds `cause=%v` to the log line. The budget and the stored result are the same. | | edge `serveAssetFar` | approve | `farForward` now goes through `backhaul`, which resolves the owner and the destination again from one snapshot. No new read. The no-key and no-home 503 still apply. | | edge `ServeHTTP` | approve | The door still checks the account and app from `Owner()`, and now passes that name, class and target owner into `backhaulTo`. Held, absent and ownerless names give the same answers as before. | | edge `newWildcardFromEnv` | approve | Serve-only only on a gated box with no DNS provider. `w.dns == nil` stops before `obtain`, which is the only place the CA and DNS are reached. It loads PEMs from the same cert cache and mirror that box already reads for per-host certs. `coversParent` checks the leaf and key. Runs in the edge as user carlos. devbox still refuses with no DNS provider. | | host `runAgent` | approve | The backstop loop now runs without a record view. With a nil view it only sets `backstopFullDue`, the existing full-pass flag. No new read site. | | host `ScanPass` | approve | Calls the hook only when inventory freshness is what blocks it. The `FreshAfter` gate still decides. | | host `complete` | approve | Same nudge, only on stale inventory. Completion gates and exact-ETag deletion are unchanged. | | host `armHADepartures` | approve | Wires `RequestInventory` to an in-memory signal. No store, reader or loop added. | | provision `PoolWithdrawalBackoff.pending` | approve | In memory only: 30 s doubling to the existing 5 min cap, reset when the row or pools change. | | provision `ReconcileConfig.withdrawPools` | approve | `succeeded(rt.Host)` deletes a map entry. Fresh record checks, guarded SQL delete and fence cleanup are unchanged. `errors.As` still reads the outer code. | | envelope internal/activator | approve | `Unwrap` now returns the cause and `Is` matches the pending sentinel. Error codes come from `errors.As`; no consumer tests other sentinels against this error. | | envelope internal/edge | approve | See the holder-name points below. | | envelope internal/host | approve | See the full-walk point below. | | envelope internal/provision | approve | Overlay and chain line match the card's seal, and the census test passes. | **The holder name (`backhaul_holder.go`)** - **Where it comes from:** it is read only from a 503 on the backhaul response. That connection is TLS-verified against the host. The activator's `answerForwarded` sets the name from the lease owner record. - **Can an app set it:** no. `responseModifier` → `stripAppHolder` removes an app's header and trailer on all five proxy arms (replica, forward, tunnel, fleet, socket, addrs). `group_admission` and `assetcatch` delete it too. The static `_headers` allowlist (`headerChecks`) cannot name it. - **Is it validated against signed edges files:** yes. `boxInRegionView` requires the holder and the answering box to both be in the edges-file view, with the same region, placement, data bucket and secrets-key fingerprint, home-eligible, a fresh generation, and not self. - **Scope of the follow:** the remembered holder is keyed by host and bound to the checked owner, capped at 50k entries for 10 min. There is one retry with `retry=false` and no onward forward (the `hopVerified` guard). The receiving box still re-checks the lease. - **Connect-failure fallback:** `backhaulAlternative` keeps only claims with the same name, class, account, app and target, in the failed box's region view. Ownerless legacy claims get no fallback. **Serve-only wildcard manager:** it reads nothing new. It uses an existing cache key family from the gated `certCache`, which is written by the elected issuer box. Non-issuer boxes with a DNS provider already trusted that, and it runs as user carlos, not root. **Departure nudge:** a nudge only re-runs the existing 30 min backstop round: index rebuild plus the full-pass flag. It is limited to one round per 60 s across the process, and at most three after any one piece of departure evidence. It opens no new path, and the departure evidence is not tenant-writable here. One residual cost: a steady stream of new departures could hold the rate at one walk a minute. That is S3 request cost, not new authority. **Census: approved.** Two things to fix that are not census issues: 1. Card wording: the `ServeHTTP` row says the holder follow is "GET/HEAD no body". The code also follows bodiless upgrade requests (`isUpgradeRequest`). That is harmless, but the card should say so. 2. `backhaul` now gates on `State != NameAbsent` where it used `Home()`'s `ok`. This behaves the same: a held name still reaches the empty-target `AdmissionResponse`. The card is `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g2r-fixes/docs/superpowers/notes/census-proposal-region-ha-g2r-fixes.md`. I did not post to #280: this review was read-only and I made no edits.</result> <usage><subagent_tokens>106044</subagent_tokens><tool_uses>30</tool_uses><duration_ms>192207</duration_ms></usage> </task-notification>

diff --git a/docs/region-ha-runbook.md b/docs/region-ha-runbook.md
index 872a1abb0..53cbf4763 100644
--- a/docs/region-ha-runbook.md
+++ b/docs/region-ha-runbook.md
@@ -43,6 +43,8 @@ To roll back, restore the previous host.env and restart `carlos-edge.service`.
Set `/carlos/<env>/<region>/CARLOS_WILDCARD_DOMAINS` for group members to the same value as the region's fixed boxes. This is a required regional SSM parameter for serving their mirrored wildcards. It is not derived because no allowed source lists the region's static wildcard parents without bypassing the current-set limit.
+Group members never contend for the housekeeper lease. At least one fixed box must contend, and the platform box always does. Members need no `CARLOS_DNS_PROVIDER` or DNS token. You can remove the hand-set `/carlos/dev/ie/CARLOS_DNS_PROVIDER` after this release reaches the members. Each member logs `agent: housekeeper: never (group member: deployment-wide duties stay on fixed boxes)` once at startup.
+
Once this branch is released, group members need neither `CARLOS_DNS_PROVIDER` nor a DNS token to serve the mirrored wildcard. Ordering stays with the issuer. In a member's `carlos-edge` journal, look for this serve-only line from `internal/edge/wildcard.go`. Its exact format is:
```text
diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
index f77d42dc5..f999ea780 100644
--- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
+++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
@@ -310,7 +310,7 @@ A box acts on a duty only after an HA acquire, which every duty needs anyway, si
| **Co-spawn sidecars** (`activator.go:17-25`) | Start on the box that woke the instance. | Unchanged: the holder. |
| **`carlos run`:** the record names one picking box (`runexec.go:109-119`) | Any box may pick. | Only the duty owner picks. |
| **WebSockets** | Held on the waking box. | On the holder. A forwarded upgrade rides the backhaul; the plan confirms it does. |
-| **Static sites** and **housekeeper duties** | Every box, and one election. | Unchanged. |
+| **Static sites** and **housekeeper duties** | Every box, and one election. | Static sites are unchanged. Group members never contend for the housekeeper lease. The election runs among fixed boxes. A deployment needs at least one fixed contender; the platform box is always fixed (§12.5). Paul's ruling 2026-11-07 (W2b). |
### 7.3 Keys and tokens (astra-1.6)
@@ -639,7 +639,7 @@ Every other claim package stays inert with claims off, and is left to opportunis
- **`db pull`, `db query --at` and the cross-region db forward:** unchanged. They read the replica, so any box of the region serves them.
- **Litestream #284** (`origin/litestream-oom-284`): restores get more frequent, so land slice A before small group instances.
- **The change index (#336):** one new scope, `control/box-roles`. Edges deletions ride `control/edges`.
-- **The housekeeper election and certificates:** unchanged (S2 §6).
+- **The housekeeper election and certificates:** group members never contend. The election runs among fixed boxes, with at least one fixed contender per deployment. The platform box is always fixed (§12.5). Certificate serving is unchanged (S2 §6). Paul's ruling 2026-11-07 (W2b).
## 18. Request budget (astra-1.16, astra-1.16 r2)
diff --git a/internal/host/housekeeper.go b/internal/host/housekeeper.go
index 944c6cd32..05b538ebf 100644
--- a/internal/host/housekeeper.go
+++ b/internal/host/housekeeper.go
@@ -187,6 +187,9 @@ func newHousekeeper(getenv func(string) string, acquire leaseAcquirer) *housekee
case shouldSkipPublisherElection(getenv):
hk.mode = housekeeperNever
hk.reason = "fleet box — deployment-global duties are a platform-box job; never contending"
+ case groupReferenced(getenv):
+ hk.mode = housekeeperNever
+ hk.reason = "never (group member: deployment-wide duties stay on fixed boxes)"
case getenv("CARLOS_DEPLOYMENT_BUCKET") != "":
// The bucket openDeployStore already adopts from — the duties act on
// its contents, so the lock guarding them belongs in it.
diff --git a/internal/host/housekeeper_group_test.go b/internal/host/housekeeper_group_test.go
new file mode 100644
index 000000000..3e5749b52
--- /dev/null
+++ b/internal/host/housekeeper_group_test.go
@@ -0,0 +1,161 @@
+package host
+
+import (
+ "context"
+ "errors"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "strings"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/edge"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+func TestHousekeeperGroupMode(t *testing.T) {
+ for _, tt := range []struct {
+ name, reference, bucket, dir, hostname string
+ want housekeeperMode
+ }{
+ {"group with bucket", "group", "deployment", "", "fixed-looking", housekeeperNever},
+ {"group with directory", "group", "", "deployment", "", housekeeperNever},
+ {"group without store", "group", "", "", "", housekeeperNever},
+ {"trimmed group marker", " group ", "deployment", "", "", housekeeperNever},
+ {"fixed with group-looking hostname", "", "deployment", "", "g-0123456789abcdef0123", housekeeperElect},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ hk := newHousekeeper(envFunc(map[string]string{
+ "CARLOS_BOX_REFERENCE": tt.reference, "CARLOS_DEPLOYMENT_BUCKET": tt.bucket,
+ "CARLOS_DEPLOYMENT_DIR": tt.dir, "HOSTNAME": tt.hostname,
+ }), acquireDeploymentLease)
+ if hk.mode != tt.want {
+ t.Errorf("mode = %v, want %v", hk.mode, tt.want)
+ }
+ })
+ }
+}
+
+// The transport serves the real lease client over a directory store. Only
+// S3 is replaced; mode selection, acquisition, release and duty gates run.
+func housekeeperDirEndpoint(t *testing.T) (*release.DirStore, *atomic.Int64) {
+ t.Helper()
+ store := release.NewDirStore(t.TempDir())
+ writes := &atomic.Int64{}
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ key := strings.TrimPrefix(r.URL.Path, "/deployment/")
+ var body []byte
+ var etag string
+ var err error
+ switch r.Method {
+ case http.MethodGet:
+ body, etag, err = store.Get(r.Context(), key)
+ case http.MethodPut:
+ writes.Add(1)
+ body, err = io.ReadAll(r.Body)
+ if err == nil {
+ etag, err = store.Put(r.Context(), key, body, strings.Trim(r.Header.Get("If-Match"), `"`))
+ }
+ body = nil
+ case http.MethodDelete:
+ err = store.DeleteIfMatch(r.Context(), key, strings.Trim(r.Header.Get("If-Match"), `"`))
+ default:
+ w.WriteHeader(http.StatusMethodNotAllowed)
+ return
+ }
+ if err != nil {
+ status, code := http.StatusInternalServerError, "InternalError"
+ if errors.Is(err, os.ErrNotExist) {
+ status, code = http.StatusNotFound, "NoSuchKey"
+ } else if errors.Is(err, release.ErrCASConflict) {
+ status, code = http.StatusPreconditionFailed, "PreconditionFailed"
+ }
+ w.Header().Set("Content-Type", "application/xml")
+ w.WriteHeader(status)
+ _, _ = io.WriteString(w, "<Error><Code>"+code+"</Code></Error>")
+ return
+ }
+ if etag != "" {
+ w.Header().Set("ETag", `"`+etag+`"`)
+ }
+ _, _ = w.Write(body)
+ }))
+ t.Cleanup(srv.Close)
+ for key, value := range map[string]string{
+ "CARLOS_S3_ENDPOINT": srv.URL, "CARLOS_DEPLOYMENT_BUCKET": "deployment",
+ "CARLOS_DEPLOYMENT_DIR": "", "CARLOS_FLEET": "",
+ "AWS_ACCESS_KEY_ID": "test", "AWS_SECRET_ACCESS_KEY": "test", "AWS_SESSION_TOKEN": "",
+ "AWS_PROFILE": "", "AWS_CONFIG_FILE": "/nonexistent", "AWS_SHARED_CREDENTIALS_FILE": "/nonexistent",
+ "AWS_EC2_METADATA_DISABLED": "true", "AWS_REGION": "us-east-1",
+ } {
+ t.Setenv(key, value)
+ }
+ return store, writes
+}
+
+func TestHousekeeperGroupNeverWritesLease(t *testing.T) {
+ store, writes := housekeeperDirEndpoint(t)
+ t.Setenv("CARLOS_BOX_REFERENCE", "group")
+ buf := captureRacyLog(t)
+ hk := newHousekeeper(os.Getenv, acquireDeploymentLease)
+ old := theHousekeeper.Swap(hk)
+ t.Cleanup(func() { theHousekeeper.Store(old) })
+ // Run to completion, so a missing exclusion has time to acquire and
+ // release a real lease. Counting PUTs also catches a deleted lock.
+ ctx, cancel := context.WithTimeout(t.Context(), 250*time.Millisecond)
+ defer cancel()
+ hk.run(ctx)
+ if n := writes.Load(); n != 0 {
+ t.Errorf("group member wrote %d lease requests, want none", n)
+ }
+ if housekeeperContends() || housekeeperHeld() {
+ t.Error("group member contends or holds the issuer lease")
+ }
+ if ctx, held := housekeeperGate(); held || ctx != nil {
+ t.Errorf("issuer gate = (%v, %v), want (nil, false)", ctx, held)
+ }
+ runHousekeeperDuties(housekeeperGate, housekeeperDuty{"mesh key mint", func(ctx context.Context) error {
+ return edge.MintMeshKey(ctx, store)
+ }})
+ for _, key := range []string{"control/housekeeper-lease/lock.json", "control/edge-mesh-key"} {
+ if _, _, err := store.Get(t.Context(), key); !errors.Is(err, os.ErrNotExist) {
+ t.Errorf("group member created %s: %v", key, err)
+ }
+ }
+ const line = "agent: housekeeper: never (group member: deployment-wide duties stay on fixed boxes)"
+ if n := strings.Count(buf.String(), line); n != 1 {
+ t.Errorf("startup reason logged %d times, want once; log: %s", n, buf.String())
+ }
+}
+
+func TestHousekeeperFixedBoxWritesLease(t *testing.T) {
+ store, writes := housekeeperDirEndpoint(t)
+ t.Setenv("CARLOS_BOX_REFERENCE", "")
+ old := theHousekeeper.Load()
+ t.Cleanup(func() { theHousekeeper.Store(old) })
+ stop := startHousekeeper()
+ t.Cleanup(stop)
+ waitFor(t, "fixed box to hold the lease", housekeeperHeld)
+ if !housekeeperContends() {
+ t.Fatal("fixed box does not contend")
+ }
+ if _, _, err := store.Get(t.Context(), "control/housekeeper-lease/lock.json"); err != nil {
+ t.Fatalf("fixed box did not write the lease: %v", err)
+ }
+ if n := writes.Load(); n != 1 {
+ t.Fatalf("fixed box wrote %d lease requests, want one acquisition", n)
+ }
+ runHousekeeperDuties(housekeeperGate, housekeeperDuty{"mesh key mint", func(ctx context.Context) error {
+ return edge.MintMeshKey(ctx, store)
+ }})
+ if _, _, err := store.Get(t.Context(), "control/edge-mesh-key"); err != nil {
+ t.Fatalf("fixed holder did not mint the mesh key: %v", err)
+ }
+ stop()
+ if _, _, err := store.Get(t.Context(), "control/housekeeper-lease/lock.json"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("fixed box did not release the lease: %v", err)
+ }
+}