pathmapcheck: compare serving-box sets, not one elected home (#186)
The check elected one home per host with edge.FoldedHome over every edges file, so a front served by two boxes (region HA, a static, a public address route) with its target on only one of them passed, though the other box would hop after the roll. It now lists, per host, every box whose own edges file gives a dial target, and flags a target unless it is served on every box that serves its front; an empty set on either side still fails. This also removes the static false alarm. The runbook describes the set rule and why step 1 keeps mixed versions from hopping. A comment says a claim detached between listing and GET fails closed on purpose.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+132
−42
docs/superpowers/runbooks/path-routes-across-boxes-rollout.md+16 −13scripts/pathmapcheck/main.go+71 −29scripts/pathmapcheck/main_test.go+45 −0
CI failed — run details
diff --git a/docs/superpowers/runbooks/path-routes-across-boxes-rollout.md b/docs/superpowers/runbooks/path-routes-across-boxes-rollout.md| index d4a9a73b7..ae57b32a8 100644 |
| --- a/docs/superpowers/runbooks/path-routes-across-boxes-rollout.md |
| +++ b/docs/superpowers/runbooks/path-routes-across-boxes-rollout.md |
| @@ -29,20 +29,24 @@ AWS_PROFILE=kass go run ./scripts/pathmapcheck -bucket carlos-dev-64001295344 |
| AWS_PROFILE=keymail go run ./scripts/pathmapcheck -bucket carlos-flagship-271376211898 -region eu-west-1 |
| ``` |
| -It reads every published claim under `domains/`, keeps the ones with a |
| -path map, and works out each front's and each target's home box from every |
| -edges file under `control/edges/`, the way an edge does. It prints one line |
| -per map: |
| +It reads every published claim under `domains/` and keeps the ones with a |
| +path map. For each front and each target it lists every box that serves it: |
| +each edges file under `control/edges/` is asked on its own, the way an edge |
| +reads it. One host can have several boxes. Statics and public address routes |
| +are on every box, and a region HA route is on two. It prints one line per |
| +map, with the front's boxes and, for each flagged prefix, the target's: |
| ``` |
| -hub.example.com (box-a): 3 prefixes, 1 cross-box, e.g. /paulca -> t1.example.com (box-b) |
| +hub.example.com (box-a, box-b): 3 prefixes, 1 cross-box, e.g. /paulca -> t1.example.com (box-a) |
| ``` |
| and ends with `OK` (exit 0) or `FAIL` (exit 1). `FAIL` means at least one |
| of these: |
| -- a target is homed on a different box than its front, or on no box |
| - (`no home`); |
| +- a target is missing from at least one box that serves its front. After |
| + the roll that box would hop the prefix's requests to another box. A box |
| + that serves the target but not the front does not matter; |
| +- a front or a target that no box serves (`no home`); |
| - a claim or edges file could not be listed, read or decoded. Its key is |
| printed after `unreadable:`. An unreadable claim might be a cross-box |
| map, so the check does not pass over it. |
| @@ -52,10 +56,6 @@ which maps and keys it named, and wait for his go before rolling. A |
| transient read error is worth one re-run first; a second `FAIL` goes to |
| Paul. |
| -A static site that every box serves can show up as cross-box, because the |
| -fold picks one box to dial. That is a false alarm, but it is still Paul's |
| -call to wave it through. |
| - |
| Any other deployment that takes this release (Tito's, for example) needs |
| the same check against its own bucket before it upgrades. Tell its |
| operator. |
| @@ -69,8 +69,11 @@ cross-box hop for a region HA target with a 503 (spec §8, accepted with the |
| cut of the capability gate), so a pinned or forgotten box must be rolled or |
| reported. |
| -Between steps 1 and 3 nothing names a cross-box target, so mixed versions |
| -during the roll cannot route a request across boxes. |
| +When step 1 passes, every box that serves a front also serves each of its |
| +targets, so every box answers those prefixes locally and none hops. That |
| +holds until step 3, so mixed versions during the roll cannot route a |
| +request across boxes. A map published or changed after step 1 is not |
| +covered: if one may have moved before the roll starts, run the check again. |
| After the dev roll, run the dev witness (spec §9): a hub on one dev box and |
| a tenant on another; `curl https://<hub>/<slug>/api/version` through each |
diff --git a/scripts/pathmapcheck/main.go b/scripts/pathmapcheck/main.go| index 5b7a460d8..06db4407b 100644 |
| --- a/scripts/pathmapcheck/main.go |
| +++ b/scripts/pathmapcheck/main.go |
| @@ -1,8 +1,8 @@ |
| // Command pathmapcheck is the read-only pre-roll check for path routes |
| // across boxes (#186, spec 2026-11-19 §8 step 1). It lists every published |
| -// path map in a deployment's control bucket and flags each target whose |
| -// home box differs from its front's, or that no box homes. Exit 0: no map |
| -// names such a target. Exit 1: one does, or something it had to read could |
| +// path map in a deployment's control bucket and flags each target that is |
| +// missing from any box serving its front (that box would hop to it after the |
| +// roll), or that no box serves. Exit 0: no map names such a target. Exit 1: one does, or something it had to read could |
| // not be read. |
| // |
| // AWS_PROFILE=kass go run ./scripts/pathmapcheck -bucket <control bucket> -region <region> |
| @@ -21,6 +21,7 @@ import ( |
| "fmt" |
| "io" |
| "os" |
| + "slices" |
| "sort" |
| "strings" |
| @@ -33,16 +34,18 @@ import ( |
| // examples is how many flagged prefixes one map's line shows. |
| const examples = 3 |
| -// flagged is one prefix whose target is not on its front's box. |
| +// flagged is one prefix whose target is not on every box of its front. |
| type flagged struct { |
| - prefix, target, home string // home "" means no box homes target |
| + prefix, target string |
| + homes []string // the boxes that serve target; none means no box does |
| } |
| // pathMap is one published map as the check sees it. |
| type pathMap struct { |
| - front, home string // home "" means no box homes the front |
| - prefixes int |
| - cross []flagged // sorted by prefix |
| + front string |
| + homes []string // the boxes that serve the front; none means no box does |
| + prefixes int |
| + cross []flagged // sorted by prefix |
| } |
| // report is the check's whole answer. |
| @@ -53,7 +56,8 @@ type report struct { |
| unread []string |
| } |
| -// ok is the verdict: every map readable, every target on its front's box. |
| +// ok is the verdict: every map readable, every target on every box that |
| +// serves its front. |
| func (r report) ok() bool { |
| if len(r.unread) > 0 { |
| return false |
| @@ -66,22 +70,22 @@ func (r report) ok() bool { |
| return true |
| } |
| -func homeLabel(box string) string { |
| - if box == "" { |
| +func homeLabel(boxes []string) string { |
| + if len(boxes) == 0 { |
| return "no home" |
| } |
| - return box |
| + return strings.Join(boxes, ", ") |
| } |
| func (r report) write(w io.Writer) { |
| crossMaps := 0 |
| for _, m := range r.maps { |
| - fmt.Fprintf(w, "%s (%s): %d prefixes, %d cross-box", m.front, homeLabel(m.home), m.prefixes, len(m.cross)) |
| + fmt.Fprintf(w, "%s (%s): %d prefixes, %d cross-box", m.front, homeLabel(m.homes), m.prefixes, len(m.cross)) |
| if len(m.cross) > 0 { |
| crossMaps++ |
| var eg []string |
| for _, c := range m.cross[:min(examples, len(m.cross))] { |
| - eg = append(eg, fmt.Sprintf("/%s -> %s (%s)", c.prefix, c.target, homeLabel(c.home))) |
| + eg = append(eg, fmt.Sprintf("/%s -> %s (%s)", c.prefix, c.target, homeLabel(c.homes))) |
| } |
| fmt.Fprintf(w, ", e.g. %s", strings.Join(eg, ", ")) |
| } |
| @@ -91,10 +95,10 @@ func (r report) write(w io.Writer) { |
| fmt.Fprintf(w, "unreadable: %s\n", u) |
| } |
| if r.ok() { |
| - fmt.Fprintf(w, "OK: %d path map(s), every target homed on its front's box\n", len(r.maps)) |
| + fmt.Fprintf(w, "OK: %d path map(s), every target served on every box that serves its front\n", len(r.maps)) |
| return |
| } |
| - fmt.Fprintf(w, "FAIL: %d of %d path map(s) name a target on another box or on none; %d object(s) unreadable\n", crossMaps, len(r.maps), len(r.unread)) |
| + fmt.Fprintf(w, "FAIL: %d of %d path map(s) name a target missing from a box that serves the front; %d object(s) unreadable\n", crossMaps, len(r.maps), len(r.unread)) |
| } |
| // check reads every claim and every edges file in s and reports each path |
| @@ -110,31 +114,31 @@ func check(ctx context.Context, s release.Store) (report, error) { |
| if err != nil { |
| return report{}, err |
| } |
| - homes := map[string]string{} |
| - homeOf := func(host string) (string, error) { |
| - if box, seen := homes[host]; seen { |
| - return box, nil |
| + homes := map[string][]string{} |
| + homesOf := func(host string) ([]string, error) { |
| + if boxes, seen := homes[host]; seen { |
| + return boxes, nil |
| } |
| - box, _, err := edge.FoldedHome(bodies, "", host) |
| + boxes, err := servingBoxes(bodies, host) |
| if err != nil { |
| - return "", err |
| + return nil, err |
| } |
| - homes[host] = box |
| - return box, nil |
| + homes[host] = boxes |
| + return boxes, nil |
| } |
| for _, c := range claims { |
| - home, err := homeOf(c.Host) |
| + front, err := homesOf(c.Host) |
| if err != nil { |
| return report{}, err |
| } |
| - m := pathMap{front: c.Host, home: home, prefixes: len(c.Paths)} |
| + m := pathMap{front: c.Host, homes: front, prefixes: len(c.Paths)} |
| for prefix, target := range c.Paths { |
| - th, err := homeOf(target) |
| + th, err := homesOf(target) |
| if err != nil { |
| return report{}, err |
| } |
| - if home == "" || th != home { |
| - m.cross = append(m.cross, flagged{prefix: prefix, target: target, home: th}) |
| + if !coversAll(th, front) { |
| + m.cross = append(m.cross, flagged{prefix: prefix, target: target, homes: th}) |
| } |
| } |
| sort.Slice(m.cross, func(i, j int) bool { return m.cross[i].prefix < m.cross[j].prefix }) |
| @@ -145,6 +149,42 @@ func check(ctx context.Context, s release.Store) (report, error) { |
| return r, nil |
| } |
| +// servingBoxes is every box whose own edges file gives host a dial target, |
| +// sorted. It asks each file alone rather than electing one box across all |
| +// of them: statics and public address routes are published as home by every |
| +// box, and a region HA route by two, and each of those boxes takes the |
| +// front's traffic, so each must hold the target locally (spec §5.3, case 1) |
| +// or it hops after the roll. |
| +func servingBoxes(bodies map[string][]byte, host string) ([]string, error) { |
| + var boxes []string |
| + for key, body := range bodies { |
| + box, ok, err := edge.FoldedHome(map[string][]byte{key: body}, "", host) |
| + if err != nil { |
| + return nil, err |
| + } |
| + if ok && !slices.Contains(boxes, box) { |
| + boxes = append(boxes, box) |
| + } |
| + } |
| + slices.Sort(boxes) |
| + return boxes, nil |
| +} |
| + |
| +// coversAll reports whether target is served on every box in front. A front |
| +// or a target no box serves is never covered: nothing shows it is local |
| +// anywhere. A box serving the target but not the front changes nothing. |
| +func coversAll(target, front []string) bool { |
| + if len(front) == 0 || len(target) == 0 { |
| + return false |
| + } |
| + for _, box := range front { |
| + if !slices.Contains(target, box) { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| // readClaims returns every readable claim with a path map, recording each |
| // key it could not read or decode. |
| func readClaims(ctx context.Context, s release.Store, r *report) ([]domains.Claim, error) { |
| @@ -161,6 +201,8 @@ func readClaims(ctx context.Context, s release.Store, r *report) ([]domains.Clai |
| continue |
| } |
| c, err := domains.GetClaim(ctx, s, host) |
| + // Not-found fails too, on purpose: a claim detached between the |
| + // listing and this read is rare, and a re-run settles it. |
| if err != nil { |
| r.unread = append(r.unread, fmt.Sprintf("%s: %v", key, err)) |
| continue |
diff --git a/scripts/pathmapcheck/main_test.go b/scripts/pathmapcheck/main_test.go| index a09e6d57b..80f217ffe 100644 |
| --- a/scripts/pathmapcheck/main_test.go |
| +++ b/scripts/pathmapcheck/main_test.go |
| @@ -211,3 +211,48 @@ func TestPathMapCheckListingErrorFails(t *testing.T) { |
| t.Fatalf("exit %d, want 1 naming the listing error:\n%s", code, out) |
| } |
| } |
| + |
| +// TestPathMapCheckFrontOnTwoBoxesTargetOnOne: a front two boxes serve (a |
| +// region HA pair, a static, a public address route) with its target on only |
| +// one of them. After the roll the other box hops, so it is cross-box, |
| +// whichever box an election would pick. |
| +func TestPathMapCheckFrontOnTwoBoxesTargetOnOne(t *testing.T) { |
| + f := newFixture(t) |
| + f.claim("hub.example.com", map[string]string{"paulca": "t1.example.com"}) |
| + f.box("box-a", 1, "hub.example.com", "t1.example.com") |
| + f.box("box-b", 2, "hub.example.com") |
| + code, out := f.run(f.s) |
| + if code != 1 { |
| + t.Fatalf("exit %d, want 1:\n%s", code, out) |
| + } |
| + if !strings.Contains(out, "hub.example.com (box-a, box-b): 1 prefixes, 1 cross-box, e.g. /paulca -> t1.example.com (box-a)") { |
| + t.Fatalf("output:\n%s", out) |
| + } |
| +} |
| + |
| +// TestPathMapCheckEveryBoxServesBoth: a front and a target every box |
| +// serves (two statics) are local wherever the front is served. |
| +func TestPathMapCheckEveryBoxServesBoth(t *testing.T) { |
| + f := newFixture(t) |
| + f.claim("hub.example.com", map[string]string{"paulca": "t1.example.com"}) |
| + f.box("box-a", 1, "hub.example.com", "t1.example.com") |
| + f.box("box-b", 2, "hub.example.com", "t1.example.com") |
| + f.box("box-c", 3, "hub.example.com", "t1.example.com") |
| + code, out := f.run(f.s) |
| + if code != 0 || !strings.Contains(out, "hub.example.com (box-a, box-b, box-c): 1 prefixes, 0 cross-box") { |
| + t.Fatalf("exit %d, want 0:\n%s", code, out) |
| + } |
| +} |
| + |
| +// TestPathMapCheckTargetOnSuperset: a box that serves the target but not |
| +// the front never sees the front's traffic, so it changes nothing. |
| +func TestPathMapCheckTargetOnSuperset(t *testing.T) { |
| + f := newFixture(t) |
| + f.claim("hub.example.com", map[string]string{"paulca": "t1.example.com"}) |
| + f.box("box-a", 1, "hub.example.com", "t1.example.com") |
| + f.box("box-b", 2, "t1.example.com") |
| + code, out := f.run(f.s) |
| + if code != 0 || !strings.Contains(out, "hub.example.com (box-a): 1 prefixes, 0 cross-box") { |
| + t.Fatalf("exit %d, want 0:\n%s", code, out) |
| + } |
| +} |