Skip to content

fix(metrics): use vm_stat for accurate macOS memory reporting#45

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/investigate-memory-issue
Draft

fix(metrics): use vm_stat for accurate macOS memory reporting#45
Copilot wants to merge 4 commits intomainfrom
copilot/investigate-memory-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 28, 2026

macOS memory appeared halved (~7GB on 14GB runners) because systeminformation calculates available = total - Pages_active, misclassifying wired and compressed memory as available.

macOS memory parser (src/lib.ts)

  • Added parseMacOsVmStat() — parses vm_stat output directly, computing available as (free + inactive + purgeable + speculative) × pageSize, matching Activity Monitor's definition
  • Handles both 4KB (Intel) and 16KB (Apple Silicon) page sizes dynamically from the vm_stat header
  • getMacOsMemory() wrapper with execSync fallback

Metrics collection (src/main/metrics.ts)

  • On darwin, calls getMacOsMemory() instead of systeminformation.mem(). Other platforms unchanged.

Test fix (src/main/metrics.test.ts)

  • Mocks node:child_process (execSync → controlled vm_stat output) and node:os (totalmem → fixed value) so getMacOsMemory() returns deterministic values on macOS CI runners
  • Spreads real node:os exports to preserve EOL etc. for @actions/core
// systeminformation (wrong on macOS):
result.active = Pages_active * pageSize;          // misses wired, compressed
result.available = result.free + result.buffcache; // includes wired as "available"

// New (correct):
const available = (pagesFree + pagesInactive + pagesPurgeable + pagesSpeculative) * pageSize;
return { active: totalMemory - available, available };

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 28, 2026 12:49
On macOS, systeminformation calculates available = total - Pages_active,
which incorrectly includes wired/compressed memory as available. Parse
vm_stat directly to properly calculate available memory as
(free + inactive + purgeable + speculative) * pageSize.

Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
- Fix misleading JSDoc comment on getMacOsMemory fallback
- Add maxBuffer option to execSync to prevent memory exhaustion
- Add comment explaining default 16KB page size choice

Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate reduced memory availability on macOS fix(metrics): use vm_stat for accurate macOS memory reporting Feb 28, 2026
Add mocks for node:child_process and node:os in metrics.test.ts so
getMacOsMemory() returns controlled values on macOS instead of calling
real vm_stat. The mock vm_stat output produces exactly 4096 MB active
and 8192 MB available, matching the existing test expectations.

Co-authored-by: Garbee <868301+Garbee@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants