Files
Rosea/.agents/reviews/fix-cpu-guard.md

2.6 KiB
Raw Permalink Blame History

Review — fix/cpu-guard

Adversarial self-review (CLAUDE.md §5.3). Reviewed 2026-11-02 on Node 22.11.0, Windows 10. There is no PR: the only remote is Gitea.

Why and what

CLAUDE.md §5.7: do not start a full run above ~80 % CPU. On 2026-11-02 that was broken three times (lessons/process.md), twice right after reading the number. Now pnpm test, test:e2e and test:offline first run pnpm guard:cpu (tools/cpu-guard):

flowchart LR
  run["pnpm test / test:e2e / test:offline"] --> guard["guard:cpu<br/>sample 2 s with os.cpus()"]
  guard -->|"≤ 80 %"| go["the run starts"]
  guard -->|"> 80 %"| wait["wait 10 s, sample again"] --> guard
  wait -->|"after 180 s"| stop["exit 1: not starting"]

Node's os.cpus(), not a shell command, so it works the same on Windows, Linux and macOS. A dedicated machine sets ROSEA_CPU_MAX (100 never refuses) and ROSEA_CPU_WAIT_SECONDS; a value that is not a whole number in range is refused, never quietly the default.

Checks

Check Result
Unit tests, tools/cpu-guard 13 passed: the busy share between two readings (not since boot), system time as busy, no NaN on equal readings, defaults, overrides, five bad settings, start / wait / refuse
On this machine, busy with another project's tests waited 51 s at 93–100 %, then started at 61 %
Forced refusal (ROSEA_CPU_MAX=1, no wait) exit 1 with the reason
pnpm test behind a refusal stopped before Turbo ran a single test
The guard's reading beside Windows' own counter, sampled together 64 / 75, 93 / 96, 96 / 98 %

Findings

# Finding Resolution
1 The guard measures before the run, not during it: a machine that becomes busy mid-run is not seen. Accepted: §5.7 is about starting. Stopping a run halfway would leave browsers and servers half-closed, the very mess §5.7 exists to avoid.
2 ROSEA_CPU_MAX=100 is a way round the rule. Documented as for dedicated machines only, in CLAUDE.md §5.7 and the lesson. An override nobody can use would push people to edit the script instead.
3 The guard adds 2 s to every full run on a quiet machine. Accepted.
4 Filtered runs (pnpm --filter X test) and drills are not guarded. By design: they are not full runs.
5 Its own 2 s sample could read its own start-up as load. It samples after Node has started. Later, on a quiet machine, it read 2.4–4.1 % beside Windows' 1.5–3.3 %; busy, 2–11 points lower. Close enough for an 80 % line.

Not verified

  • macOS and Linux (only Windows 10 here).
  • A CI runner: there is none yet (G0.22).