Repository navigation
fix(system): read Windows process command lines in process, not through PowerShell - #37857
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. The change removes the cause (starting PowerShell and running a WMI query on every poll) rather than raising the timeout, and it reuses the Toolhelp walk the repo already has. Notes
[DESIGN-REVIEWED] 917a4ad Description read[DESCRIPTION-READ] 45f3e67f4b35821c8ebc1ef2282af55b7d5555b80000cd1abfd95fae1fb78d8c That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: each removed piece (the shape check, the WQL quoting, the JSON parser, the spawn-audit entry) only existed for the PowerShell spawn, and the fix goes after the cause of the slow scans, which was PowerShell start-up plus WMI. Not checked: whether What this change shipsInventory (5 items) — 5 justifiedIntent: Windows users with the System page open get correct sandbox and
[FIRST-PRINCIPLES-REVIEWED] 917a4ad Description read[DESCRIPTION-READ] 386570034d146227950fb34b67de49dcec0b3c68d74521c187e8863e9829f30f That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
ea3401f to
3e67305
Compare
|
|
3e67305 to
b1497c5
Compare
|
Rebased with no code change onto 85d0512, which carries the boot-smoke fix (head b1497c5, range-diff |
b1497c5 to
7b2f5e9
Compare
|
Rebased with no code change onto d2f22f2 (head 7b2f5e9, range-diff |
7b2f5e9 to
917a4ad
Compare
Code change approver recommendation: A person should decideWhy: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 440 lines, more than the 400 it may approve on its own. The Windows process scan no longer starts PowerShell and runs WMI. It takes one process-list snapshot with the repo's existing helper, then reads each command line in process (OpenProcess plus NtQueryInformationProcess). Snapshot failures raise subclasses of OSError, which the new code catches and turns into None. Off Windows the reader is None, so the answer is None. The retry loop is bounded and always closes its handles, and the reply buffer is bounds-checked before it is read. The caller still skips its own pid and keeps its fallback to zero counts. The removed helpers and the spawn-audit entry have no other references. Tests drive the reader against fake DLLs on every host and against a real child process on Windows, and CI is green, including the Windows shards. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (4 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: fixes the slow Windows System page process probe by reading process command lines in process (Toolhelp snapshot plus NtQueryInformationProcess, with bounds checks on the returned buffer) instead of starting PowerShell for a WMI query; drops the now-unused PowerShell entry from the spawn audit list and updates its tests.
Problem / Motivation
Goal: On Windows, the System page counts the sandbox and
kiro-cliprocesses on every scan, and no scan holds/api/systemfor seconds.The Windows probe started a new
powershell.exefor each scan and ran a WMIWin32_Processquery with a 10 s timeout. On a busy host the query took 6 to 7 s and timed out in bursts (16 timeouts in one user's retained logs). Each timeout showed as 0 sandbox and 0kiro-cliprocesses, and every/api/systempoll that arrived during a scan waited on it, becauseapi_systemholds_metrics_lockfor the whole collection (#36676).Why it matters
Every Windows desktop user with the System page open is affected: the Performance tab polls every 2 s, so a slow scan stalls it, and a timed-out scan reports no MCP processes while dozens run.
Not a goal
test_unreadable_table_counts_zerokeeps it.platform_compat.process_command_line, the single-pid WMI reader used elsewhere.What changed (motivation → approach → change)
The cost was PowerShell start-up plus WMI, not the data. The reporter measured the same 34 processes in 0.13 to 0.41 s by reading the table in process.
windows_process_command_linesnow reads the table without starting a process:platform_compat._windows_process_parent_map)OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION)plusNtQueryInformationProcess(ProcessCommandLineInformation), retried once at the size Windows asks for, capped at the 32,767-character command-line limitLIKEwasThe function keeps its signature and its
Nonefor an unreadable table. A process this user cannot open, or one that exits mid-walk, is skipped. The answer buffer is read only when itsUNICODE_STRINGpoints inside the buffer with an even length.The signature-shape
ValueError, the WQL quoting helper and the JSON parser are removed: they existed because each signature was written into PowerShell source, and nothing is interpolated anywhere now. The benign-spawn entry for this function intest/spawn_audit_helpers.pygoes with the spawn.Backwards compatibility
Compatible: the one caller,
_scan_mcp_processes, passes two literal signatures and reads the same(pid, command line)rows orNone.Reader: src/kiro_crew/dashboard/handlers_system.py:_scan_mcp_processes -- crew page -- it never passed a signature the removed shape check refused;
test_counts_kiro_cli_and_sandbox_processesandtest_unreadable_table_counts_zero.Tests
TestProcessTableRead: a fake table with a sandbox, aKiro-CLI.EXE, an unrelated and an unreadable process gives the two matches; an unreadable snapshot and a missing reader giveNone; no signatures read nothing; the read starts no child process.test_finds_a_real_child_by_its_command_line_on_windows(Windows runners only) starts a child with a unique marker in its argv and finds exactly that pid.TestCommandLineBuffer: the answer decodes, and a string that reaches past the buffer, a pointer before it, or an odd length is refused.TestCommandLineReaderdrives the reader against fakekernel32andntdll, so it runs on every host: it reads a command line and closes the handle, reads again at the size Windows asks for, refuses an answer past the command-line limit or a failed query, and skips a process it cannot open without querying it. 20/20 repeats green.scripts/local-gate.py): 811 passed. One failure,test_data_home_owner.py::test_root_in_roots_own_home_is_left_alone, fails the same way onorigin/mainon this host.Proof: not provable -- other: the new tests import the new reader's helpers, so the reverted tree fails at collection rather than at an assertion
Manual verification
Not run on a Windows host from here. The real-process test above runs on the Windows backend shards; the struct layout and buffer checks run on every host.
Related Issues
Closes #36676
Sibling sweep
Swept: git grep -ln "Get-CimInstance" -- src website/electron
Sibling: src/kiro_crew/platform_compat_identity.py -- not affected -- reads one pid on demand, not a whole table per poll
Sibling: website/electron/windows-port.js -- tracked in #35497
Pattern harvest
Not generalizable: a per-poll subprocess on one Windows probe; the other Windows reads either run once or are already in process.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)