Skip to content

Fix Windows Resource Manager memory and CPU attribution - #8845

Merged
OrcaWin merged 3 commits into
stablyai:mainfrom
adityachaudhary99:fix/windows-resource-manager-memory
Jul 21, 2026
Merged

OrcaWin merged 3 commits into
stablyai:mainfrom
adityachaudhary99:fix/windows-resource-manager-memory

Conversation

@adityachaudhary99

@adityachaudhary99 adityachaudhary99 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • restore Windows Resource Manager memory and CPU attribution on systems where wmic.exe is unavailable
  • collect PID, parent PID, working set, cumulative kernel/user CPU ticks, and process creation identity with one PowerShell CIM process per healthy Resource Manager poll
  • fall back to typeperf.exe for memory only after a failed CIM sample, retry CIM after a bounded 30-second cooldown, and warm a fresh CPU baseline on recovery
  • protect CPU deltas against PID reuse, unsafe integer conversion, too-short sample intervals, stale samples, and values above the host-core capacity
  • keep the existing macOS/Linux, SSH/runtime-host, history, and process-subtree behavior unchanged

Windows 11 25H2 removes WMIC, so the previous collector could return an empty process index and local PTY subtrees would resolve to 0 KB. The Windows collector also hardcoded process CPU to zero, leaving every terminal at 0.0% even while busy.

Microsoft reference: WMIC removal in Windows 11 25H2.

Performance and resilience

  • healthy sampling launches exactly one Resource Manager PowerShell child per poll
  • aggregate child CPU per poll measured at approximately 191 ms, down from approximately 391 ms for the earlier two-process implementation
  • CIM output parsing preserves empty tab-separated fields and bounds input size
  • a CIM timeout may delay one recovery poll by the existing five-second timeout, at most once per 30-second cooldown
  • the separate foreground-process scanner remains independent because it has a different payload and freshness requirement

Screenshots / live verification

No UI code or layout changed. Live Electron validation on Windows showed:

  • a busy terminal at approximately 99.7-100% CPU and 152 MB memory
  • backing-store attribution of 100.305% CPU and 161,075,200 bytes for the busy session
  • CPU returning to 0 after the workload completed while memory remained populated
  • at most one concurrent Resource Manager OS sample
  • no renderer console errors, clipping, overlap, or layout regressions

Testing

  • 31/31 Windows collector tests
  • 59/59 affected tests across collector and Resource Manager consumers
  • TypeScript typecheck
  • touched-file Oxlint, maximum-lines ratchet, reliability gates, and staged-diff checks
  • live Electron golden-path validation on Windows

The full pnpm lint command remains blocked by an unrelated pre-existing non-exhaustive switch in src/renderer/src/components/skills/skill-freshness-group.tsx:101; touched files pass lint.

Implementation notes

  • execFile launches only constant in-box executable names and arguments; no user-controlled shell command is constructed.
  • child windows are hidden and retain bounded timeouts and output caps
  • CPU counters and creation identities remain bigint/strings because Windows tick values can exceed JavaScript's safe integer range
  • the first CPU observation, and the first observation after CIM recovery, intentionally reports zero because no comparable prior cumulative sample exists
  • malformed, aggregate, negative, and incomplete rows are dropped or clamped without shifting later fields

PR #9048 independently implements overlapping Windows resource sampling inside a broader lifecycle/status refactor. This PR remains the focused collector fix with targeted tests and live Windows verification.

AI review / security

Three review rounds and two fix rounds covered platform isolation, local versus remote behavior, process invocation, PID reuse, parser bounds, failure recovery, polling cost, and test portability. No auth, secrets, IPC contracts, dependencies, filesystem writes, or network access were added.

X: @thecalendre

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Windows process enumeration now uses PowerShell CIM as the primary backend and Typeperf during CIM failure or cooldown periods. New parsers handle tab-delimited CIM output and Typeperf CSV counters, replacing WMIC parsing. The collector now attributes CPU from cumulative CIM samples and delegates Windows sweeps to the new module. Tests add separate process-execution mocks, backend fixtures, parser coverage, sweep-count assertions, fallback behavior, CPU and memory handling, concurrency, and enumeration failures.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main Windows memory/CPU attribution fix.
Description check ✅ Passed The description covers the required Summary, Screenshots, Testing, AI Review, Security Audit, and Notes content with only minor formatting differences.

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/memory/collector.test.ts (1)

517-529: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise both platform failure paths explicitly.

This test never stubs os.platform(): Unix runs never invoke execFileMock, while Windows runs never invoke execMock. Split it into Unix and win32 cases so the Typeperf-then-CIM double failure is covered deterministically.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 670e33ec-f709-4eea-9d43-97e29d22f282

📥 Commits

Reviewing files that changed from the base of the PR and between e74a8e0 and f8070ab.

📒 Files selected for processing (2)
  • src/main/memory/collector.test.ts
  • src/main/memory/collector.ts

Comment thread src/main/memory/collector.ts Resolved
@adityachaudhary99 adityachaudhary99 changed the title Fix Windows Resource Manager memory attribution without WMIC Fix Windows Resource Manager memory and CPU attribution Jul 17, 2026
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:38

@OrcaWin OrcaWin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the final Windows sampling implementation through three review rounds and two fix rounds. The healthy path uses one bounded CIM process per poll, Typeperf is memory-only fallback with recovery, CPU deltas handle PID reuse and counter precision, and Unix/SSH behavior remains isolated. Verified 31 collector tests, 59 affected tests, typecheck, touched-file lint/reliability gates, staged diff checks, and the live Windows Electron golden path. The only full-lint failure is the documented unrelated pre-existing exhaustive-switch error. Approving b3729e3.

@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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 52056db3-2fe5-4a5a-9015-51af8a99f518

📥 Commits

Reviewing files that changed from the base of the PR and between d5b2da5 and b3729e3.

📒 Files selected for processing (3)
  • src/main/memory/collector.test.ts
  • src/main/memory/collector.ts
  • src/main/memory/windows-process-resource-collector.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/memory/collector.test.ts

Comment on lines +1 to +3
/* eslint-disable max-lines -- Why: the collector's host-process index,
history ring buffer, Electron bucketing, and worktree attribution live
together to keep one snapshot's orchestration in one place. */

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Remove the max-lines suppression now that Windows enumeration is extracted.

This PR extracts the ~200-line Windows CIM/Typeperf backend into windows-process-resource-collector.ts — exactly the fix previously requested to shrink this file — but the eslint-disable max-lines directive at the top of the file is still present. The coding guideline prohibits disabling max-lines unconditionally, with no carve-out for documented/justified suppressions.

Please recheck whether the file is now under the line limit and remove the disable; if it's still over, further splitting (e.g., history ring buffer, Electron bucketing) is needed instead of retaining the suppression.

As per coding guidelines, "Never disable ESLint or Oxlint max-lines, including line-specific disables; never add a per-file max-lines bump in mobile/.oxlintrc.json."

Source: Coding guidelines

@OrcaWin
OrcaWin merged commit 4877d0b into stablyai:main Jul 21, 2026
1 check passed
@adityachaudhary99
adityachaudhary99 deleted the fix/windows-resource-manager-memory branch August 21, 2026 16:57
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Use a single CIM sample for Windows process memory and CPU attribution, with bounded Typeperf memory fallback and safe CPU delta recovery.
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.

3 participants