fix(server): discover Windows ports without PowerShell - #9520
fix(server): discover Windows ports without PowerShell#9520UtkarshUsername wants to merge 12 commits into
Conversation
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.
| const nowMillis = yield* Clock.currentTimeMillis; | ||
| const fallback = yield* Ref.get(windowsFallbackRef); | ||
| if (nowMillis < fallback.nextAttemptAtMillis) { | ||
| return fallback.lastSnapshot ?? (yield* probeCommonPorts()); |
There was a problem hiding this comment.
🟡 Medium preview/PortScanner.ts:523
During the Windows fallback cooldown, scans return fallback.lastSnapshot with stale terminal ownership, so registering or unregistering a terminal leaves old associations (including closed terminals) visible for up to 60 seconds. Re-resolve each cached server's terminal from the current terminalByProcessId map before returning the snapshot.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/preview/PortScanner.ts around line 523:
During the Windows fallback cooldown, scans return `fallback.lastSnapshot` with stale `terminal` ownership, so registering or unregistering a terminal leaves old associations (including closed terminals) visible for up to 60 seconds. Re-resolve each cached server's `terminal` from the current `terminalByProcessId` map before returning the snapshot.
|
Note 🤖 GPT-6 Astra (preview) responding on behalf of Theo This note is part of an automated cleanup pass. Carryover from #6254 at 920f8251d9: retain listener-to-PID/process-name mapping and the interrupted-scan case, where a later scan must run normally. Check degraded discovery with a previously found non-common port so it does not disappear only because fallback probes common ports. Its old single-flight test does not start the first fork before awaiting the second scan, so do not copy that test unchanged. Keep terminal ownership fresh when reusing listener data. |
What Changed
windowsListenerscommand to the existing native resource-monitor sidecarGetExtendedTcpTableDepends on #9476. The local branches are managed as a
gh-stackchain. GitHub cannot base this upstream PR directly on the parent branch because both contribution branches live in a fork.Why
Windows preview discovery currently launches
Get-NetTCPConnectionevery three seconds and performs oneGet-Processcall per listener. On affected systems, those WMI-backed commands overlap, consume sustained CPU, and spin the fans.The resource-monitor sidecar already ships with the server and owns native process telemetry. Reading the Windows TCP table there removes PowerShell from the normal path without adding another native dependency. The fallback remains available for environments without a compatible sidecar, but failures no longer create an unbounded retry loop.
Closes #5900.
Checklist
Verification:
vp test run apps/server/src/preview/PortScanner.test.ts apps/server/src/resourceTelemetry/NativeTelemetryClient.test.ts apps/server/src/diagnostics/ProcessDiagnostics.test.ts apps/server/src/resourceTelemetry/Model.test.ts apps/server/src/resourceTelemetry/ResourceTelemetry.test.ts apps/server/src/resourceTelemetry/ResourceTelemetryHistory.test.ts(63 passed)vp run --filter t3 typecheckgit diff --checkNative Rust compilation was not available in this Windows shell because
cargoandrustfmtare not installed. The PR remains a draft until CI verifies that target.Model: GPT-5 | Harness: Codex / T3 Code
Note
Discover Windows ports via native telemetry instead of
PowerShellprocessTableandwindowsListenerscommands in native/resource-monitor/src/main.rs using Windows FFIprocessTableandwindowsListenersrequests with 5-second timeoutswindowsListenersreturns an explicit unavailable error on non-Windows platforms.📊 Macroscope summarized c9abc35. 7 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues