carlos / platform Public

remote-metrics-nested: note section and census proposal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ad74768c5dda64d2cadac01e0f68ff8807a00026 parent dea5a7e
4 files changed, +101 −0
  • docs/superpowers/notes/census-proposal-remote-metrics-nested.md +28 −0
  • docs/superpowers/notes/remote-instance-metrics.md +57 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv +15 −0

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/notes/census-proposal-remote-metrics-nested.md b/docs/superpowers/notes/census-proposal-remote-metrics-nested.md
new file mode 100644
index 000000000..9ff20c415
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-remote-metrics-nested.md
@@ -0,0 +1,28 @@
+# Census approval: remote-metrics-nested
+
+Ruling `census-ruling-remote-metrics-nested`. The independent reviewer approves or rejects every change below, 4 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/host/agent.go` `runAgent` | body | unchanged (5) | snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself |
+| `internal/host/metrics_loop.go` `sampler.tick` | body | unchanged (1) | clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags; no read added |
+
+Envelopes re-pinned: `internal/host`.
+
+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.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/host/agent.go` `runAgent`: authority, task B,C,D,F. Basis: rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself
+- `internal/host/metrics_loop.go` `sampler.tick`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-remote-instance-metrics;basis=calls the owners probe before and after the unit read and tags readings with metrics.TagUnits and metrics.CarryTags; no read added
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/host/agent.go:routeHostNames`: reads +registry:Host, +whole:Route ×2; written legacy, accepted-legacy, frozen
+- new `internal/host/metrics_nested.go:nestedUnitReadings`: reads +file:ReadDir; written legacy, accepted-legacy, frozen
+- new `internal/host/metrics_nested.go:snapshotNestedUnits`: reads +file:ReadDir ×2; written legacy, accepted-legacy, frozen
+- new `internal/host/metrics_nested_linux.go:cgroupID`: reads +file:Stat; written legacy, accepted-legacy, frozen
+
+Seal: `ed0d770a827bdb37a87d21e5c8efb259ca0de88457b0cb3202ebb006fc0cd032` → `5a1cc50b9465ed19098fb9b0557324acb622bd84e1621157788af63a702ce4a3`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/notes/remote-instance-metrics.md b/docs/superpowers/notes/remote-instance-metrics.md
index dda421d65..f7ad52580 100644
--- a/docs/superpowers/notes/remote-instance-metrics.md
+++ b/docs/superpowers/notes/remote-instance-metrics.md
@@ -295,3 +295,60 @@ instances are all on other boxes, because remote readings were cut; with
untagged samples it now reads the existing "no recent data" (the sweep
was read and nothing in it is this tenant's), and the test says so.
`ResourcesUnavailable` means a failed sweep or no instance at all.
+
+## Follow-up: nested instances (branch remote-metrics-nested)
+
+The release agent found that 4dc5902d gave no readings to nested
+(isolated exec) instances, and a box running only nested instances
+(every instance on it) showed only its platform services in its chunks.
+
+**Root cause.** The sampler read `carlos-*.service` cgroups directly under
+`system.slice` and `carlos.slice`, plus the children of `system-*.slice`.
+A nested host's units (`carlos-instance@`, `-gen@`, `-sidecar@`, `-seed@`,
+`-cmd@`, the rootfs templates) run two slices deeper, at
+`carlos.slice/carlos-instances.slice/carlos-instances-<id>.slice/<unit>`
+(`instancectl.SliceName`). Nothing read there, so nested instances had no
+readings on any box, the console's own box (local rows) included.
+
+**Now.** Each tick reads, for every host the registry has a route for,
+the unit cgroups in its nested slice (`nestedUnitReadings`), sums them
+(a field only when every unit has it; peaks are not summed) and
+publishes the sum as `carlos-exec@<host>`, the name a flat host reports
+under, so the console's per-host match and tenant filter need no change.
+A host with both a flat cgroup and a slice (a layout change in flight) is
+summed. Unit cgroups, never the slice: systemd makes a unit's cgroup new
+at each start, while the slice keeps the charges of units that stopped,
+an earlier tenant's included.
+
+Tags follow the rule above unchanged: the activator's entries
+(`putEntryLocked`, `Tenancies`: one tenant ever for the host in this
+agent's life), the registry row agreeing, the reads before and after the
+cgroup read, and the previous tick (`CarryTags`). The nested layout's
+leftover is per unit: before the activator can start anything, the agent
+records the cgroup ids (inodes, never reused while the box is up) of
+every unit then in the layout (`snapshotNestedUnits`). Nested units are
+`BindsTo=carlos-edge.service`, so a previous agent's units stop with it,
+but a stop can still be in flight; a reading that includes one of those
+units, or a unit whose id cannot be read, or any reading after a layout
+that could not be listed, is never vouched. Once that unit goes, the
+first reading is still untagged (its CPU delta starts from the leftover's
+counter) and the next is tagged.
+
+**Request budget.** No new request: the same chunk, one more entry per
+nested instance. On the box, two more registry listings and one directory
+listing per route host per minute, all local.
+
+**Tests.** `internal/host/metrics_nested_test.go`: a real activator waking
+and stopping through a stand-in backend, a real registry, the nested
+cgroup tree laid out as systemd does, the sampler's tick and flush: a
+nested instance is sampled, summed and tagged; a reused hostname under the
+nested layout is never tagged; an agent restart with a unit still there
+is untagged until it goes; an unlistable layout vouches nothing.
+`TestRootRunnerNestedUnitsAreSampled` (root runner, real systemd units in
+the real slice tree via systemd-run): readings have CPU and memory, a unit
+the snapshot held is a leftover, and the same unit started again is a new
+id. Passed in run 20261026T194200-02064e. Mutations: 8, all killed.
+
+**Still not sampled.** Unit-backed `carlos-app@` tenants (systemd starts
+them, including by socket activation, and they can outlive the agent) and
+instances that never sleep (no activator entry vouches for them).
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 3943d3a67..8075f29b2 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -3,3 +3,4 @@
plan14-root-reads-c2-root-exec-inputs.tsv 0ef813eebfb1a2e2812d897c4f0b5fd7f75e3e39c7602cf64d1634e8374327af
plan14-root-reads-label-case-running-tile.tsv 0ef813eebfb1a2e2812d897c4f0b5fd7f75e3e39c7602cf64d1634e8374327af
plan14-root-reads-remote-instance-metrics.tsv ed0d770a827bdb37a87d21e5c8efb259ca0de88457b0cb3202ebb006fc0cd032
+plan14-root-reads-remote-metrics-nested.tsv 5a1cc50b9465ed19098fb9b0557324acb622bd84e1621157788af63a702ce4a3
diff --git a/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv b/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv
new file mode 100644
index 000000000..cba38bc19
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv
@@ -0,0 +1,15 @@
+# Census overlay remote-metrics-nested, written by census-propose (#369). census-ruling-remote-metrics-nested, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-remote-metrics-nested.md.
+# 2 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 4 new dispositions: 0 reads re-frozen at their disposition with the claim, 4 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 99d191aa6dd304aa060b5c321552431c4d6b2c4d030920bface2ea34fbf07154 internal/host/metrics_loop.go sampler.tick legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-remote-instance-metrics;basis=calls the owners probe before and after the unit read and tags readings with metrics.TagUnits and metrics.CarryTags; no read added;rev3=census-ruling-remote-metrics-nested;basis=clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags; no read added file:ReadBytes@963 4789ff4d04c00a2c5ac99fd868e64a794eed38b36db818fe488f669e0c1e2add
+@legacy 4732421e39880404f16930726c01362c30d092a4869c8ee7e9a9b963fc9be0f5 internal/host/agent.go routeHostNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: lists the agent's own registry for its route hosts (as stampedUnitNames does each tick) for the nested slice reads; no file path, nothing written registry:Host@261,whole:Route@203,whole:Route@232 9d2f7f2de05da66145e8e229b5dca737593b3ebfd6455fa83791fe1bb869c711
+@legacy e46e9eb10dcb71ada6f9ea5ff88eba98c93559eafc0ea5f1be991662ac7162e4 internal/host/metrics_nested.go nestedUnitReadings legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent (user carlos), lists each route host's nested slice dir under the fixed cgroupfs root (path from instancectl.SliceName of a registry host, which escapes everything but [A-Za-z0-9:_.]) and reads its unit cgroups' cpu.stat, memory.current, memory.peak and io.stat through readUnitRaw, as the sampler already does for other units; read-only, world-readable cgroupfs files; root never calls it file:ReadDir@226 333995b2c499b6535e7db9104248fa2540d2fc6b1f8c86606459421f7b8cb99a
+@legacy fdba9404918aa1ff51552f42cb6c917393981f78dbdba238bec34ce19e1e1387 internal/host/metrics_nested.go snapshotNestedUnits legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent, once at start, lists the fixed nested layout root and its slices and records each unit cgroup's inode; read-only; root never calls it file:ReadDir@370,file:ReadDir@68 19a49124d843519691de7b4dce2adb0e727cc637974c2c9f375e35d10ea6430e
+@legacy cb395998f3fc6f6bd8660c377171c199bf5282bfa4c8401729983a5b170926cf internal/host/metrics_nested_linux.go cgroupID legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: stats a cgroup dir for its inode (the cgroup id); read-only; root never calls it file:Stat@55 a42cbf096d2fc142026a764ddb19788e500fee5f197eec5cfd88e158735b8b4b
+internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself;rev3=census-ruling-remote-metrics-nested;basis=snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself file:Exec@15646,file:Open@1150,registry:App@10927,whole:Route@10919,whole:Route@25822 76515f7210520c335e157c9dd72181eace54ba1c4ffcd005e516e12404bc54df
+internal/host/metrics_loop.go sampler.tick legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-remote-instance-metrics;basis=calls the owners probe before and after the unit read and tags readings with metrics.TagUnits and metrics.CarryTags; no read added;rev3=census-ruling-remote-metrics-nested;basis=clears the tenant tag of a reading marked leftover (a nested unit present at agent start) before CarryTags; no read added file:ReadBytes@963 4789ff4d04c00a2c5ac99fd868e64a794eed38b36db818fe488f669e0c1e2add
+internal/host/agent.go routeHostNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: lists the agent's own registry for its route hosts (as stampedUnitNames does each tick) for the nested slice reads; no file path, nothing written registry:Host@261,whole:Route@203,whole:Route@232 9d2f7f2de05da66145e8e229b5dca737593b3ebfd6455fa83791fe1bb869c711
+internal/host/metrics_nested.go nestedUnitReadings legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent (user carlos), lists each route host's nested slice dir under the fixed cgroupfs root (path from instancectl.SliceName of a registry host, which escapes everything but [A-Za-z0-9:_.]) and reads its unit cgroups' cpu.stat, memory.current, memory.peak and io.stat through readUnitRaw, as the sampler already does for other units; read-only, world-readable cgroupfs files; root never calls it file:ReadDir@226 333995b2c499b6535e7db9104248fa2540d2fc6b1f8c86606459421f7b8cb99a
+internal/host/metrics_nested.go snapshotNestedUnits legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: as the agent, once at start, lists the fixed nested layout root and its slices and records each unit cgroup's inode; read-only; root never calls it file:ReadDir@370,file:ReadDir@68 19a49124d843519691de7b4dce2adb0e727cc637974c2c9f375e35d10ea6430e
+internal/host/metrics_nested_linux.go cgroupID legacy accepted-legacy accepted-legacy;rev3=census-ruling-remote-metrics-nested;basis=new: stats a cgroup dir for its inode (the cgroup id); read-only; root never calls it file:Stat@55 a42cbf096d2fc142026a764ddb19788e500fee5f197eec5cfd88e158735b8b4b
+@coverage internal/host 023493f7c44f91162122fe7ec8eadcfec730d9777bfc0c69c3f0627ce6ce70b2