Repository navigation
fix(windows): stop a wedged process-table reader retaining a callback per cooldown - #16696
Conversation
… 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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/windows/windows-process-table.ts (1)
149-167: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten 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
📒 Files selected for processing (3)
docs/reference/windows-process-enumeration.mdsrc/main/windows/windows-process-table.test.tssrc/main/windows/windows-process-table.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
|
Independent review verification for exact head |
|
QA/evidence for exact head |
|
Final review verification — exact head No issues found after an exact-head adversarial review of the complete branch diff against 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. |
|
QA and evidence — exact head 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. Exact-head CI is green after rerunning two unrelated Node 24 flakes: both reruns passed without code changes and aggregate 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:
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. |
|
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. |
… 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)
… 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
What's wrong
src/main/windows/windows-process-table.tsguards 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
requestInProgresslatch completes: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.
A
Setof 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()inaddon.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 asyncfsand 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
docs/reference/windows-process-enumeration.md). A present-but-failing reader must never start forking shells at the caller's poll rate.docs/reference/ssh-execution-boundary.md.nulloff Windows and returns before the new gate).Tests
src/main/windows/windows-process-table.test.ts— thewedge cooldownblock becomessticky wedge:never re-enters the reader while the timed-out read is still outresumes as soon as the timed-out read finally calls backstops calling the reader after a timeout…clears the deadline when the reader throws synchronouslyNon-vacuous — reverting only
windows-process-table.tsand re-running: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 skippedpnpm tc→ cleanoxlint+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
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.src/main/windows/windows-process-table.test.tsuses 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 experimentalterminal-session.explicit-close-retirementprocess-table gate.timed outandwedgederrors plus deterministic native-call counts identify the failure mode.