carlos / platform Public

hosts-used scan: Astra round 3 P1 fixes (moves/seeds prefixes, census), README --targets

Summary

- Round 3 P1-1 (configured vs inventoried namespace): a bucket prefix
  whose first segment is moves or seeds is refused before any AWS call,
  exit 2, no output: the bucket mapper reads moves/ and seeds/ before the
  replica prefix, so a replica under them would be taken for another
  host's move or seed data. Witnesses: moves, moves/x, seeds/x (failed
  before the fix); moves-archive is still listed.
- Round 3 P1-2 (census): root-read census overlay
  plan14-root-reads-nearest-region-scan.tsv re-pins the internal/layout
  envelope (make census-propose; card at
  docs/superpowers/notes/census-proposal-nearest-region-scan.md, CLAIMS
  beside it). Record-write census layer nearestRegionScanWriteCensusInventory
  carries HostsFromBoxListing's new digest (kinds unchanged); 9B8 reads it.
- README step 3 names the --targets coords file.
Agent notes
go test ./internal/provision (full) passes, as do
internal/layout and cmd/console -run TestHostsUsedScanAWS. Census
approval and the narrow round 3 confirmation go to Astra next.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 0b634d7b63b334527509200a4d894cf10b7f6a1b parent 84478f2
9 files changed, +85 −11
  • README.md +2 −0
  • cmd/console/hostsused_scan_test.go +16 −6
  • docs/superpowers/notes/census-nearest-region-scan-claims.md +8 −0
  • docs/superpowers/notes/census-proposal-nearest-region-scan.md +11 −0
  • internal/provision/nearest_region_scan_census_test.go +29 −0
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-nearest-region-scan.tsv +3 −0
  • scripts/hosts-used-scan-aws.sh +14 −4
diff --git a/README.md b/README.md
index 05ef8c748..5c3899b89 100644
--- a/README.md
+++ b/README.md
@@ -364,6 +364,8 @@ while it is stopped.
2. Run `console hosts-used roster -o roster.json`. It lists every box and
bucket the regions and fleets use.
3. Scan every target on the roster with `scripts/hosts-used-scan-aws.sh`.
+ Pass it a `--targets` coords file naming each box's instance and region
+ and each bucket's prefix. The script's header shows the format.
4. Run `console hosts-used activate -roster roster.json -listings
scan.jsonl`. A fleet that cannot be scanned can be closed instead, with
`-close-fleet <fleet>`. A closed fleet takes no new instances. Regions
diff --git a/cmd/console/hostsused_scan_test.go b/cmd/console/hostsused_scan_test.go
index bee972d08..d2b596162 100644
--- a/cmd/console/hostsused_scan_test.go
+++ b/cmd/console/hostsused_scan_test.go
@@ -603,13 +603,19 @@ func TestHostsUsedScanAWSFailsATargetClosed(t *testing.T) {
// TestHostsUsedScanAWSPrefixInPlainFormOnly (Paul's cut on discussion 438):
// a bucket's prefix is taken only in plain form, segments of
// [A-Za-z0-9._-]+ joined by single slashes, none of them "." or "..", or
-// "" (replicas at the top level). Any other prefix stops the whole run
-// before any AWS call, with exit 2 and no output. A plain prefix is listed
-// as written.
+// "" (replicas at the top level). A prefix whose first segment is moves or
+// seeds is refused too: the bucket mapper reads those roots first, so a
+// replica under them would be taken for move or seed data of another host
+// (Astra round 3). Any such prefix stops the whole run before any AWS call,
+// with exit 2 and no output. A plain prefix is listed as written.
func TestHostsUsedScanAWSPrefixInPlainFormOnly(t *testing.T) {
keys := []string{"top.example.com/db/1", "moves/m.example.com/x", "a/b.c-d_e/i.example.com/y", "instances/j.example.com/z"}
+ refusals := map[string]string{"moves": "moves or seeds", "moves/x": "moves or seeds", "seeds/x": "moves or seeds"}
for _, bad := range []string{"/instances", "instances/", "///", " //instances// ", "a//b", "a/./b", "./a", "a/..", "..", ".",
"snapshots/../instances", " instances", "inst ances", "instances\t", "\u00edinstances", "a\nb", "a/b/"} {
+ refusals[bad] = "plain form"
+ }
+ for bad, why := range refusals {
w := newScanWorld(t)
w.bucket("bucket:good", "instances", keys...)
w.bucket("bucket:bad", bad, keys...)
@@ -622,8 +628,8 @@ func TestHostsUsedScanAWSPrefixInPlainFormOnly(t *testing.T) {
cmd.Env = append(os.Environ(), w.env...)
b, err := cmd.CombinedOutput()
var ee *exec.ExitError
- if !errors.As(err, &ee) || ee.ExitCode() != 2 || !strings.Contains(string(b), "bucket:bad") || !strings.Contains(string(b), "plain form") {
- t.Errorf("prefix %q: %v, want exit 2 naming bucket:bad\n%s", bad, err, b)
+ if !errors.As(err, &ee) || ee.ExitCode() != 2 || !strings.Contains(string(b), "bucket:bad") || !strings.Contains(string(b), why) {
+ t.Errorf("prefix %q: %v, want exit 2 naming bucket:bad and %q\n%s", bad, err, why, b)
}
if _, err := os.Stat(out); err == nil {
t.Errorf("prefix %q: an output file was written", bad)
@@ -636,8 +642,9 @@ func TestHostsUsedScanAWSPrefixInPlainFormOnly(t *testing.T) {
w.bucket("bucket:top", "", keys...)
w.bucket("bucket:one", "instances", keys...)
w.bucket("bucket:two", "a/b.c-d_e", keys...)
+ w.bucket("bucket:movesish", "moves-archive", keys...)
rosterPath := filepath.Join(w.dir, "roster.json")
- writeJSON(t, rosterPath, map[string]any{"targets": []string{"bucket:top", "bucket:one", "bucket:two"}})
+ writeJSON(t, rosterPath, map[string]any{"targets": []string{"bucket:top", "bucket:one", "bucket:two", "bucket:movesish"}})
got, stderr, code := w.scan(rosterPath)
if code != 0 {
t.Fatalf("plain prefixes: exit %d\n%s", code, stderr)
@@ -649,6 +656,9 @@ func TestHostsUsedScanAWSPrefixInPlainFormOnly(t *testing.T) {
if l := ls["bucket:one"]; l.Prefix != "instances" || !slices.Equal(l.Entries, []string{"instances/j.example.com/z", "moves/m.example.com/x"}) {
t.Errorf("prefix instances = %+v", l)
}
+ if l := ls["bucket:movesish"]; !l.OK || l.Prefix != "moves-archive" {
+ t.Errorf("prefix moves-archive = %+v, want it listed", l)
+ }
if l := ls["bucket:two"]; l.Prefix != "a/b.c-d_e" || !slices.Equal(l.Entries, []string{"a/b.c-d_e/i.example.com/y", "moves/m.example.com/x"}) {
t.Errorf("prefix a/b.c-d_e = %+v", l)
}
diff --git a/docs/superpowers/notes/census-nearest-region-scan-claims.md b/docs/superpowers/notes/census-nearest-region-scan-claims.md
new file mode 100644
index 000000000..0e389bd81
--- /dev/null
+++ b/docs/superpowers/notes/census-nearest-region-scan-claims.md
@@ -0,0 +1,8 @@
+# CLAIMS for the root-read census, branch nearest-region-scan (amadan #437, #438; nearest-region never-reuse Task 11).
+# Format (AGENTS.md "The census"): <file>:<unit><TAB><what changed>. Lines starting with # are ignored.
+# Base: 0a32ce38 (origin/main). No root-read unit changed, so there are no unit claims.
+# The internal/layout envelope is re-pinned for one change: HostsFromBoxListing (internal/layout/hostsused.go),
+# a pure mapping with no I/O, now skips instances/_probe and .instances/_probe (instancectl.ProbeDirName, the
+# readiness probe's own directory, made at bootstrap) with anything below them, by exact name, instead of
+# reporting them unmapped. Its only caller is console hosts-used activate (cmd/console, out of scope); root
+# never calls it. No read added.
diff --git a/docs/superpowers/notes/census-proposal-nearest-region-scan.md b/docs/superpowers/notes/census-proposal-nearest-region-scan.md
new file mode 100644
index 000000000..2e183e0d2
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-nearest-region-scan.md
@@ -0,0 +1,11 @@
+# Census approval: nearest-region-scan
+
+Ruling `census-ruling-nearest-region-scan`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `internal/layout`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision.
+
+Seal: `f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7` → `f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-nearest-region-scan.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/provision/nearest_region_scan_census_test.go b/internal/provision/nearest_region_scan_census_test.go
new file mode 100644
index 000000000..cde302410
--- /dev/null
+++ b/internal/provision/nearest_region_scan_census_test.go
@@ -0,0 +1,29 @@
+package provision
+
+// Record-write census entry for nearest-region-scan (amadan #437: the box
+// listing mapper skips the readiness probe's own directory), layered on
+// usageAttribution390WriteCensusInventory (main's newest at 0a32ce38).
+// Reviewed by the branch author and the cross-model reviewer (Astra) with
+// the branch. No record write is added, moved or reclassified:
+// - layout.HostsFromBoxListing keeps its one key site, the "instances"
+// directory literal. Its body now skips instances/<id> and
+// .instances/<id> when id is exactly instancectl.ProbeDirName, with
+// anything below them. It is a pure mapping and writes nothing.
+func nearestRegionScanWriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), usageAttribution390WriteCensusInventory()...)
+ replacements := []censusEntry{
+ {"internal/layout/hostsused.go", "HostsFromBoxListing", "key-site", "lit:instances", "3f1141229de70236eaa9fd97198edfd139ff7f5ffa6d6c6236bdfe7cbc2daa73"},
+ }
+ for _, r := range replacements {
+ found := false
+ for i, e := range entries {
+ if e.File == r.File && e.Unit == r.Unit {
+ entries[i], found = r, true
+ }
+ }
+ if !found {
+ panic("nearest-region-scan replacement of an unlisted unit " + r.File + ":" + r.Unit)
+ }
+ }
+ return entries
+}
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index d95103afb..4fa542146 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := usageAttribution390WriteCensusInventory()
+ inventory := nearestRegionScanWriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 3bef53d39..96a124b01 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -13,3 +13,4 @@ plan14-root-reads-ha-p1a-433.tsv f8acbc0dd8828636e3f73d9afd0e539d3dfd1346e0232d9
plan14-root-reads-rollup-tenant-tags.tsv f8acbc0dd8828636e3f73d9afd0e539d3dfd1346e0232d91903c33d6eb27d820
plan14-root-reads-alias-wake-338.tsv deeddee1bf22a18562acda97cc34c6d73ee0dff1825100c73fa0be4c6a3f3e7b
plan14-root-reads-analytics-onramp.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7
+plan14-root-reads-nearest-region-scan.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7
diff --git a/internal/provision/testdata/plan14-root-reads-nearest-region-scan.tsv b/internal/provision/testdata/plan14-root-reads-nearest-region-scan.tsv
new file mode 100644
index 000000000..2412fa7e4
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-nearest-region-scan.tsv
@@ -0,0 +1,3 @@
+# Census overlay nearest-region-scan, written by census-propose (#369). census-ruling-nearest-region-scan, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-nearest-region-scan.md.
+# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage internal/layout 2b40e510234739bf231719b18c73ddc6b2112d96b203ad1191d62dd62612c1c1
diff --git a/scripts/hosts-used-scan-aws.sh b/scripts/hosts-used-scan-aws.sh
index f1a11f1f8..602a08f19 100755
--- a/scripts/hosts-used-scan-aws.sh
+++ b/scripts/hosts-used-scan-aws.sh
@@ -24,8 +24,11 @@
# bucket's top level, and then the whole bucket is listed). A wrong prefix
# misses that bucket's replicas, so it is never defaulted, and it is taken
# only in plain form: segments of [A-Za-z0-9._-]+ joined by single slashes,
-# none of them "." or "..", or "". Any other prefix stops the whole run
-# before any AWS call. region is optional for a bucket.
+# none of them "." or "..", or "". Its first segment may not be moves or
+# seeds: the mapper reads those roots before the replica prefix, so a
+# replica under them would be taken for another host's move or seed data.
+# Any other prefix stops the whole run before any AWS call. region is
+# optional for a bucket.
#
# Any failure for a target (no coordinates, an AWS error, a command that
# failed or timed out, a listing that changed while it was paged) gives that
@@ -75,10 +78,17 @@ notplain="$(jq -rn --slurpfile r "$roster" --slurpfile c "$coords" '
and (explode | all(. as $x | ($x >= 48 and $x <= 57) or ($x >= 65 and $x <= 90) or ($x >= 97 and $x <= 122)
or $x == 45 or $x == 46 or $x == 95))));
$r[0].targets[] | select(startswith("bucket:")) as $t | $c[0][$t]
- | select(type == "object" and has("prefix")) | select((.prefix|type) != "string" or (.prefix|plain|not)) | $t')" || {
+ | select(type == "object" and has("prefix")) | .prefix
+ | if type != "string" or (plain|not) then "plain\t" + $t
+ elif (split("/")[0]) == "moves" or (split("/")[0]) == "seeds" then "root\t" + $t
+ else empty end')" || {
echo "hosts-used-scan: could not check the prefixes in $coords" >&2; exit 2; }
if [ -n "$notplain" ]; then
- while IFS= read -r t; do
+ while IFS=$'\t' read -r why t; do
+ if [ "$why" = root ]; then
+ echo "hosts-used-scan: the prefix for $t in $coords starts with moves or seeds, where the platform keeps move and seed data, so its replicas cannot be told apart. a box with such a CARLOS_HIBERNATE_PREFIX cannot be scanned" >&2
+ continue
+ fi
echo "hosts-used-scan: the prefix for $t in $coords is not in plain form. write it as the box resolves CARLOS_HIBERNATE_PREFIX: segments of letters, digits, '.', '_' and '-' joined by single slashes, with no '.' or '..' segment and no slash at either end, or \"\" for the top level" >&2
done <<<"$notplain"
exit 2