agent: STATUS_NAME_REGION stamps a regional display name on the status report
Group boxes may carry it in host.env (hostenv.Optional), and moves treat it as box-owned so a move between regions doesn't fail its env pin.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+196
−1
README.md+6 −0internal/host/agent.go+12 −0internal/host/displayname.go+28 −0internal/host/displayname_test.go+136 −0internal/hostenv/hostenv.go+1 −0internal/hostenv/hostenv_test.go+9 −0internal/moves/envreport.go+1 −1internal/moves/envreport_test.go+3 −0
diff --git a/README.md b/README.md| index 3cf801394..690de17a7 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -760,6 +760,12 @@ no single reader owns the whole contract: |
| Keep it geographically consistent with the region's place name in the |
| console's region picker (for example "EU · Ireland" beside |
| "Ireland · Dublin"); it may stay coarser. |
| +- `STATUS_NAME_REGION`: a region code (2 to 8 lowercase letters, `ie`, |
| + `uk`) that gives this box a display name such as `seamus-minding-ie` on |
| + the status page and in the console. The name is for people to read. |
| + Nothing is keyed on it, and the box's label is unchanged. The code is |
| + public after it is set. If it is unset, the label appears alone, as |
| + before. Fleet boxes never get a display name. |
| - `STATUS_HOST` / `STATUS_PUBLIC` — not read by the agent process itself; |
| consumed by ops/tofu to decide whether the edge fronts the bucket's |
| `status/` prefix with a public hostname. `STATUS_PUBLIC=1` publishes the |
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 148e56557..04469115c 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -91,6 +91,10 @@ |
| // free text chosen by the operator, never derived from cloud metadata — |
| // the public commitment is a human-readable region, not a specific |
| // datacenter. |
| +// - STATUS_NAME_REGION — a region code (ie, uk) that themes this box's |
| +// display name (status.DisplayName, resolveNameRegion), stamped on the |
| +// snapshot after its label is final; "" or an invalid code publishes no |
| +// name, and a fleet box never gets one. Display only: nothing keys on it. |
| // - CARLOS_SYSTEM_CHANNEL — platform channel this box follows for |
| // self-update, canary|stable (default stable). |
| // - CARLOS_LAYOUT_DEFAULT — the instance layout this box converges to |
| @@ -3918,6 +3922,7 @@ func statusLoop(reg *registry.Registry, svc *activator.Service, buildStates func |
| prefix := resolveStatusPrefix(os.Getenv) |
| region := os.Getenv("CARLOS_STATUS_REGION") |
| boxRegion := os.Getenv("STATUS_BOX_REGION") |
| + nameRegion := resolveNameRegion(os.Getenv, log.Printf) |
| skipElection := shouldSkipPublisherElection(os.Getenv) |
| // Fleet boxes heartbeat under the operator-chosen channel label |
| @@ -4024,6 +4029,7 @@ func statusLoop(reg *registry.Registry, svc *activator.Service, buildStates func |
| MachineID: readMachineID(), |
| InstanceID: cachedInstanceID(), |
| Region: boxRegion, |
| + NameRegion: nameRegion, |
| MemFrac: readMemFrac(), |
| DiskFrac: readDiskFrac(), |
| Listening: wrapListeningProbe(unitBackedSockets(routes), statusSocketProbe(routes, svc)), |
| @@ -4169,6 +4175,9 @@ func statusLoop(reg *registry.Registry, svc *activator.Service, buildStates func |
| // fleets/<fleet>/status/boxes/<label>.json under the SAME label the edge |
| // dials, not an opaque pseudonym only the public status page ever wanted. |
| // "" (every platform box) leaves CollectBox's own label untouched. |
| +// |
| +// The display name (p.NameRegion, status.DisplayName) is derived after the |
| +// override, so it always follows the label the report is published under. |
| func statusTick(ctx context.Context, s release.Store, reg *registry.Registry, p status.Probes, publish bool, labelOverride string) error { |
| routes, err := reg.List() |
| if err != nil { |
| @@ -4192,6 +4201,9 @@ func statusTick(ctx context.Context, s release.Store, reg *registry.Registry, p |
| if labelOverride != "" { |
| box.Label = labelOverride |
| } |
| + if p.NameRegion != "" { |
| + box.Name = status.DisplayName(box.Label, p.NameRegion) |
| + } |
| if err := status.WriteBox(ctx, s, box); err != nil { |
| return err |
| } |
diff --git a/internal/host/displayname.go b/internal/host/displayname.go| new file mode 100644 |
| index 000000000..313d250aa |
| --- /dev/null |
| +++ b/internal/host/displayname.go |
| @@ -0,0 +1,28 @@ |
| +package host |
| + |
| +import ( |
| + "strings" |
| + |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// resolveNameRegion reads STATUS_NAME_REGION, the region code a box's |
| +// display name is themed for (status.DisplayName; spec |
| +// 2026-10-25-regional-box-names-design.md). statusLoop calls it once. |
| +// |
| +// "" means no display name: the variable is unset, or this is a fleet box |
| +// (CARLOS_FLEET set to anything, valid or not), whose operator already |
| +// picked its name and whose report never reaches the shared fleet's page. |
| +// An invalid code is logged once and also gives "", the degrade-don't- |
| +// disable rule the status loop follows everywhere else. |
| +func resolveNameRegion(getenv func(string) string, logf func(string, ...any)) string { |
| + code := strings.TrimSpace(getenv("STATUS_NAME_REGION")) |
| + if code == "" || strings.TrimSpace(getenv("CARLOS_FLEET")) != "" { |
| + return "" |
| + } |
| + if !status.ValidNameRegion(code) { |
| + logf("agent: STATUS_NAME_REGION=%q is not a region code (2 to 8 lowercase letters). this box shows no display name", code) |
| + return "" |
| + } |
| + return code |
| +} |
diff --git a/internal/host/displayname_test.go b/internal/host/displayname_test.go| new file mode 100644 |
| index 000000000..b268b87e6 |
| --- /dev/null |
| +++ b/internal/host/displayname_test.go |
| @@ -0,0 +1,136 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/hostactors" |
| + "github.com/carlosframework/platform/internal/hostenv" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +func TestResolveNameRegion(t *testing.T) { |
| + for _, c := range []struct { |
| + env map[string]string |
| + want string |
| + logs int |
| + }{ |
| + {map[string]string{}, "", 0}, |
| + {map[string]string{"STATUS_NAME_REGION": "ie"}, "ie", 0}, |
| + {map[string]string{"STATUS_NAME_REGION": "ie "}, "ie", 0}, |
| + {map[string]string{"STATUS_NAME_REGION": "ie\n"}, "ie", 0}, |
| + {map[string]string{"STATUS_NAME_REGION": "IE"}, "", 1}, |
| + {map[string]string{"STATUS_NAME_REGION": "Ireland"}, "", 1}, |
| + {map[string]string{"STATUS_NAME_REGION": "u-k"}, "", 1}, |
| + {map[string]string{"STATUS_NAME_REGION": "ie", "CARLOS_FLEET": "acme"}, "", 0}, |
| + {map[string]string{"STATUS_NAME_REGION": "ie", "CARLOS_FLEET": "bad name!"}, "", 0}, |
| + } { |
| + var lines []string |
| + logf := func(format string, args ...any) { lines = append(lines, fmt.Sprintf(format, args...)) } |
| + got := resolveNameRegion(groupEnv(c.env), logf) |
| + if got != c.want || len(lines) != c.logs { |
| + t.Errorf("env %q: %q with %d log lines %q, want %q with %d", c.env, got, len(lines), lines, c.want, c.logs) |
| + } |
| + } |
| +} |
| + |
| +// readBox reads one published report back raw, so a test can see whether |
| +// the name key is there at all, not just whether it decodes empty. |
| +func readBox(t *testing.T, get func(string) ([]byte, error), label string) (status.Box, map[string]json.RawMessage) { |
| + t.Helper() |
| + body, err := get("status/boxes/" + label + ".json") |
| + if err != nil { |
| + t.Fatalf("report for %s: %v", label, err) |
| + } |
| + var b status.Box |
| + var raw map[string]json.RawMessage |
| + if err := json.Unmarshal(body, &b); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := json.Unmarshal(body, &raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + return b, raw |
| +} |
| + |
| +func TestStatusTickStampsTheName(t *testing.T) { |
| + ctx := context.Background() |
| + reg, s, _ := statusFixture(t) |
| + label := status.Label("test-machine") |
| + if err := statusTick(ctx, s, reg, status.Probes{MachineID: "test-machine", NameRegion: "ie"}, true, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + get := func(k string) ([]byte, error) { b, _, err := s.Get(ctx, k); return b, err } |
| + want := status.DisplayName(label, "ie") |
| + if b, _ := readBox(t, get, label); want == "" || b.Name != want { |
| + t.Fatalf("report name %q, want %q", b.Name, want) |
| + } |
| + body, err := get("status/fleet.json") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var f status.Fleet |
| + if err := json.Unmarshal(body, &f); err != nil { |
| + t.Fatal(err) |
| + } |
| + found := false |
| + for _, b := range f.Boxes { |
| + if b.Label == label { |
| + found = b.Name == want |
| + } |
| + } |
| + if !found { |
| + t.Fatalf("fleet.json lacks %s named %s: %s", label, want, body) |
| + } |
| +} |
| + |
| +func TestStatusTickNoNameRegionIsUnchanged(t *testing.T) { |
| + ctx := context.Background() |
| + reg, s, _ := statusFixture(t) |
| + if err := statusTick(ctx, s, reg, status.Probes{MachineID: "test-machine"}, false, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + get := func(k string) ([]byte, error) { b, _, err := s.Get(ctx, k); return b, err } |
| + if _, raw := readBox(t, get, status.Label("test-machine")); raw["name"] != nil { |
| + t.Fatalf("an unset STATUS_NAME_REGION published a name: %s", raw["name"]) |
| + } |
| +} |
| + |
| +// A group box's name follows its g- reference, the label it publishes |
| +// under, never the hashed pseudonym; and with no reference it publishes |
| +// nothing at all, name or not (Review Focus 1). |
| +func TestGroupBoxNameFollowsItsReference(t *testing.T) { |
| + ctx := context.Background() |
| + env := groupEnv(map[string]string{hostenv.BoxReference: hostenv.GroupReference}) |
| + probes := status.Probes{MachineID: "m", NameRegion: "uk"} |
| + |
| + reg, s, victim := statusFixture(t) |
| + withGroupIdentity(t, "", "", errors.New("IMDS answered 500")) |
| + if err := groupStatusTick(ctx, s, reg, probes, false, "", env); !errors.Is(err, errNoGroupReference) { |
| + t.Fatalf("unresolved reference: %v", err) |
| + } |
| + if keys, _ := s.List(ctx, "status/boxes/"); len(keys) != 1 { |
| + t.Fatalf("published with no reference: %v", keys) |
| + } |
| + if got, _, _ := s.Get(ctx, "status/boxes/"+status.Label("machine-1")+".json"); string(got) != string(victim) { |
| + t.Fatalf("the victim's report was replaced: %s", got) |
| + } |
| + |
| + reg, s, _ = statusFixture(t) |
| + withGroupIdentity(t, "123456789012", "i-0a61f580df1acfa65", nil) |
| + if err := groupStatusTick(ctx, s, reg, probes, false, "", env); err != nil { |
| + t.Fatal(err) |
| + } |
| + ref := hostactors.GroupBoxReference("123456789012", "i-0a61f580df1acfa65") |
| + get := func(k string) ([]byte, error) { b, _, err := s.Get(ctx, k); return b, err } |
| + b, _ := readBox(t, get, ref) |
| + if want := status.DisplayName(ref, "uk"); b.Name != want || want == "" { |
| + t.Fatalf("group box name %q, want %q", b.Name, want) |
| + } |
| + if b.Name == status.DisplayName(status.Label("m"), "uk") { |
| + t.Fatalf("group box name %q came from the hashed pseudonym", b.Name) |
| + } |
| +} |
diff --git a/internal/hostenv/hostenv.go b/internal/hostenv/hostenv.go| index e89154183..0fb0323a9 100644 |
| --- a/internal/hostenv/hostenv.go |
| +++ b/internal/hostenv/hostenv.go |
| @@ -94,6 +94,7 @@ var Optional = []string{ |
| "CARLOS_VERSIONS_GRACE", |
| "CARLOS_WILDCARD_DOMAINS", |
| "STATUS_BOX_REGION", |
| + "STATUS_NAME_REGION", |
| } |
| // Allowed reports whether name is a variable host.env may carry from the |
diff --git a/internal/hostenv/hostenv_test.go b/internal/hostenv/hostenv_test.go| index 7b61ece70..075ef928b 100644 |
| --- a/internal/hostenv/hostenv_test.go |
| +++ b/internal/hostenv/hostenv_test.go |
| @@ -426,3 +426,12 @@ func TestStatusOverridesAndTheAlertWebhookAreRefusedByNameNotValue(t *testing.T) |
| }) |
| } |
| } |
| + |
| +// TestStatusNameRegionIsAllowed: a group box's host.env can carry its |
| +// display-name region (regional box names, 2026-10-25). Like |
| +// STATUS_BOX_REGION it selects no authority; it only themes a name. |
| +func TestStatusNameRegionIsAllowed(t *testing.T) { |
| + if !Allowed("STATUS_NAME_REGION") { |
| + t.Fatal("STATUS_NAME_REGION is not allowed in host.env") |
| + } |
| +} |
diff --git a/internal/moves/envreport.go b/internal/moves/envreport.go| index f23f779d0..58cd020ee 100644 |
| --- a/internal/moves/envreport.go |
| +++ b/internal/moves/envreport.go |
| @@ -49,7 +49,7 @@ var ( |
| "LISTEN_PID": true, "LISTEN_FDS": true, "LISTEN_FDNAMES": true, |
| "RUNTIME_DIRECTORY": true, "STATE_DIRECTORY": true, "CACHE_DIRECTORY": true, "LOGS_DIRECTORY": true, |
| "CONFIGURATION_DIRECTORY": true, "CREDENTIALS_DIRECTORY": true, |
| - "AWS_REGION": true, "STATUS_BOX_REGION": true, "PLATFORM_EDGE_IPS": true, "PLATFORM_APPS_DOMAIN": true, |
| + "AWS_REGION": true, "STATUS_BOX_REGION": true, "STATUS_NAME_REGION": true, "PLATFORM_EDGE_IPS": true, "PLATFORM_APPS_DOMAIN": true, |
| "CONSOLE_DENY_DOMAINS": true, "CONSOLE_HOME_REGION": true, |
| } |
| // AgentOwnedVars are the variables the agent sets, overwrites or |
diff --git a/internal/moves/envreport_test.go b/internal/moves/envreport_test.go| index d9e68a99f..6a749d2b6 100644 |
| --- a/internal/moves/envreport_test.go |
| +++ b/internal/moves/envreport_test.go |
| @@ -430,6 +430,9 @@ func TestBoxVarsCoverTheMeasuredAgentEnvironment(t *testing.T) { |
| "INVOCATION_ID", "JOURNAL_STREAM", "SYSTEMD_EXEC_PID", "MEMORY_PRESSURE_WATCH", "MEMORY_PRESSURE_WRITE", |
| "AWS_REGION", "STATUS_BOX_REGION", "PLATFORM_EDGE_IPS", "PLATFORM_APPS_DOMAIN", |
| "CONSOLE_DENY_DOMAINS", "CONSOLE_HOME_REGION", |
| + // Not measured but the same shape: STATUS_NAME_REGION differs per |
| + // region (regional box names, 2026-10-25). |
| + "STATUS_NAME_REGION", |
| } { |
| if !BoxOwned(name) { |
| t.Errorf("%s differs per box but is not box-owned", name) |