fix(cli): compute macOS machine-health memory from vm_stat#990
Open
junmo-kim wants to merge 2 commits into
Open
fix(cli): compute macOS machine-health memory from vm_stat#990junmo-kim wants to merge 2 commits into
junmo-kim wants to merge 2 commits into
Conversation
Add readDarwinMemoryUsedPercent, a pure parser that computes macOS used memory as App Memory + Wired + Compressed (anonymous + wired-down + occupied-by-compressor pages), matching Activity Monitor's "Memory Used" figure. Page size is parsed from the vm_stat header rather than hardcoded, since it differs between Apple Silicon (16KB) and Intel (4KB) Macs. Not wired up yet; covered by unit tests, including a verbatim vm_stat capture from a 16GB Mac mini where the pre-fix total - freemem() path reported 99% (counting reclaimable cache as used) while App+Wired+ Compressed is 79% — the number a user sees in Activity Monitor.
Add a platform() === 'darwin' branch that shells out to vm_stat (1s timeout, guarded by try/catch) and feeds its output to readDarwinMemoryUsedPercent. On any failure or undefined result it falls through to the existing total - freemem() fallback, matching the Linux branch's structure. This fixes the Machine capacity tooltip showing a stuck ~99% "High pressure" warning on macOS runners: os.freemem() there counts reclaimable file cache as used, so it reports near-total usage. Summing only App Memory + Wired + Compressed reports the same figure Activity Monitor shows.
There was a problem hiding this comment.
Findings
- No issues found.
Summary
- Review mode: initial
- Reviewed the full diff for the macOS
vm_statmemory calculation and parser tests. Residual risk: I could not execute the test suite in this environment becausebunis unavailable.
Testing
- Not run (automation;
bunnot installed in this container)
HAPI Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS runners, the Machine capacity tooltip in the session sidebar shows "RAM in use" pinned near 99% and displays "High pressure — avoid spawning more here", even when the machine has plenty of headroom and macOS itself reports normal memory pressure.
The runner's
computeMemoryPercent()(cli/src/utils/machineHealth.ts) has a dedicated/proc/meminfobranch for Linux but currently falls through tototal - os.freemem()on every other platform. On macOS,os.freemem()counts only truly-free pages, and macOS keeps almost all physical memory populated with reclaimable file cache, soused / totalsits at ~99% permanently regardless of real usage.Solution
Add a
platform() === 'darwin'branch that readsvm_statand computes used memory the same way Activity Monitor's "Memory Used" does: App Memory + Wired + Compressed, i.e. the sum of anonymous, wired-down, and compressor-occupied pages. Reclaimable file cache stays out of the sum, so the figure tracks what a user sees in Activity Monitor.This mirrors the intent of the existing Linux branch, whose
total - MemAvailableis byte-identical to whatfreereports as "used" — reclaimable cache is not treated as pressure on either platform. The Linux branch is unchanged.Details:
vm_statheader (16 KB on Apple Silicon, 4 KB on Intel) rather than hardcoded.execSync('vm_stat')runs with a 1 s timeout inside a try/catch; any failure or unparseable required field returnsundefinedand falls through to the existingos.freemem()path, so behavior is unchanged wherevm_statis unavailable.Tests
readDarwinMemoryUsedPercent(vmStat, totalBytes)parser: a verbatimvm_statcapture from a 16 GB Mac mini (the pre-changetotal - freemem()path reports 99% for that same snapshot, while the new formula reports 79%, matchingtop's wired and compressor figures), an Intel 4 KB page-size fixture, and fail-safe cases (missing page-size header, missing page count, non-positive total).