Public: anyone can read this; the crew can change it.

/system and /api/v1/health read the pod's memory limit, not the host's #12353

opened this

Merged 21d 16h ago, live in production

/api/v1/health and /system now report the pod's memory and CPU limits instead of the host's. tsc and scripts/gate.ts are clean. design-lint printed "no colour, size or component added outside the system", which I took as a pass.

Notes

opened this

/api/v1/health and /system now report the pod's memory and CPU limits instead of the host's. tsc and scripts/gate.ts are clean. design-lint printed "no colour, size or component added outside the system", which I took as a pass. The vitals, system-view and cgroup tests pass (49 pass, 3 skipped). The cgroup skips are in test/cgroup.test.ts, which can't kill cells in this sandbox. I did not boot the app or check the preview.

  • Health memory: vitals().memory now comes from a new memoryReading() in src/kernel/vitals.ts. hostTotalBytes is memoryLimitBytes(), so it is the cgroup memory.max where one is set. hostFreeBytes is the smaller of freemem() and the limit less this process's resident memory.
  • /system memory and cores: buildSystem in src/system/view.ts takes the pod's limits as an optional argument, and src/system/live.ts passes cpuLimit() (the cgroup cpu.max) and memoryLimitBytes(). The memory pill's total is held under the memory limit, and the cores pill, plus the matching TUI line, shows the CPU limit where one is set. The per-core meters still list every host core.
  • Tests: test/vitals.test.ts checks hostTotalBytes equals memoryLimitBytes() and free stays within the limit less rss. test/system-crew.test.ts feeds an 80-core, 64 GiB host with a 2-core, 512 MiB limit and checks the pill and total follow the limit.
  • Not done: /system "used" is still the host's used memory capped at the limit, not the pod cgroup's own usage; reading memory.current would be a separate change.
  • Push hook: the push was refused until a commit carried a Try: line, so there is an empty commit for that.

Closes #12347

3 earlier comments
commented

/api/v1/health and /system now report the pod's memory and CPU limits instead of the host's. tsc and scripts/gate.ts are clean. design-lint printed "no colour, size or component added outside the system", which I took as a pass. The vitals, system-view and cgroup tests pass (49 pass, 3 skipped). The cgroup skips are in test/cgroup.test.ts, which can't kill cells in this sandbox. I did not boot the app or check the preview.

  • Health memory: vitals().memory now comes from a new memoryReading() in src/kernel/vitals.ts. hostTotalBytes is memoryLimitBytes(), so it is the cgroup memory.max where one is set. hostFreeBytes is the smaller of freemem() and the limit less this process's resident memory.
  • /system memory and cores: buildSystem in src/system/view.ts takes the pod's limits as an optional argument, and src/system/live.ts passes cpuLimit() (the cgroup cpu.max) and memoryLimitBytes(). The memory pill's total is held under the memory limit, and the cores pill, plus the matching TUI line, shows the CPU limit where one is set. The per-core meters still list every host core.
  • Tests: test/vitals.test.ts checks hostTotalBytes equals memoryLimitBytes() and free stays within the limit less rss. test/system-crew.test.ts feeds an 80-core, 64 GiB host with a 2-core, 512 MiB limit and checks the pill and total follow the limit.
  • Not done: /system "used" is still the host's used memory capped at the limit, not the pod cgroup's own usage; reading memory.current would be a separate change.
  • Push hook: the push was refused until a commit carried a Try: line, so there is an empty commit for that.
commented

Rewrapped the one over-long comment that failed the gate, and pushed the fix to the pull.

  • The fix: the limitCores doc comment in src/system/view.ts was 107 columns. It is now a three-line block comment, each line under 100.
  • Checks: bun scripts/gate.ts and bun x tsc --noEmit pass. test/vitals.test.ts and test/system-crew.test.ts pass, 19 tests.
  • Not run: scripts/fast.ts reported the diff is too broad to name test files, because src/kernel/vitals.ts changed. I ran the two test files covering the change instead of the full suite, which the forge's check runs on the push.
  • Gate behaviour: it only reads committed lines, so it kept flagging line 35 until I committed.

The pull changes /system and /api/v1/health to report the pod's own CPU and memory limits instead of the host's. limitCores is the new optional field on the CPU view. To try it, open /system on the preview and check that the cores and memory pills show the pod's limits.

commented

/system and /api/v1/health now read the pod's memory limit and the pod's own memory use, and the changes you asked for are in. tsc, the gate, the design lint and the five system and vitals test files pass. I did not run the full suite or open the preview, and /system there needs an admin.

  • Used memory: on a limited pod, "used" is now the cgroup's memory.current less inactive_file from memory.stat. A 512 MiB pod on a busy 64 GiB host no longer reads "512 MiB of 512 MiB". If the cgroup can't be read it shows 0, so the memory figure can be wrong in that case. On the health payload, free is the limit less pod use, or less this process's rss if the cgroup is unreadable. With no cgroup limit, both pages show the host figures as before.
  • Per-core rows: I kept the host's rows and the page now says so. When the limit is below the host's core count, a line reads "This pod may use N of the host's M cores; the rows below are the host's." I didn't trim the rows because a cgroup CPU quota doesn't say which host cores the pod runs on.
  • Health field names: hostFreeBytes and hostTotalBytes are now freeBytes and totalBytes, with a doc comment saying they are the pod's limit where one is set. Nothing else in the repo read the old names. This does change the payload's field names, so any outside reader of them would need updating.
  • Tests:
    • memoryReading and vitals() take an injected podMemory. The tests assert that total and free follow it, and that an unreadable cgroup falls back to rss.
    • createLive takes an injected limits. A test checks that the page pill and the TUI line say the limit, and that the cores note appears.
    • A test builds a fake cgroup directory to check podMemoryUsedBytes.
    • Under a limit, the view shows the injected pod use, not the host's 60 GiB.

I added no components or accents.

commented

I rewrapped the three comments the gate flagged and pushed. Locally the gate and tsc print nothing, and I did not re-run the tests, since the change only rewraps comments.

  • Comment wrapping: the long comment lines were in src/kernel/vitals.ts (the freeBytes doc and the memoryReading doc) and src/system/view.ts (the usedBytes doc). The line numbers in the check log differ from my tree because it checks the merge with main. I found the lines from my own diff, so I can't confirm they are the exact ones it named.
  • Looks rule: the gate also said src/web/pages/system.ts needs a Looks: line. The commit message now has Looks: /system, so the forge can take before/after pictures of that page.

The pull now covers the earlier changes:

  • Pod memory: /system and /api/v1/health read the pod's memory limit and the pod's own use from the cgroup, not the host's.
  • Core rows: the page keeps the host's per-core rows and says so when the pod's limit is lower.
  • Health fields: hostFreeBytes and hostTotalBytes in the health payload are now freeBytes and totalBytes.
  • Tests: they inject the limits and fail without the wiring.

To try it, open /system as an admin on the preview. On a limited pod the pills show the limit, memory reads the pod's own use, and the cores list opens with the host-rows note.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs