remote-metrics-nested: cut the flat/nested overlap sum (round 2 P2, stopping rule 2)
A host read in both layouts in one tick has no reading that tick, rather than a sum whose CPU delta mixes cgroup sets. Branch review round 2: READY AFTER FIXES.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+69
−8
docs/superpowers/notes/remote-instance-metrics.md+10 −2docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r2.md+31 −0internal/host/metrics_loop.go+8 −5internal/host/metrics_nested_test.go+19 −0internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv+1 −1
CI cancelled — superseded by a newer push — run details
diff --git a/docs/superpowers/notes/remote-instance-metrics.md b/docs/superpowers/notes/remote-instance-metrics.md| index 8925eba28..52859a9ec 100644 |
| --- a/docs/superpowers/notes/remote-instance-metrics.md |
| +++ b/docs/superpowers/notes/remote-instance-metrics.md |
| @@ -315,8 +315,8 @@ 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. The reading names the cgroups it summed (unit and cgroup id), and |
| +A host read in both layouts in one tick (a layout change in flight) has |
| +no reading that tick. The reading names the cgroups it summed (unit and cgroup id), and |
| the sampler takes no CPU delta between two readings of different sets: a |
| unit that went or came makes the difference of two sums wrong. Unit |
| cgroups, never the slice: systemd makes a unit's cgroup new |
| @@ -370,3 +370,11 @@ Round 1 (Astra, 139e04ca): NOT READY. |
| values; mutant killed). |
| - Census: the reviewer approved all six units and the `internal/host` |
| envelope. |
| + |
| +Round 2 (Astra, 67934c7d): READY AFTER FIXES. Round 1's P1 resolved; its |
| +P2 partly: summing a host's flat and nested readings during a layout |
| +overlap still mixed cgroup sets. That is the second round in the CPU |
| +continuity family, so under stopping rule 2 the overlap summing was cut |
| +rather than patched again: a host read in both layouts in one tick has no |
| +reading that tick (`TestMergeNestedCutsAnOverlap`). Census: the changed |
| +units and envelope approved. The branch review stops here. |
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r2.md b/docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r2.md| new file mode 100644 |
| index 000000000..faf985038 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-remote-metrics-nested-r2.md |
| @@ -0,0 +1,31 @@ |
| +- Round 1 P1 — **Resolved:** cgroup identity tests are now Linux-only; the pure aggregation test remains cross-platform. |
| +- Round 1 P2 — **Partly resolved:** nested-only readings track membership, but combining flat and nested readings loses it. |
| + |
| +Reviewed commit `67934c7d9522a336a2eb3f3c8f0c902809e5c28d` against merge base `4dc5902d4f244a3de346b258660950472df9b07a`, round **2 of 3**. |
| + |
| +1. **P2 — Section 2: merged readings still subtract counters from different cgroup sets.** |
| + **Fault family: CPU counter continuity.** |
| + |
| + [mergeNested, metrics_loop.go:892](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_loop.go:892) combines flat and nested readings using `sumUnitRaw`. That function leaves `members` empty ([metrics_nested.go:130](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested.go:130)), discarding the nested identities. The sampler therefore accepts the previous counter when both membership strings are empty ([metrics_loop.go:108](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_loop.go:108)). |
| + |
| + **Failure scenario:** during the explicitly supported layout overlap, one tick reads flat CPU at 100 seconds plus nested CPU at 20. Sixty seconds later, the nested cgroup is gone and flat CPU reads 130. Both readings have empty membership, so CPU reports `(130−120)/60 = 16.7%`, although the surviving flat cgroup consumed 50%. |
| + |
| + **Fix:** preserve the complete contributing set through aggregation, including flat participation, and rebaseline whenever it changes. Add an exact-value regression covering mixed-to-flat readings. The current regression supplies an empty exec root ([metrics_nested_linux_test.go:150](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested_linux_test.go:150)), so it misses this path. |
| + |
| + This is the second consecutive round in this fault family. Stopping rule 2 applies: choose a gate refusing overlapping layouts, remove overlap aggregation, or enforce membership continuity centrally with a guard test. I recommend the third option. |
| + |
| +Census verdicts concern authority and read boundaries; they do not clear the functional finding above. |
| + |
| +| Unit or envelope | Verdict and evidence | |
| +|---|---| |
| +| `nestedUnitReadings` | **APPROVE.** [metrics_nested.go:95](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_nested.go:95) retains the existing read-only identity lookup and leftover checks; the revision records and sorts those identities. `legacy/accepted-legacy` remains appropriate. | |
| +| `sampler.tick` | **APPROVE.** [metrics_loop.go:108](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_loop.go:108) compares in-memory membership before calculating CPU. Leftover tag removal still precedes `CarryTags`. No new privileged read or authority. | |
| +| `internal/host` envelope | **APPROVE.** Reviewed the changed wiring, readers, aggregation and platform-specific tests. [metrics_loop.go:651](/home/paulca/amadan.net/carlos/platform-remote-metrics-nested/internal/host/metrics_loop.go:651) adds local sampling only; no new store request, root execution or write authority. | |
| + |
| +Round-one census approvals for the other units stand. No additional P1 or P3 findings. |
| + |
| +Changed Go files pass formatting and whitespace checks. Targeted tests could not start because the sandbox refused Go’s work-directory creation. Root-runner and mutation results were not independently rerun. No files changed. |
| + |
| +No P1 remains: this review stops here; address the P2 under the stopping rules without reopening a whole-branch round. |
| + |
| +**READY AFTER FIXES** |
| \ No newline at end of file |
diff --git a/internal/host/metrics_loop.go b/internal/host/metrics_loop.go| index a9ec19365..a45982ed6 100644 |
| --- a/internal/host/metrics_loop.go |
| +++ b/internal/host/metrics_loop.go |
| @@ -877,9 +877,12 @@ func metricsLoop(execRoot string, src unitSources, owners func() map[string]metr |
| } |
| } |
| -// mergeNested adds nested hosts' readings to the flat scan's. A host with |
| -// both (a layout change in flight) is summed: both are its processes, under |
| -// the same activator entry rule. |
| +// mergeNested adds nested hosts' readings to the flat scan's. A host |
| +// with both in one tick (a layout change in flight) gets no reading that |
| +// tick: summing two layouts' counters made CPU deltas across unit sets |
| +// that come and go (Astra, nested branch rounds 1 and 2), so the overlap |
| +// is cut rather than reconciled. It is transient: the next tick reads |
| +// whichever layout is left. |
| func mergeNested(flat, nested map[string]unitRaw) map[string]unitRaw { |
| if len(nested) == 0 { |
| return flat |
| @@ -888,8 +891,8 @@ func mergeNested(flat, nested map[string]unitRaw) map[string]unitRaw { |
| flat = make(map[string]unitRaw, len(nested)) |
| } |
| for name, n := range nested { |
| - if f, ok := flat[name]; ok { |
| - flat[name] = sumUnitRaw([]unitRaw{f, n}) |
| + if _, both := flat[name]; both { |
| + delete(flat, name) |
| continue |
| } |
| flat[name] = n |
diff --git a/internal/host/metrics_nested_test.go b/internal/host/metrics_nested_test.go| index 7d34a9165..2e7a0f578 100644 |
| --- a/internal/host/metrics_nested_test.go |
| +++ b/internal/host/metrics_nested_test.go |
| @@ -13,3 +13,22 @@ func TestSumUnitRaw(t *testing.T) { |
| t.Fatal("a leftover part did not make the sum a leftover") |
| } |
| } |
| + |
| +// TestMergeNestedCutsAnOverlap: a host read in both layouts in one tick |
| +// (a layout change in flight) has no reading that tick, rather than a sum |
| +// whose CPU delta would mix cgroup sets (Astra, nested branch round 2). |
| +func TestMergeNestedCutsAnOverlap(t *testing.T) { |
| + one := int64(1) |
| + flat := map[string]unitRaw{"carlos-exec@both.example.com": {cpuUsec: &one}, "carlos-exec@flat.example.com": {cpuUsec: &one}} |
| + nested := map[string]unitRaw{"carlos-exec@both.example.com": {cpuUsec: &one, members: "a#1"}, "carlos-exec@nested.example.com": {cpuUsec: &one, members: "b#2"}} |
| + got := mergeNested(flat, nested) |
| + if _, ok := got["carlos-exec@both.example.com"]; ok { |
| + t.Fatalf("an overlapping host kept a reading: %+v", got["carlos-exec@both.example.com"]) |
| + } |
| + if _, ok := got["carlos-exec@flat.example.com"]; !ok { |
| + t.Fatal("a flat host lost its reading") |
| + } |
| + if n, ok := got["carlos-exec@nested.example.com"]; !ok || n.members != "b#2" { |
| + t.Fatalf("a nested host's reading = %+v", n) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv b/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv| index fee9d8493..72313ac97 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-remote-metrics-nested.tsv |
| @@ -12,4 +12,4 @@ internal/host/agent.go routeHostNames legacy accepted-legacy accepted-legacy;rev |
| 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, and names the cgroups it summed (unit and cgroup id); read-only, world-readable cgroupfs files; root never calls it file:ReadDir@226 442f0e537ceb7cf207dba4d22f36c72b25f84057ee78a191d0eef0928e179605 |
| 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 3476df1ecdefdb3bf472740f058464c8e360187ef9547cf8dd255f82545d5034 |
| +@coverage internal/host 8c203b532f1ac17e48d00b4c2b96bd06fa29eb30c06690d145f1e9210471f7a2 |