Skip to content

fix(system): read Windows process command lines in process, not through PowerShell - #37857

Merged
cruisercohen merged 1 commit into
mainfrom
fix/36676-windows-process-probe
Nov 16, 2026
Merged

cruisercohen merged 1 commit into
mainfrom
fix/36676-windows-process-probe

Conversation

@cruisercohen

@cruisercohen cruisercohen commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On Windows, the System page counts the sandbox and kiro-cli processes on every scan, and no scan holds /api/system for seconds.

The Windows probe started a new powershell.exe for each scan and ran a WMI Win32_Process query 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 0 kiro-cli processes, and every /api/system poll that arrived during a scan waited on it, because api_system holds _metrics_lock for 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

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_lines now reads the table without starting a process:

Step Source
pids the Toolhelp snapshot walk the repo already uses for process trees (platform_compat._windows_process_parent_map)
each command line OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION) plus NtQueryInformationProcess(ProcessCommandLineInformation), retried once at the size Windows asks for, capped at the 32,767-character command-line limit
match case-insensitive substring, the same as WQL LIKE was

The function keeps its signature and its None for an unreadable table. A process this user cannot open, or one that exits mid-walk, is skipped. The answer buffer is read only when its UNICODE_STRING points 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 in test/spawn_audit_helpers.py goes with the spawn.

Backwards compatibility

Compatible: the one caller, _scan_mcp_processes, passes two literal signatures and reads the same (pid, command line) rows or None.

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_processes and test_unreadable_table_counts_zero.

Tests

  • TestProcessTableRead: a fake table with a sandbox, a Kiro-CLI.EXE, an unrelated and an unreadable process gives the two matches; an unreadable snapshot and a missing reader give None; 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.
  • TestCommandLineReader drives the reader against fake kernel32 and ntdll, 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.
  • Related tests (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 on origin/main on 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@cruisercohen
cruisercohen requested review from a team and KiroCrewCaptain as code owners November 16, 2026 06:50
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 917a4adbdbe9829f7c7452921b079f89c9d859ac touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 917a4adbdbe9829f7c7452921b079f89c9d859ac — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Unlike the old WMI query, this reads every pid's command line on each scan. That cost is only measured by the reporter's 0.13–0.41 s figure, so log the scan duration at debug level so a slow host shows up in retained logs.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 917a4adbdbe9829f7c7452921b079f89c9d859ac — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 NtQueryInformationProcess(ProcessCommandLineInformation) reads the table on real Windows hosts in under a second.

What this change ships

Inventory (5 items) — 5 justified

Intent: Windows users with the System page open get correct sandbox and kiro-cli counts, and no /api/system poll stalls for seconds. FIX.

  1. A Windows process scan no longer starts PowerShell. It reads the process table in process (a Toolhelp snapshot, then each pid's command line) — justified
  2. A busy host no longer times out the scan, so it no longer shows 0 sandbox and 0 kiro-cli processes — justified
  3. The signature-shape ValueError, _wql_literal and _parse_process_rows are removed — justified
  4. The benign-spawn audit entry for windows_process_command_lines is removed, since the function no longer spawns anything — justified
  5. A process this user cannot open is skipped instead of failing the whole query — justified

[FIRST-PRINCIPLES-REVIEWED] 917a4ad

Description read

[DESCRIPTION-READ] 386570034d146227950fb34b67de49dcec0b3c68d74521c187e8863e9829f30f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 917a4adbdbe9829f7c7452921b079f89c9d859ac — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 917a4ad

Verdict parsed from the review's SHA-scoped output markers for commit 917a4adbdbe9829f7c7452921b079f89c9d859ac.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 917a4adbdbe9829f7c7452921b079f89c9d859ac false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 917a4adbdbe9829f7c7452921b079f89c9d859ac and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 917a4ad

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 917a4adbdbe9829f7c7452921b079f89c9d859ac false-positive: <reason, 20 to 500 characters>

@cruisercohen
cruisercohen force-pushed the fix/36676-windows-process-probe branch 2 times, most recently from ea3401f to 3e67305 Compare November 16, 2026 08:09
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Integration (in-process gateway) fails on this head in test/integration/test_boot_smoke.py::test_a_second_boot_touches_only_known_module_globals on kiro_crew.apps.hidden_sessions._app_ids. That global comes from #37351 on main, and this diff touches neither file. It is tracked in #37844, and #37846 fixes it. I will rebase onto main once #37846 merges.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 16, 2026
@cruisercohen
cruisercohen force-pushed the fix/36676-windows-process-probe branch from 3e67305 to b1497c5 Compare November 16, 2026 11:20
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 16, 2026
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Rebased with no code change onto 85d0512, which carries the boot-smoke fix (head b1497c5, range-diff =). The one red, Backend Tests (3.12, 6), is 5 failures of test/test_chat_runtime_tree_sharing.py::test_claude_leaves_each_per_session_field_out_of_the_key (ChatRuntimeKey.build() got an unexpected keyword argument shared_scratch). That comes from main: #37826 removed the keyword and #37615 still passes it. #37945 fixes it, and this diff touches neither file.

@cruisercohen
cruisercohen force-pushed the fix/36676-windows-process-probe branch from b1497c5 to 7b2f5e9 Compare November 16, 2026 12:22
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Rebased with no code change onto d2f22f2 (head 7b2f5e9, range-diff =). The shard-6 red is gone. The remaining reds, Backend Tests (3.12, 7) and Backend Tests (Windows) (2), are both test_denied_commands_security_ssh_self.py::TestSshFloorNestingDepth::test_the_gate_refuses_a_nest_past_the_bound_without_an_exception, which went red on main with #37875. It is tracked in #37963, and #37964 fixes it. Coverage Gate fails only because those shards failed. This diff touches neither file.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 16, 2026
@cruisercohen
cruisercohen force-pushed the fix/36676-windows-process-probe branch from 7b2f5e9 to 917a4ad Compare November 16, 2026 13:55
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 16, 2026
@cruisercohen
cruisercohen enabled auto-merge (squash) November 16, 2026 14:59
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: 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 917a4adbdb · 440 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

None yet

Projects

None yet

2 participants