domains: an unread claim keeps its rows; never shrink on incomplete
A claim the listing shows but whose body the alias pass did not read was deleted from route_aliases, wildcard_domains and route_paths; only the regional table kept it. On 2026-11-07 the v0.34.14 flagship roll hit this: annie's first alias pass after the edge restart ran under the startup HA ingress 5 s deadline (98c43eea) with a cold ClaimCache, 75 claim GETs timed out, and every custom-domain row was deleted. The next pass re-inserted them with a blank dns_status, so the edges file withheld 58 hosts for about a minute and other edges answered 404. Rows tied to an unread claim (plain alias, catch-all star, instance names under an unread instance catch-all, wildcard parent within the cap, path prefixes) are now kept exactly as they are, stamps included. A claim that left the listing still removes its rows on the same pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+268
−10
internal/domains/aliases.go+61 −10internal/domains/aliases_unread_keep_test.go+128 −0internal/host/edgesfile_unread_claims_test.go+79 −0
diff --git a/internal/domains/aliases.go b/internal/domains/aliases.go| index 2a6395b52..012a1cd0c 100644 |
| --- a/internal/domains/aliases.go |
| +++ b/internal/domains/aliases.go |
| @@ -771,8 +771,25 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| }, reg, now) { |
| incomplete = true |
| } |
| + // A row whose claim the listing shows but whose body this pass did not |
| + // read (a failed GET, an unparseable body, a not-found) was not decided |
| + // on, so it is kept exactly as it is, box stamps included, in every |
| + // pass-owned table below; relevantDropped above has already made the |
| + // pass incomplete for it. Deleting it instead is the 2026-11-07 flagship |
| + // shrink: an edge restart's first pass ran out of time on 75 claim GETs, |
| + // dropped every custom domain's row, and the next pass re-inserted them |
| + // with a blank dns_status, which the edges file withholds until the DNS |
| + // sweep comes round again. A claim that has left the listing is not in |
| + // dropped, so a detach still removes its rows on the same pass. |
| + unread := make(map[string]bool, len(dropped)) |
| + for _, d := range dropped { |
| + unread[d.host] = true |
| + } |
| for _, a := range existing { |
| if !desired[a.Alias] { |
| + if aliasClaimUnread(a.Alias, unread) { |
| + continue |
| + } |
| if err := reg.DeleteAlias(a.Alias); err != nil { |
| log.Printf("domains: remove alias %s: %v", a.Alias, err) |
| incomplete = true |
| @@ -780,16 +797,10 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| } |
| } |
| - // regional_domains is wholly pass-owned too, with one exception: a row |
| - // whose claim the listing shows but whose body this pass did not read |
| - // (a failed GET, an unparseable body, a not-found) is kept exactly as |
| - // it is, and the pass is incomplete. Reload judges a kept row again |
| - // against the routes it serves (spec §7.3), so keeping it never binds a |
| - // target that has stopped qualifying. |
| - unread := make(map[string]bool, len(dropped)) |
| - for _, d := range dropped { |
| - unread[d.host] = true |
| - } |
| + // regional_domains is wholly pass-owned too, with the same exception |
| + // for an unread claim's rows. Reload judges a kept row again against |
| + // the routes it serves (spec §7.3), so keeping it never binds a target |
| + // that has stopped qualifying. |
| if writeRegional(reg, existingRegional, desiredRegional, unread) { |
| incomplete = true |
| } |
| @@ -831,6 +842,22 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| wildCount++ |
| desiredWild[w.Host] = w |
| } |
| + // Any other unread claim's wildcard parent is kept as it is (the alias |
| + // loop's rule), within the same per-box cap. |
| + for _, w := range existingWild { |
| + if _, ok := desiredWild[w.Host]; ok || !unread[w.Host] { |
| + continue |
| + } |
| + if _, regional := keptRegional[w.Host]; regional { |
| + continue // decided by the regional rule above |
| + } |
| + if wildCount >= maxWildcardDomains { |
| + log.Printf("domains: wildcard %s dropped: per-box cap %d reached", w.Host, maxWildcardDomains) |
| + continue |
| + } |
| + wildCount++ |
| + desiredWild[w.Host] = w |
| + } |
| for h, w := range desiredWild { |
| cur := false |
| for _, e := range existingWild { |
| @@ -872,6 +899,9 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| } |
| for _, p := range existingPaths { |
| if _, ok := desiredPaths[p.Host+"\x00"+p.Prefix]; !ok { |
| + if unread[p.Host] { |
| + continue // its claim was not read this pass: kept as it is |
| + } |
| if err := reg.DeletePath(p.Host, p.Prefix); err != nil { |
| log.Printf("domains: remove path %s/%s: %v", p.Host, p.Prefix, err) |
| incomplete = true |
| @@ -1035,3 +1065,24 @@ func deriveHAIngressAliases(c Claim, local map[string]registry.Route, deployment |
| add("*." + c.Host) |
| } |
| } |
| + |
| +// aliasClaimUnread reports whether the claim an alias row came from is in |
| +// unread (listed this pass, body not read). A row's claim is found from its |
| +// name alone: a plain alias is its claim's host, a catch-all "*.<host>" row |
| +// is <host>'s Wildcard claim, and an instance name "<label>.<parent>" is the |
| +// "*.<parent>" instance catch-all claim's. |
| +func aliasClaimUnread(alias string, unread map[string]bool) bool { |
| + if len(unread) == 0 { |
| + return false |
| + } |
| + if unread[alias] { |
| + return true |
| + } |
| + if host, ok := strings.CutPrefix(alias, "*."); ok { |
| + return unread[host] |
| + } |
| + if _, parent, ok := strings.Cut(alias, "."); ok { |
| + return unread["*."+parent] |
| + } |
| + return false |
| +} |
diff --git a/internal/domains/aliases_unread_keep_test.go b/internal/domains/aliases_unread_keep_test.go| new file mode 100644 |
| index 000000000..03e83bde7 |
| --- /dev/null |
| +++ b/internal/domains/aliases_unread_keep_test.go |
| @@ -0,0 +1,128 @@ |
| +package domains |
| + |
| +import ( |
| + "context" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// unreadKeysStore fails GET of every listed key in keys with a transient |
| +// (non-NotExist) error, the way a bucket read cut off by the pass's deadline |
| +// reads. The listing still shows the keys. |
| +type unreadKeysStore struct { |
| + *release.DirStore |
| + keys map[string]bool |
| +} |
| + |
| +func (u unreadKeysStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if u.keys[key] { |
| + return nil, "", context.DeadlineExceeded |
| + } |
| + return u.DirStore.Get(ctx, key) |
| +} |
| + |
| +// TestUnreadClaimsKeepTheirRows is the 2026-11-07 flagship shrink (v0.34.14 |
| +// annie). A box's first alias pass after an edge restart ran under the |
| +// startup HA ingress deadline with a cold ClaimCache; 75 claim GETs ran out |
| +// of time, and the pass deleted every row those claims had derived. The |
| +// next pass re-inserted them with a blank dns_status, and the edges file |
| +// withheld every custom domain until the DNS sweep stamped them again, about |
| +// a minute later. Other edges served 404 for those names for that minute. |
| +// |
| +// A claim the listing shows but whose body this pass did not read was not |
| +// decided on. Every row it derived (plain alias, catch-all alias, wildcard |
| +// parent, path prefix, instance alias under its catch-all) stays exactly as |
| +// it is, box stamps included, and the pass reports incomplete. The control |
| +// at the end shows a claim that has actually left the listing still loses |
| +// its row on the same kind of pass. |
| +func TestUnreadClaimsKeepTheirRows(t *testing.T) { |
| + e := newAliasEnv(t) |
| + addRoute(t, e.reg, "shop.example.com", "abc", "shop") |
| + addRoute(t, e.reg, "api.example.com", "abc", "api") |
| + putClaim(t, e.store, Claim{Host: "www.example.com", Account: "abc", App: "shop", Route: "shop.example.com"}) |
| + putClaim(t, e.store, Claim{Host: "gone.example.com", Account: "abc", App: "shop", Route: "shop.example.com"}) |
| + putClaim(t, e.store, Claim{Host: "wild.example.org", Account: "abc", App: "shop", Route: "shop.example.com", Wildcard: true, Catchall: true}) |
| + putClaim(t, e.store, Claim{Host: "shop.example.com", Account: "abc", App: "shop", Paths: map[string]string{"api": "api.example.com"}}) |
| + // The instance catch-all: the apex stays readable, the catch-all does not. |
| + putClaim(t, e.store, Claim{Host: "example.net", Account: "abc", App: "shop-site"}) |
| + putClaim(t, e.store, Claim{Host: "*.example.net", Account: "abc", App: "shop", Instances: true}) |
| + addInstance(t, e.reg, "acme.abc.carlos.example.net", "acme", "abc", "shop") |
| + |
| + for _, cached := range []bool{false, true} { |
| + var cache *ClaimCache |
| + if cached { |
| + cache = &ClaimCache{} |
| + } |
| + if rep, err := e.pass(e.store, known(), cache); err != nil || !rep.Complete { |
| + t.Fatalf("cache=%v control: complete=%v err=%v", cached, rep.Complete, err) |
| + } |
| + } |
| + aliases := []string{"www.example.com", "gone.example.com", "*.wild.example.org", "acme.example.net"} |
| + got := aliasMap(t, e.reg) |
| + for _, a := range aliases { |
| + if _, ok := got[a]; !ok { |
| + t.Fatalf("setup: alias %s not derived (have %v)", a, got) |
| + } |
| + if err := e.reg.SetAliasDNSStatus(a, "pointing", 1755000000); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + |
| + unread := unreadKeysStore{e.store, map[string]bool{ |
| + ClaimKey("www.example.com"): true, |
| + ClaimKey("gone.example.com"): true, |
| + ClaimKey("wild.example.org"): true, |
| + ClaimKey("shop.example.com"): true, |
| + ClaimKey("*.example.net"): true, |
| + }} |
| + for _, cached := range []bool{false, true} { |
| + var cache *ClaimCache |
| + if cached { |
| + cache = &ClaimCache{} // cold, as after a restart |
| + } |
| + rep, err := e.pass(unread, known(), cache) |
| + if err != nil { |
| + t.Fatalf("cache=%v: unread claims must not fail the pass: %v", cached, err) |
| + } |
| + if rep.Complete { |
| + t.Fatalf("cache=%v: the pass hid unread claims as complete", cached) |
| + } |
| + got := aliasMap(t, e.reg) |
| + for _, a := range aliases { |
| + row, ok := got[a] |
| + if !ok { |
| + t.Fatalf("cache=%v: alias %s was deleted on a pass that never read its claim", cached, a) |
| + } |
| + if row.DNSStatus != "pointing" { |
| + t.Fatalf("cache=%v: alias %s lost its DNS stamp (%q): the row was rewritten", cached, a, row.DNSStatus) |
| + } |
| + } |
| + wds, err := e.reg.ListWildcardDomains() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(wds) != 1 || wds[0].Host != "wild.example.org" { |
| + t.Fatalf("cache=%v: wildcard parent not kept: %+v", cached, wds) |
| + } |
| + paths, err := e.reg.ListPaths() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(paths) != 1 || paths[0].Host != "shop.example.com" || paths[0].Prefix != "api" { |
| + t.Fatalf("cache=%v: path prefix not kept: %+v", cached, paths) |
| + } |
| + } |
| + |
| + // Control: a claim that has left the listing is a detach, unread or not. |
| + deleteClaim(t, e.store, "gone.example.com") |
| + if _, err := e.pass(unread, known(), nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, ok := aliasMap(t, e.reg)["gone.example.com"]; ok { |
| + t.Fatal("a detached claim's alias was kept") |
| + } |
| + if _, ok := aliasMap(t, e.reg)["www.example.com"]; !ok { |
| + t.Fatal("the unread claim's alias was dropped alongside the detach") |
| + } |
| +} |
diff --git a/internal/host/edgesfile_unread_claims_test.go b/internal/host/edgesfile_unread_claims_test.go| new file mode 100644 |
| index 000000000..3a42af128 |
| --- /dev/null |
| +++ b/internal/host/edgesfile_unread_claims_test.go |
| @@ -0,0 +1,79 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// claimGetTimeoutStore lists every claim but times out reading their bodies, |
| +// the way a restarted edge's first alias pass read them under the startup HA |
| +// ingress deadline on 2026-11-07. |
| +type claimGetTimeoutStore struct{ *release.DirStore } |
| + |
| +func (s claimGetTimeoutStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if strings.HasPrefix(key, domains.ClaimsPrefix) { |
| + return nil, "", context.DeadlineExceeded |
| + } |
| + return s.DirStore.Get(ctx, key) |
| +} |
| + |
| +// TestEdgesFileKeepsAliasesWhenClaimReadsTimeOut is the production-wired |
| +// witness for the 2026-11-07 flagship shrink: the alias pass the agent runs |
| +// (aliasPassReportingComplete, through the box's own ClaimCache) over a |
| +// store whose claim reads time out, then the edges file the box publishes. |
| +// The custom domain must still be published, which means its row kept the |
| +// DNS stamp the sweep gave it: a re-inserted row is withheld until the next |
| +// sweep. |
| +func TestEdgesFileKeepsAliasesWhenClaimReadsTimeOut(t *testing.T) { |
| + aliasClaimCache.Reset() |
| + oldAuthority := boxAssetAuthority |
| + boxAssetAuthority = newAssetAuthority(nil) |
| + t.Cleanup(func() { |
| + aliasClaimCache.Reset() |
| + boxAssetAuthority = oldAuthority |
| + }) |
| + t.Setenv("CARLOS_REGION_HA", "") |
| + ctx := context.Background() |
| + store := release.NewDirStore(t.TempDir()) |
| + reg := edgesTestRegistry(t) |
| + if err := reg.Upsert(registry.Route{Host: "shop.example.com", Account: "abc", App: "shop", Kind: "instance", Status: "ready"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, _, err := domains.AttachClaim(ctx, store, domains.Claim{Host: "www.example.org", Account: "abc", App: "shop", Route: "shop.example.com"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + ident := edgesFile{Box: "annie"} |
| + publish := func() map[string]edgeHost { |
| + t.Helper() |
| + var last []byte |
| + if err := edgesFileWrite(ctx, store, reg, ident, "203.0.113.1", &last, true); err != nil { |
| + t.Fatal(err) |
| + } |
| + return readEdgesFile(t, store, "annie").Hosts |
| + } |
| + |
| + if ok, err := aliasPassReportingComplete(ctx, store, reg, &aliasClaimCache, boxAssetAuthority, ""); err != nil || !ok { |
| + t.Fatalf("control pass: complete=%v err=%v", ok, err) |
| + } |
| + if err := reg.SetAliasDNSStatus("www.example.org", "pointing", time.Now().Unix()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, ok := publish()["www.example.org"]; !ok { |
| + t.Fatal("control: the stamped alias is not in the edges file") |
| + } |
| + |
| + aliasClaimCache.Reset() // cold, as after a restart |
| + ok, _ := aliasPassReportingComplete(ctx, claimGetTimeoutStore{store}, reg, &aliasClaimCache, boxAssetAuthority, "") |
| + if ok { |
| + t.Fatal("a pass that read no claim bodies reported complete") |
| + } |
| + if _, ok := publish()["www.example.org"]; !ok { |
| + t.Fatal("the edges file dropped a custom domain after a pass that could not read its claim") |
| + } |
| +} |