Skip to content

fix(server): stop Windows terminal polling from spiking CPU - #9476

Open
UtkarshUsername wants to merge 11 commits into
pingdotgg:mainfrom
UtkarshUsername:fix/windows-native-process-snapshot
Open

fix(server): stop Windows terminal polling from spiking CPU#9476
UtkarshUsername wants to merge 11 commits into
pingdotgg:mainfrom
UtkarshUsername:fix/windows-native-process-snapshot

Conversation

@UtkarshUsername

@UtkarshUsername UtkarshUsername commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What Changed

Terminal subprocess polling no longer spawns a PowerShell CIM query every second while terminals are active. It now reads one shared process snapshot per polling tick from the existing resource-monitor sidecar (new processTable command, protocol v3), on both Windows and POSIX.

  • One snapshot per tick shared across every terminal, instead of per-terminal process probes.
  • Failed snapshots back off exponentially up to 60 seconds and reset on success or when no sessions are running. The backoff also applies when the sidecar is down and the ps/PowerShell fallback serves instead, so a stalled sidecar can't hot-loop the expensive fallback.
  • No process-count cap on snapshots, and terminal activity labels plus process registration keep working as before.
  • As a side effect of reusing the sidecar, no new native dependency was needed: the windows-process-tree packaging added earlier in this branch is reverted.

Verification:

  • vp test run apps/server/src/terminal/Manager.test.ts apps/server/src/resourceTelemetry/NativeTelemetryClient.test.ts scripts/lib/cli-external-packages.test.ts (82 passed, incl. a new test that fails the sidecar table and asserts fallback data is applied while fallback spawns back off)
  • vp test run apps/server/src/resourceTelemetry/ResourceTelemetry.test.ts apps/server/src/resourceTelemetry/ResourceTelemetryHistory.test.ts apps/server/src/resourceTelemetry/Model.test.ts apps/server/src/diagnostics/ProcessDiagnostics.test.ts (31 passed)
  • vp run --filter t3 typecheck and vp run --filter @t3tools/scripts typecheck (clean)
  • cargo fmt --check for native/resource-monitor (Rust binary tests need a native linker; CI covers that build)

Why

T3 Code queried Win32_Process through a fresh PowerShell process every second while terminals were active. On affected Windows machines those calls averaged roughly one second, repeatedly timed out, and kept CPUs and fans busy. The sidecar already enumerates the full process table with sysinfo and ships in desktop and CLI builds, so reusing it removes PowerShell/WMI from the polling loop without loading native code into the server process. This matches docs/internals/resource-telemetry.md, which exists to replace recurring ps/PowerShell subprocess probes.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (not applicable: no UI changes)
  • I included a video for animation/interaction changes (not applicable: no UI changes)

Implemented with GPT-5.6 using the Codex harness.


Note

Medium Risk
Bumps RESOURCE_MONITOR_PROTOCOL_VERSION to 3 and changes terminal activity detection on all platforms; mismatched or missing sidecar binaries fall back to spawned probes with backoff rather than failing silently.

Overview
Reduces Windows terminal subprocess polling CPU by sourcing one shared process table per tick from the existing resource-monitor sidecar instead of spawning PowerShell/ps on every interval.

The resource-monitor protocol moves to v3 with a new processTable command and {pid, ppid, name} response, implemented in the Rust sidecar, contracts, and NativeTelemetryClient (5s timeout, same request/deferred pattern as sampleNow).

TerminalManager calls NativeTelemetryClient.processTable by default (wired via NativeTelemetryLayerLive on the terminal layer). PowerShell CIM and POSIX ps remain fallbacks when the sidecar fails; fallback data still updates activity, but ticks count as failures. subprocessSnapshotPollDelayMs doubles the poll delay per failure (max 60s) and resets after a successful snapshot or when no sessions are running.

Tests and fixtures use protocol v3; docs list the new command/event.

Reviewed by Cursor Bugbot for commit 3bb2be6. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add native processTable command and exponential backoff to terminal polling

  • Adds a processTable command and response event to the resource-monitor protocol (bumped from v2 to v3) across main.rs, resourceTelemetry.ts, and NativeTelemetryClient
  • TerminalManager.make now uses NativeTelemetryClient.processTable as the primary subprocess snapshot source on Windows, falling back to the PowerShell-based windowsProcessTableSnapshot and spawned fallback data when it fails
  • Introduces subprocessSnapshotPollDelayMs in Manager.ts: doubles the configured interval per failure (cap 60s), resets after success or when no sessions are active — this replaces the fixed-interval loop that caused CPU spikes on repeated failures
  • pollSubprocessActivity now returns a success flag so failed snapshots are no longer treated as successful ticks
  • Risk: protocol version constant RESOURCE_MONITOR_PROTOCOL_VERSION changed from 2 to 3; any client or fixture still emitting v2 hello/events will be rejected by contract validation. All in-tree callers and test fixtures are updated.

Macroscope summarized 3bb2be6.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Sep 3, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes production terminal polling across platforms and adds a new native sidecar protocol command with fallback and backoff behavior. Its cross-component runtime and compatibility impact is broader than a self-contained fix, warranting human review.

You can add or adjust custom eligibility rules. Learn more.

Comment thread apps/server/src/terminal/Manager.ts Outdated
Comment thread apps/server/src/terminal/Manager.ts
@UtkarshUsername UtkarshUsername changed the title [WIP] fix(server): use native Windows process snapshots fix(server): stop Windows terminal polling from spiking CPU Sep 3, 2026
Comment thread apps/server/src/terminal/Manager.ts Outdated
Comment thread apps/server/src/terminal/Manager.ts Outdated
@UtkarshUsername
UtkarshUsername marked this pull request as draft September 3, 2026 21:45
@UtkarshUsername
UtkarshUsername marked this pull request as ready for review September 3, 2026 21:45
@UtkarshUsername UtkarshUsername changed the title fix(server): stop Windows terminal polling from spiking CPU [WIP] fix(server): stop Windows terminal polling from spiking CPU Sep 3, 2026
Comment thread apps/server/src/terminal/Manager.ts Outdated

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a0bc756. Configure here.

Comment thread native/resource-monitor/src/main.rs
Comment thread apps/server/src/terminal/Manager.ts
UtkarshUsername and others added 2 commits September 4, 2026 03:57
Apply exponential backoff when the sidecar fails and the spawned fallback serves instead, so a stalled sidecar no longer hot-loops PowerShell. Skip pid 0 in the Rust process table so one kernel entry cannot fail the whole event decode. Revert the Windows sidecar packaging added for the removed native dependency.
@UtkarshUsername UtkarshUsername changed the title [WIP] fix(server): stop Windows terminal polling from spiking CPU fix(server): stop Windows terminal polling from spiking CPU Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant