carlos / platform Public

domains: aggregate path refusal logs; keep unread claims' path rows

Task 3 review fix round 1 (#186).

I1: derivePaths logged the sidecar-target, cross-account-target and
bad-prefix refusals once per prefix, and every box now runs that loop
for every path claim, so one tenant's map could write 10,000 lines every
pass on every box. Each reason now logs one line per host per pass with
a count and up to three examples, as the unresolved count already did.

I2: TestReconcileRefusesPathsOnAnotherTenantsLocalHost covers the local
host tenancy check (account and app mismatch); removing the check fails
both subtests.

G1: writePaths keeps the rows of a host whose claim was listed but not
read this pass and marks the pass incomplete, the regional_domains rule,
so one failed read no longer drops and re-adds a host's rows on every
box.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9f96b1ce4f5b4322bc2ce17c760b8cecd6878c89 parent 693ff67
3 files changed, +196 −22
  • internal/domains/aliases.go +49 −19
  • internal/domains/aliases_paths_test.go +138 −0
  • internal/domains/pathwrite.go +9 −3

CI failed — run details

diff --git a/internal/domains/aliases.go b/internal/domains/aliases.go
index 9338683f0..f829c3d6f 100644
--- a/internal/domains/aliases.go
+++ b/internal/domains/aliases.go
@@ -831,7 +831,13 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry.
// prefix removed from a republished map disappears here with no delete
// verb anywhere. That is exactly how a per-account rollback reaches the
// edge.
- pathsIncomplete, err := writePaths(reg, desiredPaths, noRemoval)
+ //
+ // The same one exception as regional_domains above: a host whose claim
+ // the listing shows but whose body this pass did not read keeps its
+ // rows as they are, and the pass is incomplete. Every box holds every
+ // path-routed host's rows, so dropping them on one failed read and
+ // adding them back on the next would churn the whole map on every box.
+ pathsIncomplete, err := writePaths(reg, desiredPaths, noRemoval, unread)
if err != nil {
return err
}
@@ -1052,17 +1058,18 @@ func derivePaths(c Claim, byHost map[string]registry.Route, desired *pathSet) {
c.Host, len(prefixes), MaxPathsPerClaim, len(prefixes)-MaxPathsPerClaim)
prefixes = prefixes[:MaxPathsPerClaim]
}
- // Unresolved targets are counted and named ONCE per host per pass, not
- // logged per prefix: this pass runs every ~2s on every box, and a
- // 10k-entry map would otherwise write 10k lines every two seconds. The
- // count is the operator's signal; the first few names are enough to
- // identify which map is wrong.
- unresolved := 0
- var unresolvedEg []string
+ // Refusals and unresolved targets are counted and named ONCE per host
+ // per reason per pass, never logged per prefix: this pass runs every
+ // ~2s on every box for every path claim, and the claim's tenant chooses
+ // what its map holds, so a per-prefix line would let one tenant write
+ // 10k lines every two seconds on every box. The count is the operator's
+ // signal; the first few names are enough to identify which map is
+ // wrong.
+ var badPrefix, sidecar, foreign, unready pathTally
for _, prefix := range prefixes {
target := c.Paths[prefix]
if !validPathPrefix(prefix) {
- log.Printf("domains: path %s/%s refused: not a bare path segment", c.Host, prefix)
+ badPrefix.add(prefix)
continue
}
if strings.HasSuffix(target, sidecarSuffix) {
@@ -1075,8 +1082,7 @@ func derivePaths(c Claim, byHost map[string]registry.Route, desired *pathSet) {
// account could dial its own undialable member. Refused by
// name, so a box that does not hold the sidecar refuses it
// too.
- log.Printf("domains: path %s/%s refused: target %s is under the reserved sidecar suffix — nothing routes to a sidecar",
- c.Host, prefix, target)
+ sidecar.add(target)
continue
}
if tgtRt, local := byHost[target]; local {
@@ -1088,8 +1094,7 @@ func derivePaths(c Claim, byHost map[string]registry.Route, desired *pathSet) {
// as cross-tenant rather than swept into the unresolved count
// below.
if release.RouteAccount(tgtRt) != c.Account {
- log.Printf("domains: path %s/%s refused: target %s belongs to %s, claim says %s",
- c.Host, prefix, target, release.RouteAccount(tgtRt), c.Account)
+ foreign.add(target + " (" + release.RouteAccount(tgtRt) + ")")
continue
}
if tgtRt.Status != "ready" {
@@ -1100,10 +1105,7 @@ func derivePaths(c Claim, byHost map[string]registry.Route, desired *pathSet) {
// serves the ORIGIN, never a 404. Silent traffic is the
// danger here, not broken traffic, which is why this is
// logged at all.
- unresolved++
- if len(unresolvedEg) < 3 && !slices.Contains(unresolvedEg, target) {
- unresolvedEg = append(unresolvedEg, target)
- }
+ unready.add(target)
continue
}
}
@@ -1112,8 +1114,36 @@ func derivePaths(c Claim, byHost map[string]registry.Route, desired *pathSet) {
Account: c.Account, App: c.App,
})
}
- if unresolved > 0 {
+ if badPrefix.n > 0 {
+ log.Printf("domains: paths on %s: %d prefix(es) refused: not a bare path segment (e.g. %s)",
+ c.Host, badPrefix.n, badPrefix.examples())
+ }
+ if sidecar.n > 0 {
+ log.Printf("domains: paths on %s: %d prefix(es) refused: target is under the reserved sidecar suffix, and nothing routes to a sidecar (e.g. %s)",
+ c.Host, sidecar.n, sidecar.examples())
+ }
+ if foreign.n > 0 {
+ log.Printf("domains: paths on %s: %d prefix(es) refused: target is another account's route here, claim says %s (e.g. %s)",
+ c.Host, foreign.n, c.Account, foreign.examples())
+ }
+ if unready.n > 0 {
log.Printf("domains: paths on %s: %d prefix(es) name a local route that is not ready (e.g. %s). Those prefixes serve %s's own route.",
- c.Host, unresolved, strings.Join(unresolvedEg, ", "), c.Host)
+ c.Host, unready.n, unready.examples(), c.Host)
}
}
+
+// pathTally counts one reason derivePaths skipped a claim's prefixes and
+// keeps the first three distinct names it was given, for one log line.
+type pathTally struct {
+ n int
+ eg []string
+}
+
+func (t *pathTally) add(name string) {
+ t.n++
+ if len(t.eg) < 3 && !slices.Contains(t.eg, name) {
+ t.eg = append(t.eg, name)
+ }
+}
+
+func (t *pathTally) examples() string { return strings.Join(t.eg, ", ") }
diff --git a/internal/domains/aliases_paths_test.go b/internal/domains/aliases_paths_test.go
index 923a3849e..fbae29db8 100644
--- a/internal/domains/aliases_paths_test.go
+++ b/internal/domains/aliases_paths_test.go
@@ -475,3 +475,141 @@ func TestReconcilePathsRefusesASidecarAsATarget(t *testing.T) {
t.Fatalf("the refusal must name its reason, got: %s", logged.String())
}
}
+
+// TestReconcileRefusesPathsOnAnotherTenantsLocalHost: where this box serves
+// the claim's host, the host route's tenancy must match the claim, account
+// and app both, or the claim derives no row at all. Deriving on every box
+// does not relax this check where the host is local.
+func TestReconcileRefusesPathsOnAnotherTenantsLocalHost(t *testing.T) {
+ for name, owner := range map[string][2]string{
+ "account mismatch": {"someone-else", "classic"},
+ "app mismatch": {"tito", "other-app"},
+ } {
+ t.Run(name, func(t *testing.T) {
+ ctx := context.Background()
+ s := release.NewDirStore(t.TempDir())
+ reg := aliasRegWith(t)
+ addRoute(t, reg, "ti.to", owner[0], owner[1])
+ addRoute(t, reg, "go.tito.io", "tito", "go")
+ putClaim(t, s, Claim{
+ Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to",
+ CreatedAt: "2026-09-03T00:00:00Z",
+ Paths: map[string]string{"paulca": "go.tito.io", "acme": "elsewhere.example"},
+ })
+ if err := ReconcileAliases(ctx, s, reg, aliasNow(), nil, nil); err != nil {
+ t.Fatal(err)
+ }
+ rows, err := reg.ListPaths()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(rows) != 0 {
+ t.Fatalf("route_paths = %+v, want none: ti.to here is %s/%s's route, the claim says tito/classic", rows, owner[0], owner[1])
+ }
+ })
+ }
+}
+
+// TestReconcileAggregatesPathRefusalLogs: every box runs the prefix loop for
+// every path claim, and a tenant chooses what its map holds, so a refusal
+// logged per prefix would let one tenant write 10,000 lines every ~2 s on
+// every box. Each refusal reason logs one line per host per pass, with a
+// count and a few examples.
+func TestReconcileAggregatesPathRefusalLogs(t *testing.T) {
+ ctx := context.Background()
+ s := release.NewDirStore(t.TempDir())
+ reg := aliasRegWith(t)
+ addRoute(t, reg, "ti.to", "tito", "classic")
+ addRoute(t, reg, "victim-0.example", "someone-else", "their-app")
+ addRoute(t, reg, "victim-1.example", "someone-else", "their-app")
+ paths := map[string]string{}
+ for i := 0; i < 50; i++ {
+ n := strconv.Itoa(i)
+ paths["side"+n] = "bot" + n + ".eleven.tito.sidecar.internal"
+ paths["evil"+n] = "victim-" + strconv.Itoa(i%2) + ".example"
+ paths["bad/"+n] = "go.tito.io"
+ }
+ putClaim(t, s, Claim{
+ Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to",
+ CreatedAt: "2026-09-03T00:00:00Z",
+ Paths: paths,
+ })
+
+ var buf bytes.Buffer
+ log.SetOutput(&buf)
+ t.Cleanup(func() { log.SetOutput(os.Stderr) })
+ if err := ReconcileAliases(ctx, s, reg, aliasNow(), nil, nil); err != nil {
+ t.Fatal(err)
+ }
+ log.SetOutput(os.Stderr)
+
+ out := buf.String()
+ for _, reason := range []string{
+ "domains: paths on ti.to: 50 prefix(es) refused: target is under the reserved sidecar suffix",
+ "domains: paths on ti.to: 50 prefix(es) refused: target is another account's route here",
+ "domains: paths on ti.to: 50 prefix(es) refused: not a bare path segment",
+ } {
+ if n := strings.Count(out, reason); n != 1 {
+ t.Fatalf("logged %q %d times, want exactly once per host per pass:\n%s", reason, n, out)
+ }
+ }
+ // No per-prefix line ("domains: path ti.to/<prefix> ..."), and no
+ // other path line: three in all.
+ if n := strings.Count(out, "domains: path"); n != 3 {
+ t.Fatalf("the pass logged %d path lines, want 3, one per refusal reason:\n%s", n, out)
+ }
+ if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 0 {
+ t.Fatalf("route_paths = %v, want none", got)
+ }
+}
+
+// TestReconcileKeepsPathRowsOfAnUnreadClaim: a claim the listing shows but
+// whose body this pass could not read keeps its route_paths rows as they
+// are, and the pass is incomplete, as regional_domains rows and wildcard
+// parents are kept. Every box holds every host's rows, so dropping them on
+// one failed read and adding them back on the next would churn up to 10,000
+// rows on every box. Once the claim reads again, the rows converge on it.
+func TestReconcileKeepsPathRowsOfAnUnreadClaim(t *testing.T) {
+ for name, unreadable := range map[string]func(*release.DirStore) release.Store{
+ "read error": func(d *release.DirStore) release.Store { return unreadableKeyStore{d, ClaimKey("ti.to")} },
+ "not found": func(d *release.DirStore) release.Store { return notFoundKeyStore{d, ClaimKey("ti.to")} },
+ } {
+ for leg, cache := range map[string]*ClaimCache{"uncached": nil, "cached": {}} {
+ t.Run(name+" "+leg, func(t *testing.T) {
+ dir := release.NewDirStore(t.TempDir())
+ unread := unreadable(dir)
+ putClaim(t, dir, Claim{
+ Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to",
+ CreatedAt: "2026-09-03T00:00:00Z",
+ Paths: map[string]string{"paulca": "go.tito.io", "bigcorp": "go.tito.io"},
+ })
+ reg := aliasRegWith(t)
+ if rep := regionalPass(t, dir, reg, "", cache); !rep.Complete {
+ t.Fatal("setup pass incomplete")
+ }
+ want := map[string]string{"paulca": "go.tito.io", "bigcorp": "go.tito.io"}
+ if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 2 || got["paulca"] != want["paulca"] || got["bigcorp"] != want["bigcorp"] {
+ t.Fatalf("route_paths = %v, want %v", got, want)
+ }
+ // The republished map drops bigcorp; a pass that read it
+ // would delete that row.
+ if _, err := SetClaimPaths(context.Background(), dir, "ti.to", "tito", "classic",
+ map[string]string{"paulca": "go.tito.io"}); err != nil {
+ t.Fatal(err)
+ }
+ if rep := regionalPass(t, unread, reg, "", cache); rep.Complete {
+ t.Fatal("a pass that kept an unread claim's path rows reported complete")
+ }
+ if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 2 || got["paulca"] != want["paulca"] || got["bigcorp"] != want["bigcorp"] {
+ t.Fatalf("route_paths after the unread pass = %v, want %v kept as they were", got, want)
+ }
+ if rep := regionalPass(t, dir, reg, "", cache); !rep.Complete {
+ t.Fatal("the pass that read the claim again reported incomplete")
+ }
+ if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 1 || got["paulca"] != "go.tito.io" {
+ t.Fatalf("route_paths after the claim read again = %v, want only paulca -> go.tito.io", got)
+ }
+ })
+ }
+ }
+}
diff --git a/internal/domains/pathwrite.go b/internal/domains/pathwrite.go
index 99311661f..dd37637ab 100644
--- a/internal/domains/pathwrite.go
+++ b/internal/domains/pathwrite.go
@@ -70,11 +70,13 @@ var pathMemos sync.Map
// no memo, the generation could not be read) falls back to the full diff:
// only a row that differs from the stored one is written, and a row no longer
// desired is deleted unless noRemoval (the startup pass) leaves it for the
-// next ordinary pass. The writes go in one transaction (registry.ApplyPaths).
+// next ordinary pass, or its host is in unread (a claim the listing shows
+// but whose body this pass did not read), which keeps it as it is. The
+// writes go in one transaction (registry.ApplyPaths).
//
// It reports whether the result is incomplete: the write failed, or a row
-// was left. The error is the listing's, which aborts the pass.
-func writePaths(reg *registry.Registry, desired *pathSet, noRemoval bool) (incomplete bool, err error) {
+// was left or kept. The error is the listing's, which aborts the pass.
+func writePaths(reg *registry.Registry, desired *pathSet, noRemoval bool, unread map[string]bool) (incomplete bool, err error) {
digest := desired.sum()
gen, genErr := reg.PathsGeneration()
memo := genErr == nil
@@ -102,6 +104,10 @@ func writePaths(reg *registry.Registry, desired *pathSet, noRemoval bool) (incom
var deletes [][2]string
for _, p := range existing {
if _, ok := desired.rows[p.Host+"\x00"+p.Prefix]; !ok {
+ if unread[p.Host] {
+ incomplete = true // kept as it is: the claim was not read
+ continue
+ }
if noRemoval {
incomplete = true // left for the next ordinary pass
continue