Skip to content

fix(windows): stop a wedged process-table reader retaining a callback per cooldown - #16696

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/5499-wedged-reader
Aug 27, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/5499-wedged-reader

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​56
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

What's wrong

src/main/windows/windows-process-table.ts guards the vendored Toolhelp32 reader with a 3 s deadline plus a 30 s cooldown. The cooldown let exactly one probe through per window — deliberately, to avoid retrying at the caller's poll rate.

That bounds the rate of new callbacks, not the total. The vendored wrapper pushes every callback onto a module-global queue and drains it only when the request holding its requestInProgress latch completes:

// @vscode/windows-process-tree lib/index.js
const globalRequestQueue = []
function getRawProcessList(callback, flags) {
  globalRequestQueue.push(callback)
  if (!requestInProgress) { requestInProgress = true; native.getProcessList(...) }
}

If a snapshot never comes back — EDR hook, restricted token, a worker that dies — that latch is stuck for the life of the process. So each cooldown window parked one more closure in globalRequestQueue, forever, and blocked whichever caller drew the probe for the full 3 s deadline first.

The fix

Gate on the outstanding read rather than a wall clock. Once a read misses its deadline and has not called back, every further read is refused until that read's callback fires.

  • Retention is bounded at exactly one callback, instead of one more every 30 s for the life of the app.
  • Nothing is given up on recovery. A probe enqueued behind the latch could never have observed the drain anyway; the stuck callback firing is the drain. The reader now resumes the instant it recovers instead of up to 30 s later.
  • Wedged reads reject immediately rather than blocking a caller 3 s per window.

A Set of read ids rather than a counter, so a test reset — or a callback arriving after one — can never drive the tally negative and re-open the gate.

Why it matters more on a relay

A relay binds the bare addon, which has no JS queue to absorb the retries. Each read there is a Napi::AsyncWorker (worker->Queue() in addon.cc), so a wedged one holds a libuv threadpool slot permanently. One probe per window would have pinned all four default threads inside ~2 minutes, hanging every async fs and DNS call in the relay process — not just the process table.

Deliberate trade-off

A permanently wedged native reader is now permanently refused on that host, where before it retried every 30 s. That is the intended shape: the wedge conditions are host-wide, so a retry hangs too, and on the addon path each retry is a lost threadpool slot. Callers already treat a rejection as unverifiable rather than as evidence a process died.

What is unchanged

  • A wedge still does not engage the PowerShell/CIM fallback — only module absence does (docs/reference/windows-process-enumeration.md). A present-but-failing reader must never start forking shells at the caller's poll rate.
  • A wedged read still rejects rather than resolving empty, so "unavailable" stays distinguishable from "nothing is running" per docs/reference/ssh-execution-boundary.md.
  • No wire, IPC, or cross-host contract touched. macOS/Linux/folder-workspace paths are byte-identical (the module resolves null off Windows and returns before the new gate).

Tests

src/main/windows/windows-process-table.test.ts — the wedge cooldown block becomes sticky wedge:

test proves
never re-enters the reader while the timed-out read is still out the regression. Four cooldown windows, three concurrent callers each. Asserts call count only, not messages.
resumes as soon as the timed-out read finally calls back recovery is driven by the drain, with no wall-clock wait
stops calling the reader after a timeout… first read after a wedge is refused
clears the deadline when the reader throws synchronously unchanged — a sync throw must not wedge a recovered reader

Non-vacuous — reverting only windows-process-table.ts and re-running:

× never re-enters the reader while the timed-out read is still out
  AssertionError: expected "vi.fn()" to be called 1 times, but got 5 times
      Tests  3 failed | 20 passed (23)

5 = 1 + one per cooldown window — the leak itself, measured.

Checks

  • pnpm test src/main/windows src/main/providers src/main/ports src/shared/process-table-snapshot.test.ts → 950 passed, 12 skipped
  • pnpm tc → clean
  • oxlint + oxfmt → clean (pre-commit hook)

Not validated here

Windows-only runtime path; no Electron UI surface is involved, so there is nothing for CDP to observe. The wedge itself is not reproducible on macOS — it needs a real Toolhelp32 snapshot that never returns.

Fixes STA-5499.

Reliability contract

  • Invariant (terminal-session.windows-process-table-bounded-liveness): one timed-out native read may remain outstanding; later reads cannot add callbacks or relay workers until it returns, and a test reset cannot let an earlier deadline wedge the new reader generation. Process-table failure remains unavailable/unverifiable, never evidence that a process exited.
  • Failure source: STA-5499 plus the reset-before-timeout review finding on PR fix(windows): stop a wedged process-table reader retaining a callback per cooldown #16696.
  • Oracle and gate: src/main/windows/windows-process-table.test.ts uses fake time to prove four former cooldown windows retain one native call, recovery follows the original callback, and a pre-reset deadline cannot block a healthy post-reset read. This is focused evidence under the existing experimental terminal-session.explicit-close-retirement process-table gate.
  • Provider/platform coverage: the npm wrapper and relay bare-addon paths share the same gate; CIM fallback remains absence-only. macOS/Linux still return before the Windows native path, and no IPC, wire, persistence, folder-workspace, WSL, SSH, remote-runtime, or mobile contract changes. Real Windows packaging is covered by PR CI; a genuinely wedged Toolhelp32 snapshot remains an accepted live-runtime gap.
  • Performance budget and diagnostics: the permanent-wedge oracle bounds native calls and retained callbacks/workers at one, with no polling, retries, scans, subprocesses, listeners, or new timers. Existing timed out and wedged errors plus deterministic native-call counts identify the failure mode.

… per cooldown

The vendored reader pushes every callback onto a module-global queue and drains
it only when the request holding its `requestInProgress` latch completes. When a
Toolhelp32 snapshot never comes back, that latch is stuck for the life of the
process, so the 30 s cooldown -- which let one probe through per window --
bounded the rate of new callbacks but not the total: one more closure retained
every 30 s, forever, plus a full 3 s deadline block on whichever caller drew the
probe.

Gate on the outstanding read instead. Once a read misses its deadline and has
not called back, every further read is refused until that read's callback fires,
which bounds retention at exactly one callback. Nothing is given up on recovery:
a probe queued behind the latch could never have observed the drain anyway,
whereas the stuck callback firing IS the drain, so the reader now resumes the
instant it recovers rather than up to 30 s later.

It matters more on a relay, which binds the bare addon with no JS queue to
absorb the retries. Each read there is a `Napi::AsyncWorker`, so a wedged one
holds a libuv threadpool slot for good and one probe per window would have
pinned all four default threads inside ~2 minutes -- hanging every async `fs`
and DNS call in that process, not just the process table.

A wedge still does not engage the PowerShell fallback, and a wedged read still
rejects rather than resolving empty, so "unavailable" stays distinguishable from
"nothing is running" on every host.

Fixes STA-5499.
@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3737f4fc-ffda-4f18-9915-4ca067aca542

📥 Commits

Reviewing files that changed from the base of the PR and between 149c106 and 4be4a6a.

📒 Files selected for processing (2)
  • src/main/windows/windows-process-table.test.ts
  • src/main/windows/windows-process-table.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The Windows process-table reader now records timed-out reads as outstanding and rejects later reads with a “wedged” error until the original callback fires. Tests cover repeated concurrent attempts, prevention of reader re-entry, reset handling, and resumption after callback delivery. Documentation describes the callback queue, timeout, sticky wedge, relay threadpool behavior, and PowerShell fallback conditions.

Merge Risk: ⚪ Minimal · up to 4be4a

This change limits retries for wedged Windows process-table reads while preserving recovery behavior and existing unavailable-process semantics; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Windows process-table retention fix caused by repeated cooldown retries.
Description check ✅ Passed The description is detailed and on topic. It explains the problem, solution, rationale, behavior changes, tests, validation, limitations, and linked issue. Some template sections and checklist items a…
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.
Full details: Description check

Explanation

The description is detailed and on topic. It explains the problem, solution, rationale, behavior changes, tests, validation, limitations, and linked issue. Some template sections and checklist items are not explicitly completed, but the required technical information is mostly present.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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/windows/windows-process-table.ts (1)

149-167: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten this TypeScript comment block.

It explains implementation history and relay behavior in 19 lines. Keep only the sticky-wedge invariant and the reason for using a Set.

As per coding guidelines, TypeScript changes must be concise and must not be verbose or walk through the code.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f6ebb6e4-45a5-40ad-ad2d-d067754163ca

📥 Commits

Reviewing files that changed from the base of the PR and between 88ecc73 and 149c106.

📒 Files selected for processing (3)
  • docs/reference/windows-process-enumeration.md
  • src/main/windows/windows-process-table.test.ts
  • src/main/windows/windows-process-table.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Independent review verification for exact head 149c1065591670c3177f82725463f297fdbe4cb6: PASS, with no proven in-scope findings after three adversarial passes. The shared snapshot reader keeps the native path single-flight; the sticky gate retains at most the one timed-out callback, rejects later polls before either the desktop wrapper queue or relay bare-addon worker is entered, and reopens only when that callback returns. The relay escalation is mechanically valid because each bare-addon call queues a new async worker, while all consumers continue treating rejection as unavailable/unverifiable; macOS, Linux, WSL, folder-workspace, wire, persistence, mobile, and provider contracts are unchanged. The regression test is non-vacuous: the prior cooldown implementation permits one call in each of four expired windows, yielding five native calls versus the asserted one. No implementation edits were required; the remaining gap is real Windows wedge reproduction, which is not available from this macOS host, and there is no rendered Electron UI surface to validate.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA/evidence for exact head 149c1065591670c3177f82725463f297fdbe4cb6: pnpm test src/main/windows/windows-process-table.test.ts src/shared/process-table-snapshot.test.ts passed 34/34; affected foreground-process and port-scanner suites passed 32/32; pnpm tc:node, direct oxlint on both changed TypeScript files, and git diff --check passed. GitHub CI is fully green at this SHA, including static analysis, typecheck, Node 24/26 shards, cross-version wire, package, and package Windows; e2e is skipped because no e2e spec changed. The local check:code-quality:changed wrapper did not reach lint because the Node 26 engine warning polluted its JSON parser, so direct lint plus exact-SHA CI provide the evidence instead; an ad hoc formatter check including Markdown reported only wrap formatting in the changed reference doc, while both TypeScript files were clean. Windows-only native wedge behavior was reviewed and deterministically simulated by unit tests, but not reproduced on real Windows hardware; Electron CDP was not run because no rendered UI behavior changed.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review verification — exact head 4be4a6a9207a5f9b2a0db7a27ff1ca9561c6656f

No issues found after an exact-head adversarial review of the complete branch diff against origin/main. The open CodeRabbit reset-before-timeout finding was reproduced with a failing-first test and fixed with a native-reader epoch: stale deadlines still settle their own promise but cannot repopulate the current reset generation, and monotonic read IDs prevent stale callbacks from clearing newer state. CodeRabbit has auto-resolved the thread on this SHA.

Performance and compatibility review is clean: the fix adds only O(1) epoch/set operations; no polling, retry, subprocess, timer-count, listener, queue, wire, IPC, path, provider, folder-workspace, WSL, SSH, or remote liveness contract changed. Merge gate: exact-head CI is green and the review loop is clean; no merge was performed.

@brennanb2025

brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor Author

QA and evidence — exact head 4be4a6a9207a5f9b2a0db7a27ff1ca9561c6656f

Failing-first proof: reset before the 3 s deadline produced 1 failed / 23 passed and the stale timer falsely wedged the next healthy read. With the fix: focused Windows process-table suite 24/24 passed; snapshot-focused slice 35/35 passed; broad affected slice 85 files passed, 3 skipped, with 951 tests passed and 12 skipped. pnpm tc, direct oxlint, oxfmt --check for both touched TypeScript files, and git diff --check all passed.

Exact-head CI is green after rerunning two unrelated Node 24 flakes: both reruns passed without code changes and aggregate verify passed. The real Windows package (windows) job passed in 5m16s, including Windows-specific boundaries and packaged native capability; typecheck, static analysis, shell contracts, Git compatibility, cross-version wire compatibility, packaging, and Node 24/26 shards passed.

Important validation gap: deterministic tests and Windows packaging are not the same as reproducing the real wedge. They prove the state machine under injected callbacks and that the native addon packages; they do not prove the packaged/native Toolhelp path wedges, fails closed, and recovers on the affected high-spec Windows host under the affected account and its real EDR/security context. Electron/CDP and mobile QA are not applicable to this main-process-only change.

Real-validation gate on the Windows high-spec host:

  1. Run the packaged build for this exact SHA under the affected account and confirm the native @vscode/windows-process-tree path is active, not the CIM fallback.
  2. Use controlled native fault injection, or reproduce the environmental fault, to hold a real Toolhelp/process-table worker callback beyond the 3 s deadline. Record native worker/callback entry counts. If a genuine native hang cannot be injected or reproduced, report validation unavailable and do not call this a pass.
  3. While that callback remains held, drive repeated fresh reads from the real consumers or packaged validation harness, including concurrent bursts across at least four former 30 s cooldown windows. Verify the first read times out, every later read fails immediately with the sticky wedged result, native entry count stays exactly one with no re-entry, and the host process remains responsive.
  4. Validate both recovery paths in the same native harness: release the held callback and verify the next read succeeds immediately; separately reset before a stale deadline/callback completes and verify that stale completion neither wedges nor clears a newer read. Then verify normal foreground-process detection, port scanning, and teardown/process-liveness behavior afterward.

GitHub currently reports this PR OPEN and MERGEABLE/CLEAN with exact-head checks green, but those checks do not close the real-validation gap. Merge verdict: NOT READY until the real Windows validation above passes. No merge was performed.

@OrcaWin

OrcaWin commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

QA evidence on Windows x64 (exact head 4be4a6a): packaged @vscode/windows-process-tree loaded and real Toolhelp reads returned 752/745 entries including self. A real-time injected hold of the first native callback timed out at 3,010 ms; 12 fresh calls over four 30s former-cooldown windows made no re-entry (one native invocation), the host stayed responsive (1,124 100ms pulses), and callback-release plus reset-before-stale-callback recovered to real 747/745-row reads. windows-process-table (24), foreground/port/teardown suites (66 plus relay teardown/foreground 49) passed. Verdict: READY.

@brennanb2025
brennanb2025 merged commit 7c3bfe7 into main Aug 27, 2026
92 of 95 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
… per cooldown (stablyai#16696)

* fix(windows): stop a wedged process-table reader retaining a callback per cooldown

The vendored reader pushes every callback onto a module-global queue and drains
it only when the request holding its `requestInProgress` latch completes. When a
Toolhelp32 snapshot never comes back, that latch is stuck for the life of the
process, so the 30 s cooldown -- which let one probe through per window --
bounded the rate of new callbacks but not the total: one more closure retained
every 30 s, forever, plus a full 3 s deadline block on whichever caller drew the
probe.

Gate on the outstanding read instead. Once a read misses its deadline and has
not called back, every further read is refused until that read's callback fires,
which bounds retention at exactly one callback. Nothing is given up on recovery:
a probe queued behind the latch could never have observed the drain anyway,
whereas the stuck callback firing IS the drain, so the reader now resumes the
instant it recovers rather than up to 30 s later.

It matters more on a relay, which binds the bare addon with no JS queue to
absorb the retries. Each read there is a `Napi::AsyncWorker`, so a wedged one
holds a libuv threadpool slot for good and one probe per window would have
pinned all four default threads inside ~2 minutes -- hanging every async `fs`
and DNS call in that process, not just the process table.

A wedge still does not engage the PowerShell fallback, and a wedged read still
rejects rather than resolving empty, so "unavailable" stays distinguishable from
"nothing is running" on every host.

Fixes STA-5499.

* fix(windows): invalidate stale reader deadlines on reset

(cherry picked from commit 7c3bfe7)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… per cooldown (stablyai#16696)

* fix(windows): stop a wedged process-table reader retaining a callback per cooldown

The vendored reader pushes every callback onto a module-global queue and drains
it only when the request holding its `requestInProgress` latch completes. When a
Toolhelp32 snapshot never comes back, that latch is stuck for the life of the
process, so the 30 s cooldown -- which let one probe through per window --
bounded the rate of new callbacks but not the total: one more closure retained
every 30 s, forever, plus a full 3 s deadline block on whichever caller drew the
probe.

Gate on the outstanding read instead. Once a read misses its deadline and has
not called back, every further read is refused until that read's callback fires,
which bounds retention at exactly one callback. Nothing is given up on recovery:
a probe queued behind the latch could never have observed the drain anyway,
whereas the stuck callback firing IS the drain, so the reader now resumes the
instant it recovers rather than up to 30 s later.

It matters more on a relay, which binds the bare addon with no JS queue to
absorb the retries. Each read there is a `Napi::AsyncWorker`, so a wedged one
holds a libuv threadpool slot for good and one probe per window would have
pinned all four default threads inside ~2 minutes -- hanging every async `fs`
and DNS call in that process, not just the process table.

A wedge still does not engage the PowerShell fallback, and a wedged read still
rejects rather than resolving empty, so "unavailable" stays distinguishable from
"nothing is running" on every host.

Fixes STA-5499.

* fix(windows): invalidate stale reader deadlines on reset
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.

2 participants