Skip to content

fix(server): discover Windows ports without PowerShell - #9520

Draft
UtkarshUsername wants to merge 12 commits into
pingdotgg:mainfrom
UtkarshUsername:fix/windows-native-port-discovery
Draft

fix(server): discover Windows ports without PowerShell#9520
UtkarshUsername wants to merge 12 commits into
pingdotgg:mainfrom
UtkarshUsername:fix/windows-native-port-discovery

Conversation

@UtkarshUsername

@UtkarshUsername UtkarshUsername commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • add a windowsListeners command to the existing native resource-monitor sidecar
  • read IPv4 and IPv6 TCP listeners with Windows GetExtendedTcpTable
  • use the native listener snapshot for preview port discovery
  • retain a map-once PowerShell fallback with exponential backoff when the sidecar is unavailable
  • cover native discovery, fallback failures, cooldown behavior, and protocol handling with focused tests

Depends on #9476. The local branches are managed as a gh-stack chain. 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-NetTCPConnection every three seconds and performs one Get-Process call 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

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

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 typecheck
  • git diff --check

Native Rust compilation was not available in this Windows shell because cargo and rustfmt are 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 PowerShell

📊 Macroscope summarized c9abc35. 7 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted

🗂️ Filtered Issues

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Sep 4, 2026
const nowMillis = yield* Clock.currentTimeMillis;
const fallback = yield* Ref.get(windowsFallbackRef);
if (nowMillis < fallback.nextAttemptAtMillis) {
return fallback.lastSnapshot ?? (yield* probeCommonPorts());

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.

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

@t3dotgg

t3dotgg commented Sep 4, 2026

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 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.

[Bug]: Windows port discovery re-spawns a doomed PowerShell/WMI probe every 3 s (the port-scanner half of #4182, not fixed by #2679)

2 participants