Skip to content

fix(security-guidance): support Windows venv layout so the agentic reviewer works on win32 - #81426

Open
mholovetskyi wants to merge 1 commit into
anthropics:mainfrom
mholovetskyi:fix/security-guidance-windows-venv
Open

fix(security-guidance): support Windows venv layout so the agentic reviewer works on win32#81426
mholovetskyi wants to merge 1 commit into
anthropics:mainfrom
mholovetskyi:fix/security-guidance-windows-venv

Conversation

@mholovetskyi

Copy link
Copy Markdown

Problem

security-guidance's strongest layer — the agentic commit reviewer — is unavailable on Windows unless claude_agent_sdk happens to be system-installed. The SessionStart bootstrap (hooks/ensure_agent_sdk.py) returns SKIP_WIN32 early, and the skip's own comment explains why: "Windows venv layout (Lib/site-packages, no python subdir) isn't handled by the consumer's glob."* The consumer fallbacks in hooks/llm.py glob only the POSIX layout (lib/python*/site-packages), and venv_py assumed bin/python.

This PR closes that annotated gap end-to-end rather than working around it.

Fix

  • llm.py (both SDK-fallback sites): additionally glob the Windows layout Lib/site-packages (no python* subdir). On POSIX the extra glob matches nothing; on Windows the original glob matches nothing — no behavior change on either platform beyond enabling the intended fallback.
  • ensure_agent_sdk.py: select the venv interpreter as Scripts/python.exe on win32 (bin/python elsewhere) and remove the early-return. The SKIP_WIN32 outcome code is retained but never emitted, so sdk_bootstrap telemetry rows from older plugin versions keep their meaning; new Windows rows will now report the same BUILT/NOOP/BUILD_FAILED codes as POSIX, and the existing err_phase/err_kind fingerprinting applies unchanged.

Everything else in the bootstrap is already platform-neutral (the O_EXCL sentinel lock, timeouts, pip invocation via the venv interpreter).

Tested on Windows 11 (Python 3.13.14)

Bootstrap, run twice against a scratch SECURITY_WARNINGS_STATE_DIR:

--- RUN 1 ---
{"async": true, "asyncTimeout": 180000}
{"metrics": {"sdk_bootstrap": 2, "sdk_bootstrap_ms": 51440, "pv": 20000}}   # BUILT
--- RUN 2 ---
{"async": true, "asyncTimeout": 180000}
{"metrics": {"sdk_bootstrap": 1, "sdk_bootstrap_ms": 5191, "pv": 20000}}    # NOOP_VENV

Consumer glob, against the venv built above:

OLD glob matches: []
NEW glob matches: ['...\agent-sdk-venv\Lib\site-packages']
claude_agent_sdk imported OK from: ...\Lib\site-packages\claude_agent_sdk\__init__.py

i.e. the pre-fix glob cannot see a Windows venv at all (confirming why the skip existed), and the new glob finds it and the SDK imports through it. py_compile passes on both files.

Notes

🤖 Generated with Claude Code

…viewer works on win32

The SessionStart bootstrap (ensure_agent_sdk.py) hard-skipped Windows
(SKIP_WIN32) because the consumer glob in llm.py only matched the POSIX
venv layout (lib/python*/site-packages) and venv_py assumed bin/python.
Net effect: the plugin's agentic commit-review layer was unavailable on
Windows unless claude_agent_sdk happened to be system-installed.

- llm.py (both fallback sites): also glob the Windows layout
  Lib/site-packages, which has no python* subdir
- ensure_agent_sdk.py: select Scripts/python.exe on win32 and remove the
  early-return; the SKIP_WIN32 outcome code is retained (never emitted)
  so telemetry rows from older plugin versions keep their meaning

Tested on Windows 11 (Python 3.13):
- run 1: sdk_bootstrap=2 (BUILT) - venv created, SDK pip-installed
- run 2: sdk_bootstrap=1 (NOOP_VENV) - existing venv detected
- old glob matches [] on the built venv; new glob finds Lib/site-packages
  and claude_agent_sdk imports through it

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant