carlos / platform Public

ha: publish ingress aliases and regional names at agent start

Build alias and regional ingress projections within the bounded startup
retry schedule. Serialize with the existing alias passes, retry partial
folds, and verify forwarding before the instances loop runs.
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 07be08786d84443696656951f386f61fc01b6833 parent f273661
4 files changed, +156 −32
  • docs/superpowers/notes/2026-11-06-region-ha-g2-follow-ups.md +6 −0
  • internal/host/agent.go +26 −6
  • internal/host/haingress.go +13 −1
  • internal/host/haingress_startup_test.go +111 −25

Intent

Human

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

diff --git a/docs/superpowers/notes/2026-11-06-region-ha-g2-follow-ups.md b/docs/superpowers/notes/2026-11-06-region-ha-g2-follow-ups.md
index f5d61e72d..99eaa4cb1 100644
--- a/docs/superpowers/notes/2026-11-06-region-ha-g2-follow-ups.md
+++ b/docs/superpowers/notes/2026-11-06-region-ha-g2-follow-ups.md
@@ -110,6 +110,12 @@ line numbers; the code paths below name the current files.
Finish: record the grants, sink readbacks and page-delivery evidence on
the G3 card. L is the observed lease expiry.
+12. **Instance-control: isolation probe at startup.**
+ Instance-control's isolation probe caches a failed first probe for five
+ minutes if the control service starts before the edge
+ (`internal/instancectl/server.go`, `ProbeEvery`). Production socket
+ activation avoids this ordering.
+
## Seeded escalation locations
If stopping rule 2 selects simulation, extend
diff --git a/internal/host/agent.go b/internal/host/agent.go
index 01040f4b9..a420086a1 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -1006,7 +1006,7 @@ func runAgent(args []string, buildClaims ClaimFactory) {
// Unset CARLOS_CHANGE_INDEX, or a fleet box: nothing.
v := armChangeIndex(agentCtx, os.Getenv, openDeployStore)
go func() {
- runHAIngressStartup(agentCtx, openDeployStore, boxJudge)
+ runHAIngressStartup(agentCtx, openDeployStore, boxJudge, reg)
if v != nil && agentCtx.Err() == nil {
recordViewBackstopLoop(agentCtx, v)
}
@@ -1365,8 +1365,8 @@ func servingBuildOf(svc *activator.Service) servingBuild {
}
}
-// aliasPassMu serializes the two alias legs (the fast converge pass and the
-// five-minute instances pass). They read and rewrite the same three tables,
+// aliasPassMu serializes startup, fast convergence and the five-minute
+// instances alias pass. They read and rewrite the same three tables,
// and the domain confirmed time assumes passes finish in the order they
// started: an older pass finishing after a newer one could write rows older
// than the time the newer one recorded.
@@ -1385,8 +1385,24 @@ var aliasPassMu sync.Mutex
// home): a regional claim (#447) derives its regional_domains rows for this
// region's placement.
func aliasPassReporting(ctx context.Context, store release.Store, reg *registry.Registry, cache *domains.ClaimCache, auth *assetAuthority, region string) error {
- aliasPassMu.Lock()
+ _, err := aliasPassReportingComplete(ctx, store, reg, cache, auth, region)
+ return err
+}
+
+// aliasPassReportingComplete also returns completeness so startup retries a
+// partial fold even when reconciliation kept rows without returning an error.
+func aliasPassReportingComplete(ctx context.Context, store release.Store, reg *registry.Registry, cache *domains.ClaimCache, auth *assetAuthority, region string) (bool, error) {
+ for !aliasPassMu.TryLock() {
+ select {
+ case <-ctx.Done():
+ return false, ctx.Err()
+ case <-time.After(10 * time.Millisecond):
+ }
+ }
defer aliasPassMu.Unlock()
+ if err := ctx.Err(); err != nil {
+ return false, err
+ }
start := auth.passBegin()
defer auth.passEnd()
deploymentRoutes, routesWhole := edgesfile.DeploymentRoutesComplete(ctx, store, time.Now())
@@ -1403,14 +1419,18 @@ func aliasPassReporting(ctx context.Context, store release.Store, reg *registry.
auth.aliasPass(start, rep)
boxHAIngress.publishRegional(nil, false)
boxHAIngress.publishAliases(nil, false)
- return fmt.Errorf("alias pass: %w", err)
+ return false, fmt.Errorf("alias pass: %w", err)
}
rep.FleetRefused = refused
err = domains.ReconcileAliasesReport(ctx, store, reg, time.Now, deploymentRoutes, cache, &rep)
+ if ctx.Err() != nil {
+ err = errors.Join(err, ctx.Err())
+ rep.Complete = false
+ }
auth.aliasPass(start, rep)
boxHAIngress.publishRegional(rep.RegionalIngress, err == nil && rep.Complete)
boxHAIngress.publishAliases(rep.AliasIngress, err == nil && rep.Complete)
- return err
+ return rep.Complete && err == nil, err
}
// statusSocketProbe is the kernel-table probe the status loop hands
diff --git a/internal/host/haingress.go b/internal/host/haingress.go
index 92a8115fe..157afdaba 100644
--- a/internal/host/haingress.go
+++ b/internal/host/haingress.go
@@ -138,7 +138,7 @@ func wireHAIngressScan(ctx context.Context, s release.Store, cfg *provision.Reco
// runHAIngressStartup finishes after success or three retries. The existing
// instances and record-view loops own every later refresh.
-func runHAIngressStartup(ctx context.Context, open func(context.Context) (release.Store, error), judge *provision.LifetimeJudge) {
+func runHAIngressStartup(ctx context.Context, open func(context.Context) (release.Store, error), judge *provision.LifetimeJudge, reg *registry.Registry) {
for _, delay := range []time.Duration{0, 2 * time.Second, 5 * time.Second, 10 * time.Second} {
if delay != 0 {
timer := time.NewTimer(delay)
@@ -153,7 +153,19 @@ func runHAIngressStartup(ctx context.Context, open func(context.Context) (releas
return
}
attempt, cancel := context.WithTimeout(ctx, 5*time.Second)
+ attempt = provision.WithLifetimes(attempt, judge)
err := refreshHAIngressAtStart(attempt, open, judge)
+ if err == nil {
+ var store release.Store
+ store, err = open(attempt)
+ if err == nil {
+ var complete bool
+ complete, err = aliasPassReportingComplete(attempt, store, reg, &aliasClaimCache, boxAssetAuthority, provisionTickConfig(os.Getenv).Region)
+ if !complete {
+ err = errors.Join(err, errors.New("HA ingress: incomplete startup alias pass"))
+ }
+ }
+ }
cancel()
if err == nil {
return
diff --git a/internal/host/haingress_startup_test.go b/internal/host/haingress_startup_test.go
index 71de11028..55e3d5cd3 100644
--- a/internal/host/haingress_startup_test.go
+++ b/internal/host/haingress_startup_test.go
@@ -3,9 +3,13 @@ package host
import (
"context"
"crypto/ed25519"
+ "crypto/rand"
+ "crypto/tls"
"crypto/x509"
+ "encoding/json"
"fmt"
"io"
+ "math/big"
"net"
"net/http"
"net/http/httptest"
@@ -17,6 +21,7 @@ import (
_ "unsafe"
"github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/domains"
"github.com/carlosframework/platform/internal/edge"
"github.com/carlosframework/platform/internal/hafresh"
"github.com/carlosframework/platform/internal/lease/locktest"
@@ -37,17 +42,39 @@ func TestHAIngressStartupWiring(t *testing.T) {
t.Fatal(err)
}
body := string(src)
- start := strings.Index(body, "runHAIngressStartup(agentCtx, openDeployStore, boxJudge)")
- if strings.Count(body, "runHAIngressStartup(agentCtx, openDeployStore, boxJudge)") != 1 || start < 0 || start < strings.Index(body, "armChangeIndex(agentCtx,") || start > strings.Index(body, "go instancesLoop(") {
+ start := strings.Index(body, "runHAIngressStartup(agentCtx, openDeployStore, boxJudge, reg)")
+ if strings.Count(body, "runHAIngressStartup(agentCtx, openDeployStore, boxJudge, reg)") != 1 || start < 0 || start < strings.Index(body, "armChangeIndex(agentCtx,") || start > strings.Index(body, "go instancesLoop(") {
t.Fatal("agent does not build the ingress projection at startup after arming the index and before starting instancesLoop")
}
}
func TestHAIngressStartupForwards(t *testing.T) {
+ testHAIngressStartupForwards(t, false)
+}
+
+func TestHAIngressStartupNames(t *testing.T) {
+ testHAIngressStartupForwards(t, true)
+}
+
+func testHAIngressStartupForwards(t *testing.T, names bool) {
+ failures := []string{"", "accounts/"}
+ if names {
+ failures = append(failures, domains.ClaimsPrefix, "control/edges/")
+ }
for _, indexed := range []bool{false, true} {
- for _, fail := range []bool{false, true} {
- t.Run(fmt.Sprintf("indexed=%v/failure=%v", indexed, fail), func(t *testing.T) {
+ for _, failure := range failures {
+ t.Run(fmt.Sprintf("indexed=%v/failure=%s", indexed, failure), func(t *testing.T) {
disarmView(t)
+ oldAliases := boxHAIngress.aliases.Load()
+ boxHAIngress.aliases.Store(nil)
+ aliasClaimCache.Reset()
+ oldAuthority := boxAssetAuthority
+ boxAssetAuthority = newAssetAuthority(nil)
+ t.Cleanup(func() {
+ boxHAIngress.aliases.Store(oldAliases)
+ aliasClaimCache.Reset()
+ boxAssetAuthority = oldAuthority
+ })
oldRoutes, oldNames, oldEpoch := boxHAIngress.routes.Load(), boxHAIngress.regional.Load(), boxHAIngress.epoch
boxHAIngress.routes.Store(nil)
boxHAIngress.regional.Store(nil)
@@ -66,6 +93,23 @@ func TestHAIngressStartupForwards(t *testing.T) {
if err := provision.CreateRecord(t.Context(), w.live, rec); err != nil {
t.Fatal(err)
}
+ hosts := []string{rec.Host}
+ if names {
+ hosts = []string{"alias.example.net", "regional.example.net"}
+ for _, claim := range []domains.Claim{
+ {Schema: 1, Host: hosts[0], Route: rec.Host, Account: rec.Account, App: rec.App},
+ {Schema: 2, Host: hosts[1], Route: rec.Host, Account: rec.Account, App: rec.App, Placements: []domains.Placement{{Region: "", Host: rec.Host}}},
+ } {
+ claim.CreatedAt = time.Now().UTC().Format(time.RFC3339)
+ data, err := json.Marshal(claim)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := w.live.Put(t.Context(), domains.ClaimKey(claim.Host), data, ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
if indexed {
armView(t, w.live)
}
@@ -90,20 +134,33 @@ func TestHAIngressStartupForwards(t *testing.T) {
}
t.Setenv("CARLOS_POOLS", "other")
stale := registry.Route{Host: rec.Host, Account: rec.Account, App: rec.App, Pool: rec.Pool, Hibernate: true, Socket: "/unused"}
- if err := reg.Upsert(stale); err != nil {
- t.Fatal(err)
+ if !names {
+ if err := reg.Upsert(stale); err != nil {
+ t.Fatal(err)
+ }
}
if _, err := w.live.Put(t.Context(), "control/edge-mesh-key", []byte(strings.Repeat("a", 64)), ""); err != nil {
t.Fatal(err)
}
var deliveries atomic.Int32
- peer := httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
- if r.Header.Get("X-Carlos-Hop-Auth") == "" || r.Host != rec.Host {
+ peer := httptest.NewUnstartedServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
+ if r.Header.Get("X-Carlos-Hop-Auth") == "" || (r.Host != rec.Host && r.Host != "alias.example.net" && r.Host != "regional.example.net") {
t.Errorf("unsigned or wrong host: %s %v", r.Host, r.Header)
}
deliveries.Add(1)
io.WriteString(rw, "forwarded")
}))
+ pub, key, err := ed25519.GenerateKey(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cert := &x509.Certificate{SerialNumber: big.NewInt(1), DNSNames: []string{rec.Host, "*.example.net"}, NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(time.Hour), KeyUsage: x509.KeyUsageDigitalSignature, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}}
+ der, err := x509.CreateCertificate(rand.Reader, cert, cert, pub, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ peer.TLS = &tls.Config{Certificates: []tls.Certificate{{Certificate: [][]byte{der}, PrivateKey: key}}}
+ peer.StartTLS()
defer peer.Close()
oldDial, oldRoots := startupForwardDial, startupBackhaulRoots
startupBackhaulRoots = x509.NewCertPool()
@@ -132,36 +189,39 @@ func TestHAIngressStartupForwards(t *testing.T) {
if !snapshot.Usable || !snapshot.LocalDenied || len(snapshot.Serving) != 1 || snapshot.Serving[0].BoxID != "holder" {
t.Fatalf("startup peer view: %+v", snapshot)
}
- request := func() *httptest.ResponseRecorder {
- r := httptest.NewRequest(http.MethodPost, "https://"+rec.Host+"/", strings.NewReader("once"))
+ request := func(host string) *httptest.ResponseRecorder {
+ r := httptest.NewRequest(http.MethodPost, "https://"+host+"/", strings.NewReader("once"))
rw := httptest.NewRecorder()
e.ServeHTTP(rw, r)
return rw
}
- if fail {
- w.live.setFailList("accounts/")
+ if failure != "" {
+ w.live.setFailList(failure)
}
ctx, cancel := context.WithCancel(t.Context())
done := make(chan struct{})
go func() {
defer close(done)
- runHAIngressStartup(ctx, func(context.Context) (release.Store, error) { return w.live, nil }, newBoxJudge(claimsOffEnv))
+ runHAIngressStartup(ctx, func(context.Context) (release.Store, error) { return startupAliasStore{w.live}, nil }, newBoxJudge(claimsOffEnv), reg)
}()
defer func() { cancel(); <-done }()
start := time.Now()
- if fail {
+ if failure != "" {
deadline := time.Now().Add(time.Second)
- for boxHAIngress.routes.Load() == nil && time.Now().Before(deadline) {
+ for (boxHAIngress.routes.Load() == nil || ((failure == domains.ClaimsPrefix || failure == "control/edges/") && boxHAIngress.aliases.Load() == nil)) && time.Now().Before(deadline) {
time.Sleep(time.Millisecond)
}
if boxHAIngress.routes.Load() == nil {
t.Fatal("initial failure was not published")
}
- if rw := request(); rw.Code != 503 || rw.Header().Get("X-Carlos-Holder") != "none" || deliveries.Load() != 0 {
- t.Fatalf("failed projection served: %d", rw.Code)
- }
- if rt, _ := boxHAIngress.lookup(rec.Host); rt.HA {
- t.Fatal("failed projection usable")
+ for _, host := range hosts {
+ rw := request(host)
+ if (rw.Code != 404 && rw.Code != 503) || (!names && (rw.Code != 503 || rw.Header().Get("X-Carlos-Holder") != "none")) || deliveries.Load() != 0 {
+ t.Fatalf("failed projection served %s: %d", host, rw.Code)
+ }
+ if rt, _ := boxHAIngress.lookup(host); rt.HA {
+ t.Fatalf("failed projection usable for %s", host)
+ }
}
w.live.setFailList("")
}
@@ -173,14 +233,19 @@ func TestHAIngressStartupForwards(t *testing.T) {
if rt, ok := boxHAIngress.lookup(rec.Host); !ok || !rt.HA {
t.Fatalf("startup projection missing: %+v %v", rt, ok)
}
- rw := request()
- if rw.Code != 200 || rw.Body.String() != "forwarded" || deliveries.Load() != 1 {
- t.Fatalf("startup forward: %d %q deliveries=%d", rw.Code, rw.Body.String(), deliveries.Load())
+ for _, host := range hosts {
+ t.Run(host, func(t *testing.T) {
+ before := deliveries.Load()
+ rw := request(host)
+ if rw.Code != 200 || rw.Body.String() != "forwarded" || deliveries.Load() != before+1 {
+ t.Fatalf("startup forward %s: %d %q deliveries=%d", host, rw.Code, rw.Body.String(), deliveries.Load()-before)
+ }
+ })
}
if time.Since(start) >= 10*time.Second {
t.Fatal("forward took 10 seconds")
}
- if rows, err := reg.List(); err != nil || len(rows) != 1 || rows[0].Host != stale.Host || rows[0].HA || rows[0].Provisioned {
+ if rows, err := reg.List(); err != nil || (names && len(rows) != 0) || (!names && (len(rows) != 1 || rows[0].Host != stale.Host || rows[0].HA || rows[0].Provisioned)) {
t.Fatalf("ingress acquired local routes: %+v %v", rows, err)
}
for _, req := range fx.Requests() {
@@ -201,7 +266,7 @@ func TestHAIngressStartupCancellation(t *testing.T) {
calls++
cancel()
return nil, fmt.Errorf("store unavailable")
- }, nil)
+ }, nil, nil)
if calls != 1 {
t.Fatalf("cancelled startup opened store %d times", calls)
}
@@ -221,3 +286,24 @@ func TestHAIngressStartupLockDeadline(t *testing.T) {
t.Fatalf("startup lock deadline: %v, %s", err, time.Since(start))
}
}
+
+func TestHAIngressStartupAliasLockDeadline(t *testing.T) {
+ aliasPassMu.Lock()
+ defer aliasPassMu.Unlock()
+ ctx, cancel := context.WithTimeout(t.Context(), 30*time.Millisecond)
+ defer cancel()
+ start := time.Now()
+ complete, err := aliasPassReportingComplete(ctx, nil, nil, &aliasClaimCache, boxAssetAuthority, "")
+ if complete || err != context.DeadlineExceeded || time.Since(start) > time.Second {
+ t.Fatalf("startup alias lock deadline: complete=%v err=%v elapsed=%s", complete, err, time.Since(start))
+ }
+}
+
+type startupAliasStore struct{ *ciCountingStore }
+
+func (s startupAliasStore) ListMod(ctx context.Context, prefix string) ([]release.KeyMod, error) {
+ if s.listFails(prefix) {
+ return nil, fmt.Errorf("list mods refused")
+ }
+ return s.DirStore.ListMod(ctx, prefix)
+}