Skip to content

fix(bench): make bench:idle-cpu build, sample CPU and parse the process table on Windows - #27622

Merged
OrcaWin merged 6 commits into
mainfrom
OrcaWin/bench-idle-cpu-windows
Oct 12, 2026
Merged

OrcaWin merged 6 commits into
mainfrom
OrcaWin/bench-idle-cpu-windows

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​38
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25

ELI5

The idle-CPU benchmark couldn't build on Windows, reported 0% CPU for every process, and sometimes crashed reading the process list. It now runs end to end and reports real numbers.

What Changed

  • Build: the build step ran npx through execFileSync. On Windows that is npx.cmd, so it failed with ENOENT. It now runs config/scripts/run-electron-vite-build.mjs with the current Node, which also checks that the build's startup code loads cleanly.
  • CPU time: the Windows sampler set CPU time to null, so every process reported 0%. It now reads UserModeTime and KernelModeTime from Win32_Process. A missing value stays null instead of turning into a believable 0.
  • Parse failure ([Perf] bench:idle-cpu on Windows: intermittent JSON.parse failure while reading the process table #25236): PowerShell writes redirected output in the old console code page (437). A character like • or → in any running process's command line becomes a raw control byte, and JSON.parse rejects it. That's why it was intermittent: it only failed while such a process happened to be running. The script now sets [Console]::OutputEncoding to UTF-8, the same line Orca's own process scan uses.
  • Fixture (every platform): fetchRepos() now needs its runtime argument, so the fixture threw before sampling on any OS. It now passes { runtimeEnvironmentId: null }, as the end-to-end tests do.

Why

Windows performance fixes need a working idle-CPU baseline.

The benchmark keeps its own PowerShell read instead of using windows-process-table.ts. That module only runs inside Electron, and it deliberately exposes no CPU time or memory, which are the only things this benchmark measures.

The first three commits are @paoValle's #25238, cherry-picked with authorship kept. They closed it only to cut down their open PRs. The UTF-8 and fixture fixes are new.

Linked Issue

Fixes #25236
Refs #25235: this fixes the idle-CPU part. The import crash is fixed in the companion PR.

Visual Proof

N/A: this is a command-line benchmark with no UI.

Testing

On Windows 11:

  • Before (main): the build step fails with spawnSync npx ENOENT. With --skip-build, renderer, GPU and total CPU all show a mean of 0.

  • After: pnpm run bench:idle-cpu -- --warmup-ms 10000 --sample-ms 15000 exits 0 with total mean CPU 4.86% (p95 9.74%), renderer 1.83% and GPU 2.67%. No Electron processes are left running.

  • New Windows-only test: it starts a process whose command line contains • → ♪ and reads the process table. Without the UTF-8 fix it fails with the exact error from the issue ("Bad control character…"); with it, it passes. CIM time mapping is unit-tested.

  • vitest 5/5 passing; oxlint, oxfmt and check:code-quality:changed are clean.

  • I manually tested these changes locally

  • Automated tests added/updated

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered: the POSIX sampler is unchanged, and the build wrapper and fixture fix work on every platform

paoValle and others added 5 commits October 11, 2026 15:38
Three independent Windows defects in the idle-CPU benchmark (its report is
what Windows performance work would cite):

- `buildAppIfNeeded` spawned `npx`, which is `npx.cmd` on Windows, so
  execFileSync failed with ENOENT before any sampling. Build through
  `config/scripts/run-electron-vite-build.mjs` instead — the repo's own
  Windows-safe wrapper, which also runs the boot-graph verification.
- `readWindowsProcesses` returned `cpuTimeSeconds: null`, so the sampler's
  per-process CPU delta (idle-cpu-process-sampling.mjs:198) fell back to
  the hardcoded `percentCpu: 0` and every CPU KPI in the report was zero.
  Read `UserModeTime`/`KernelModeTime` from `Win32_Process` (100 ns units)
  and keep `null` when a host does not return them.

Measured on Windows, same options before and after the CPU fix:

| class | mean CPU before | mean CPU after |
| --- | ---: | ---: |
| renderer | 0 | 2.20 |
| gpu | 0 | 2.08 |
| utility | 0 | 0.11 |
| agent-or-node | 0 | 0.06 |
| total | 0 | 4.51 (p95 8.40) |

RSS is unchanged (934 MiB -> 937 MiB), so only the CPU reporting changed.

Refs #25235
… as zero

Review follow-up (CodeRabbit). `Number(null)` is `0`, which is also a real
counter value, so an absent `UserModeTime`/`KernelModeTime` passed the
finite check and the sampler would report a kernel-only delta instead of
taking the fallback. Require an actual number from the CIM payload.

Verified on Windows that the real payload still reports CPU once the check
is tight: total mean 4.40%, p95 14.48%, renderer 3.51%.
The mapping was only reachable through Get-CimInstance, so no test ran it.
Lift it into cimCpuSeconds and assert the 100ns-to-seconds sum plus the
missing / string / non-finite cases that must stay null.
…vives

PowerShell writes to a redirected stdout in the OEM code page (437 here),
which best-fits characters such as U+2022 and U+2192 in any running
process's command line to raw 0x07 / 0x1A bytes. ConvertTo-Json had left
them unescaped because they are not control characters in UTF-16, so the
sampler's JSON.parse failed with "Bad control character in string literal"
whenever such a process happened to be alive -- hence intermittent.

Set [Console]::OutputEncoding to UTF-8, as the app's own CIM scan does,
and cover it with a Windows-only test that fails without the fix.

Fixes #25236
fetchRepos now requires a runtimeEnvironmentId, so the fixture's bare call
threw "Cannot read properties of undefined (reading 'runtimeEnvironmentId')"
before sampling on every platform. null selects this app's own catalog, as
the e2e helpers already do.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 11a886da-36d5-4015-851b-f7ea70e4c20c

📥 Commits

Reviewing files that changed from the base of the PR and between 21d9762 and 84bf104.


📒 Files selected for processing (2)
  • .github/workflows/pr.yml
  • config/scripts/pr-code-change-scope.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

Windows process sampling now reads user and kernel CPU times, converts valid values to seconds, and uses UTF-8 PowerShell output. Tests cover time conversion and Windows process-table parsing. The Windows workflow and test-file detector include the test. The benchmark runs its build through the Node wrapper and passes an explicit runtime environment option to fetchRepos.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 84bf1

The Windows benchmark build and sampling changes preserve their intended behavior, and the fixture now explicitly selects local repositories. No actionable merge risk remains in the reviewed changes.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check Warning The PR includes changes beyond #25236. run-idle-cpu-benchmark.mjs replaces the Windows-incompatible npx build invocation, adds UserModeTime and KernelModeTime CPU mapping, and passes `{ runtim… Remove the build-wrapper, CIM CPU-time, and fixture argument changes from this PR, or link an active issue that requires them and separate that work from the #25236 parsing fix.
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main changes: Windows benchmark build, CPU sampling, and process-table parsing fixes.
Description check Passed The description is mostly complete. It includes the user impact, detailed changes, rationale, linked issues, visual-proof rationale, testing results, and checklist confirmations. Some template section…
Linked Issues check Passed The direct coding requirement in #25236 is to prevent intermittent JSON.parse failures during Windows process-table sampling. readWindowsProcesses() sets [Console]::OutputEncoding to UTF-8 befor…

Full details: Out of Scope Changes check

Explanation

The PR includes changes beyond #25236. run-idle-cpu-benchmark.mjs replaces the Windows-incompatible npx build invocation, adds UserModeTime and KernelModeTime CPU mapping, and passes { runtimeEnvironmentId: null } to fetchRepos(). The linked issue identifies the build and CPU fixes as separate work from its JSON parsing failure. The fixture argument change is a separate cross-platform failure. The test-runner registration supports the added Windows regression test and is in scope.


Full details: Docstring Coverage

Explanation

Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
config/scripts/idle-cpu-process-sampling.mjs (1)

73-77: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Force the JSON output to be an array and set an explicit depth.

The script pipes the process list directly to ConvertTo-Json -Compress. The script runs under Windows PowerShell 5.1. With default settings, a single-item pipeline serializes as an object, not an array. The calling code handles this with Array.isArray(parsed) ? parsed : [parsed], so it works today.

The change is optional. The same pattern was already present before this PR, and the learning concerns hardening only. To remove the dependence on the JS-side fallback, wrap the pipeline in @(...) and pass -InputObject with -Depth.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00ba13d1-da04-460c-ae02-402f36b86a77
📥 Commits

Reviewing files that changed from the base of the PR and between b022406 and 21d9762.

📒 Files selected for processing (3)
  • config/scripts/idle-cpu-process-sampling.mjs
  • config/scripts/idle-cpu-process-sampling.test.mjs
  • config/scripts/run-idle-cpu-benchmark.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

The UTF-8 regression test self-skips off win32, so it must be registered in
both Windows lists or it runs on no machine.
@OrcaWin
OrcaWin merged commit 983532a into main Oct 12, 2026
40 checks passed
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.

[Perf] bench:idle-cpu on Windows: intermittent JSON.parse failure while reading the process table

2 participants