carlos / platform Public

spec: instance memory alert rev 3, pressure-only (Paul's cut, #1005)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 0ab9bb57fea76dc84ee836e707ae89b625f02f9d parent f49b2b3
1 file changed, +119 −142
  • docs/superpowers/specs/2026-11-13-instance-memory-alert-design.md +119 −142

CI cancelled — superseded by a newer push — run details

Intent

Attributed to this commit: 222 g CO₂e (22,981,757 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on plan-tito-nesting-moves, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/specs/2026-11-13-instance-memory-alert-design.md b/docs/superpowers/specs/2026-11-13-instance-memory-alert-design.md
index b99b67626..d0c9e198d 100644
--- a/docs/superpowers/specs/2026-11-13-instance-memory-alert-design.md
+++ b/docs/superpowers/specs/2026-11-13-instance-memory-alert-design.md
@@ -1,163 +1,137 @@
# Instance memory alert (#996): design
-Status: rev 2, after Astra round 1. Grounded in origin/main 4c641678.
-Owner-facing strings are drafts for a later copy review.
+Status: rev 3, after Astra round 2 and Paul's cut on #1005 (v1 is sustained
+pressure only). Needs Paul's approval before planning. Grounded in origin/main
+4c641678. Owner-facing strings are drafts for a later copy review.
## 1. Why
-Nothing tells an owner that one instance is running out of room. The cap is
-real: `memory.max` from the size, `memory.high` at 90 percent
-(`internal/cgroup/cgroup.go:158-161`, `:771-783`), `memory.oom.group=1`
-(`cgroup.go:764-766`). Box memory is watched (`internal/host/memwatch.go:21-33`);
-instances are not. Triggers: #992 (which customer outgrew shared hosting) and
-the nesting plan's W2 batches (`docs/superpowers/plans/2026-11-13-tito-nesting-and-self-serve-moves.md` W5).
+Nothing tells an owner that one instance is short of memory. The cap is real:
+`memory.max` from the size, `memory.high` at 90 percent
+(`internal/cgroup/cgroup.go:158-161`, `:771-783`). Box memory is watched
+(`internal/host/memwatch.go:21-33`); instances are not. Triggers: #992 (which
+customer outgrew shared hosting) and the nesting plan's W2 batches
+(`docs/superpowers/plans/2026-11-13-tito-nesting-and-self-serve-moves.md` W5).
## 2. Goals, non-goals, anti-goals
-- **Goals.** Owner and operator see, per instance, "under memory pressure"
- and "stopped for using all its memory", with the next step.
+- **Goal.** Owner and operator see, per instance, "short of memory" while
+ pressure is sustained, with the next step.
- **Scope.** Vouched instance kinds only: exec cgroups (flat) and nested
units, both keyed `carlos-exec@<host>` (`internal/metrics/owner.go:35-57`,
`internal/host/metrics_nested.go:71-73`).
-- **Non-goals.** `carlos-app@` units and stamped or platform units: nothing
- vouches them (`owner.go:39-41`). Changing sizes; forecasts; the move (#992).
+- **Non-goals.**
+ - Stops for memory (OOM kills). Proving why one exit happened needs an
+ unconditional, per-exit lifecycle record, which is its own design.
+ Follow-up: a new amadan discussion, to be filed.
+ - `carlos-app@`, stamped and platform units: nothing vouches them
+ (`owner.go:39-41`).
+ - Changing sizes, forecasts, the move itself (#992).
- **Anti-goals.** Noise; any new S3 object or per-box polling; any root read.
-## 3. Two signals, two mechanisms
-
-### 3.1 Stops for memory: lifecycle, not sampling
-
-Kills are not sampled; a cgroup can die between ticks. They are recorded
-where the platform already handles a process ending:
-
-- **Nested units.** On exit the activator already runs `systemctl show -p
- InvocationID,ExecMainCode,ExecMainStatus,...` and matches the invocation
- (`internal/activator/control.go:151-167`, `unitproc.go:581-597`). Add
- `Result` to that one call: `oom-kill` is systemd's own word, set under the
- templates' `OOMPolicy=kill` (`internal/instancectl/gen.go:44`). It counts
- only when the host slice's `oom` counter also grew since the spawn, as
- systemd may say `oom-kill` for a box-wide OOM too (unknown: check
- systemd's `unit_check_oom`). Not the exit
- record: it is advisory and written inside the instance's namespace
- (`instancectl/names.go:604-606`, `instanceexec/exit.go:26-32`). Unknown:
- whether `Result` still reads `oom-kill` on systemd 257 with PrivatePIDs,
- given `unitproc.go:576-579`; check by forcing an OOM in a nested unit on dev.
-- **Flat exec.** The wait goroutine (`internal/activator/backend_exec.go:2737-2754`)
- reads the boundary's `memory.events` once at spawn and once after
- `cmd.Wait()`, before `RemoveChild`. A SIGKILL exit with the `oom` counter
- grown (this cgroup's own limit was hit) is a stop for memory. `oom_kill`
- and `oom_group_kill` are not used: a box-wide OOM moves them too.
-
-The activator counts these per instance incarnation (§4) since the agent
-started, with the time of the last one. One stop is one count, however many
-processes the group kill took.
-
-### 3.2 Pressure: the 60 s sampler
-
-The metrics sampler (`internal/host/metrics_loop.go:1-8`, `:1024`) already
-reads every vouched instance cgroup (`metrics_probes.go:223-241`,
-`metrics_nested.go:80-111`). It adds `memory.events` `high`, `memory.pressure`
-`some avg60`, `memory.current` and `memory.max` at the boundary (§3.3). No
-production code reads `memory.events` per cgroup today; tests do
-(`internal/host/size_rootrunner_linux_test.go:213-221`). Losing a minute here
-is harmless.
+## 3. The signal
-`memory.current` near `memory.max` is never a trigger: the charge includes
-page cache (`cgroup.go:758-762`). The box reports one current state per
-instance, never history:
+The 60 s metrics sampler (`internal/host/metrics_loop.go:1-8`, `:1024`)
+already reads every vouched instance's cgroups (`metrics_probes.go:223-241`,
+`metrics_nested.go:80-111`). For each instance it adds four reads at the
+boundary (§3.1): `memory.events` `high`, `memory.pressure` `some avg60`,
+`memory.current` and `memory.max`. No production code reads `memory.events`
+per cgroup today; tests do (`internal/host/size_rootrunner_linux_test.go:213-221`).
-| State | Rule (proposal, calibrate first) |
-|---|---|
-| `pressure` | `high` grew in at least 8 of the last 10 read minutes and `some avg60` at or above 5 percent |
-| `ok` | from `pressure`: `some avg60` below 1 percent for 15 read minutes, whatever `high` does (cheap reclaim cannot hold it open) |
-| `asleep` | no process |
-| `swapping` | a generation swap is under way (`sizestatus.go:106-108`) |
-| `unavailable` | a read failed, no PSI, an unvouched reading, or a root-run agent |
-
-`asleep`, `swapping` and `unavailable` pause the windows: they neither fire
-nor clear. Without PSI there is no verdict: `high` alone cannot tell a full
-page cache from pain. memwatch reads PSI on every armed box (`memwatch.go:28`);
-unknown whether every box has per-cgroup `memory.pressure`: check with
-`cat` on a nested slice on dev and on a Pi. An agent restart starts the
-windows empty (`metrics_loop.go:982`); the console owns episodes, so that
-only delays a fire.
-
-### 3.3 The boundary per layout
-
-The monitored cgroup is the one whose `memory.max` is the instance's size,
-resolved as `readSizeInForce` does (`internal/host/sizestatus.go:64-100`).
-Usage, limit and events all come from that one cgroup, read hierarchically
-there and never summed, so nothing is counted twice.
-
-| Layout | Boundary |
+`memory.current` near `memory.max` is never a trigger: the charge includes
+page cache (`cgroup.go:758-762`). `high` alone cannot tell a full cache from
+pain, so PSI is required.
+
+### 3.1 The boundary: the instance's top cgroup
+
+One cgroup per instance: the top of its subtree. Flat, that is
+`carlos-exec@<host>` (`cgroup.go:449`). Nested, it is the host slice
+(`metrics_nested.go:16-22`, `:83`). Every cap below it (a generation's, the
+parent's) and every sibling that shares the parent's budget (seed, sidecar;
+`cgroup/gen.go:21-23`, `:261-264`, `:300-318`) sits inside it. `memory.events`
+and `memory.pressure` are hierarchical, so a breach of any cap in the subtree
+shows at the top, once, under one subject. Unknown: check that boxes mount
+cgroup2 without `memory_localevents` (`grep cgroup2 /proc/mounts`).
+
+The figure shown is the top's `memory.current` against the size in force
+(`internal/host/sizestatus.go:64-100`); the words never say which cap.
+During a swap the parent holds two tiers summed (`gen.go:54-58`), so the
+state is `swapping` (`sizestatus.go:106-108`). A new cgroup id
+(`metrics_nested_linux.go:13`) or a smaller counter is a fresh baseline,
+never a negative delta.
+
+### 3.2 Evidence, not a latch
+
+The box keeps no episode state. Each heartbeat carries, per instance, the
+evidence over its own recent readable minutes:
+
+- `high_minutes`: minutes of the last 10 in which `high` grew
+- `psi_now`, and `psi_max_15`: the highest `some avg60` of the last 15
+ minutes
+- `read_minutes`: readable minutes since the baseline (capped at 15)
+- `state`: `measured`, `asleep`, `swapping` or `unavailable` (a failed read,
+ no per-cgroup PSI, an unvouched reading, a root-run agent)
+
+The console applies the rules (proposals; calibrate first):
+
+| Rule | Condition |
|---|---|
-| Flat exec | `carlos-exec@<host>` (`cgroup.go:449`), or the serving `g<n>` under the generation layout (`cgroup/gen.go:17-24`) |
-| Nested, native | the serving generation unit's cgroup, else the host slice (`sizestatus.go:69-81`) |
-| gVisor | the retained unit, at the physical limit (`sizestatus.go:90-93`) |
+| Fire | `measured`, `read_minutes` at least 10, `high_minutes` at least 8, `psi_now` at least 5 percent |
+| Clear | `measured`, `read_minutes` 15, `psi_max_15` below 1 percent, whatever `high` does |
+| Hold | anything else |
-During a swap the parent holds the two tiers summed (`cgroup/gen.go:54-58`),
-so it is never the boundary, and the state is `swapping`. A successor that
-overruns dies alone and is reported as a release refusal
-(`internal/status/snapshot.go:751-754`), not here. Role children (seed,
-sidecar) have no limit of their own (`gen.go:21-22`) and are outside the
-signal.
+Hold keeps the last state, as the engine already does for a source it could
+not read (`internal/console/alertsignals.go:17-18`). So an agent restart, a
+wake, a swap or a move starts the box's minutes from zero and holds: it
+neither clears an open episode nor fires a new one until the evidence is
+complete. No PSI means `unavailable`, a hold for good, never a verdict.
## 4. Identity, carrier, judge, display
**Identity.** Every entry carries account, app and the record's incarnation,
`provision.Incarnation(account, app, host, created)`
(`internal/provision/incarnation.go:17-23`), which the box already computes
-(`internal/activator/wakeidentity.go:255`). A reused hostname gets a new
-incarnation.
+(`internal/activator/wakeidentity.go:255`).
**Carrier.** The 5-minute heartbeat's private `Metrics` block
-(`internal/status/fleet.go:120`, `snapshot.go:579-583`), one map keyed by
-host: state, minutes in state, current, max, stop count, last stop time.
-Only instances not `ok`, or with a stop since agent start, get an entry. That
-adds bytes to an existing PUT, no request.
-
-**Judge.** The alerts engine owns episodes, dedup and suppression. It reads
-heartbeats every fifth pass (`internal/console/alertengine_pass.go:46-51`).
-- Subject: incarnation, so restarts and wakes never open a new episode, and
- the flapping and 24-hour quiet rules (alerts spec §6 rules 7, 8) hold
- against deliberate kill loops.
-- Stops dedupe on (incarnation, box, last stop time); count deltas add up.
-- After a move, pressure comes from the box serving the host now. Stops from
- any box count.
-- Account and app scope is the alerts spec's Plan 3, not built; today the
- engine has fleet scope only (`alertsignals.go:444-450`).
-
-**Display and routing.** Before showing or routing an entry, the console
-checks account, app and incarnation against the authorized record and drops
-any mismatch. This is the rule `metricsview.go:873-885` and
-`apiinstances.go:552-558` apply to resource readings. Shown in REASON
+(`internal/status/fleet.go:120`, `snapshot.go:579-583`), one entry for every
+vouched instance the box holds. Omission means the box no longer holds it;
+it never means `ok`. That adds bytes to an existing PUT, no request.
+
+**Judge.** The alerts engine owns episodes, reading heartbeats every fifth
+pass (`internal/console/alertengine_pass.go:46-51`). The subject is the
+incarnation, so wakes and restarts never open a new episode. Its one member
+is the box serving the host now; after a move, the new box holds until its
+evidence is complete. A non-firing signal removes a firing member
+(`alertengine.go:192-208`), so only Clear may send one; Hold sends none.
+Account and app scope is the alerts spec's Plan 3, not built; today the
+engine has fleet scope only (`alertsignals.go:444-450`).
+
+**Display and routing.** The console checks account, app and incarnation
+against the authorized record and drops any mismatch, as
+`metricsview.go:873-885` and `apiinstances.go:552-558` do. Shown in REASON
(`instances_cli.go:713-727`, joined at `apiinstances.go:1096`), on the
instance page and in alerts.
-**Latency.** Ten minutes to `pressure`, then up to 5 each for the heartbeat,
+**Latency.** Ten minutes of evidence, then up to 5 each for the heartbeat,
the engine's read and its grouping hold (`alertengine.go:77`): about 25
minutes at most. Fine for a warning.
## 5. Privilege and census
-The agent runs as `carlos` (`internal/host/units/carlos-edge.service:41`).
-cgroupfs files are kernel-written, and the activator's `systemctl show` call
-needs no privilege (`control.go:151-155`). The new readers take the same
-effective-UID gate as the engine beat and the verify watch
-(`metrics_loop.go:971-1003`): a root-run agent reads nothing and reports
-`unavailable`. The changes touch `internal/host` and `internal/activator`, so
-they are in the census scope (`AGENTS.md:337-370`). The plan needs a census
-proposal and an independent reviewer's approval.
+The agent runs as `carlos` (`internal/host/units/carlos-edge.service:41`);
+cgroupfs files are kernel-written. The new reads take the effective-UID gate
+the engine beat and verify watch use (`metrics_loop.go:971-1003`): a root-run
+agent reads nothing and reports `unavailable`. The changes touch
+`internal/host`, so they are in census scope (`AGENTS.md:337-370`) and need
+an independent reviewer's census approval.
## 6. Words (drafts)
-- REASON: `memory: under pressure for 25 min, 470 of 512 MB`
-- REASON: `memory: stopped 3 times today for using all its memory`
-- Page: "Under memory pressure" / "Stopped for using all its memory" /
- "Memory OK" / "Asleep".
+- REASON: `memory: short of memory for 25 min, 470 of 512 MB`
+- Page: "Short of memory" / "Memory OK" / "Asleep" / "Not measured".
- Alert: "shop-42.example.com has been short of memory for 10 minutes and is
slowing down. Next step: a bigger size, or its own box."
-- Alert: "shop-42.example.com was stopped at 14:07 for using all its memory."
- Clear: "shop-42.example.com is no longer short of memory."
## 7. Approaches
@@ -172,9 +146,9 @@ Calibrate first: a week reporting only, counting would-be fires.
## 8. Left to the builder
-Field names and the map's cap; tests: an OOM and a wake entirely between two
-ticks, before the first tick, a cache-heavy fixture, no PSI, and recovery
-with `high` still rising.
+Field names; tests: a cache-heavy fixture, no PSI, recovery with `high`
+still rising, a sidecar pressing the parent cap, agent restart mid-episode,
+a move mid-episode.
## 9. Open questions for Paul
@@ -182,23 +156,26 @@ with `high` still rising.
minimal app scope now?
2. The next step: `carlos instances set --size` is operator-only
(`docs/site/cli.md:1348`) and #992 does not exist yet. "Contact us"?
-3. Is a stop for memory an incident or a warning?
-4. Replace "too busy"'s memory half (alerts spec §7.3) with this?
+3. Replace "too busy"'s memory half (alerts spec §7.3) with this?
## Round 1 dispositions
-1. P1 OOM lost between samples: accepted. Kills come from lifecycle at exit
- (§3.1); nothing samples them.
-2. P1 tenant identity: accepted. Account, app and incarnation travel with
- every entry; the console drops mismatches (§4).
-3. P2 episode continuity: accepted. The box reports current state only;
- the engine owns episodes keyed by incarnation; asleep, swapping and
- unavailable pause windows (§3.2, §4).
-4. P2 wording beyond evidence: accepted. "Stopped for using all its memory"
- from the cgroup's `oom` counter (with systemd's Result when nested); no
- restart claim (§6).
-5. P2 boundary: accepted. One cgroup per layout, swaps paused (§3.3).
-6. P2 PSI and recovery: accepted. No PSI, no verdict; clear on low PSI (§3.2).
-7. P2 vouch scope: accepted. `carlos-app@` and stamped units are non-goals (§2).
-8. P2 privilege and census: accepted. Effective-UID gate; census applies (§5).
-9. P3 facts: accepted. The test reader and the 5-minute hold are in §3.2, §4.
+1. P1 OOM lost between samples: cut in rev 3 (§2).
+2. P1 tenant identity: accepted (§4).
+3. P2 episode continuity: accepted; reworked in rev 3 (§3.2, §4).
+4. P2 wording beyond evidence: falls away with the cut; pressure words only.
+5. P2 boundary: accepted; reworked in rev 3 (§3.1).
+6. P2 PSI and recovery: accepted (§3.2).
+7. P2 vouch scope: accepted (§2).
+8. P2 privilege and census: accepted (§5).
+9. P3 facts: accepted (§3, §4).
+
+## Round 2 dispositions
+
+1. P1 nested exits not all captured: falls away; stops are a non-goal (§2).
+2. P2 parent cap missed: accepted. The boundary is the instance's top cgroup,
+ whose hierarchical events and PSI cover every cap and sibling (§3.1).
+3. P2 cause of exit: falls away with the cut.
+4. P2 hysteresis across restarts and moves: accepted. The box sends evidence,
+ not a latch; incomplete evidence holds; omission is defined (§3.2, §4).
+5. P2 stop totals: falls away with the cut.