Skip to content

Fix Windows: registry write crash, process liveness probes, and drive-relative /tmp paths - #7

Open
neelsvan wants to merge 3 commits into
captivus:mainfrom
neelsvan:fix/windows-compatibility
Open

Fix Windows: registry write crash, process liveness probes, and drive-relative /tmp paths#7
neelsvan wants to merge 3 commits into
captivus:mainfrom
neelsvan:fix/windows-compatibility

Conversation

@neelsvan

Copy link
Copy Markdown

Summary

Three fixes that make the CLI usable on Windows. All changes are behind sys.platform == "win32" except the os.rename -> os.replace swap, which is equivalent-or-better on POSIX. No POSIX behavior changes.

1. os.replace for registry writes (registry.py)

os.rename raises FileExistsError (WinError 183) when the destination exists -- which is every save after the first. launch crashed on a clean Windows machine right after creating the initial registry file.

2. Windows-safe process liveness probes (utils.py)

os.kill(pid, 0) is a POSIX idiom. On Windows, signal 0 maps to CTRL_C_EVENT and the call raises OSError (WinError 87, "The parameter is incorrect") for ordinary processes, so every registry liveness check crashed -- status, stop, attach, and cleanup were all unusable. The fix probes with OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION) (ERROR_ACCESS_DENIED still proves existence) and adds a GetProcessTimes-based start-time token so the PID-reuse identity check works on Windows too, instead of silently returning None via the ps -o lstart= fallback.

3. Absolute temp paths on Windows (registry.py, launcher.py)

"/tmp/chrome-agent" is drive-relative on Windows -- it resolves against the current drive. Instances registered while working on one drive are invisible from another, and every command reports "No instances registered". The registry and session root now resolve via tempfile.gettempdir() on Windows.

Testing

  • Windows 11, Python 3.14.3, Chrome 151 -- full lifecycle verified manually (launch / status / navigate / Runtime.evaluate / screenshot / attach with +Network.requestWillBeSent / stop, from two different drives):
    • main: 29 failed, 49 errors, 86 passed
    • this branch: 9 failed, 8 errors, 147 passed
    • remaining failures are POSIX-semantics tests (SIGTERM-based attach exits, /proc-based sweep identity) and fingerprint/viewport assertions that do not hold in this environment
  • Linux (python:3.12-slim container, no Chrome installed) -- identical results on main and this branch (44 passed / 6 failed / 9 errors; every failure is BrowserNotFoundError from the missing browser), confirming no POSIX regressions in the touched modules (test_registry and test_pid_identity pass fully).

Not addressed (out of scope): os.kill(pid, 15) in registry.py maps to TerminateProcess on Windows rather than a graceful SIGTERM -- functional, but stop is a hard kill there.

os.rename fails with FileExistsError (WinError 183) when the
destination exists, which is every save after the first one --
launch crashed on a clean Windows machine after creating the
initial registry file. os.replace overwrites atomically on all
platforms and is the documented replacement.
os.kill(pid, 0) is a POSIX idiom; on Windows signal 0 maps to
CTRL_C_EVENT and raises OSError (WinError 87, 'The parameter is
incorrect') for ordinary processes, so every registry liveness
check crashed: status, stop, attach and cleanup were unusable.

Probe with OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION) instead
(ERROR_ACCESS_DENIED still proves existence), and add a
GetProcessTimes-based start-time token so the PID-reuse identity
check also works on Windows instead of silently returning None.
POSIX code paths are unchanged.
"/tmp/chrome-agent" is drive-relative on Windows: it resolves
against the current drive, so instances registered while working
on one drive are invisible from another and every command reports
"No instances registered". Resolve the registry and session root
against tempfile.gettempdir() on Windows; POSIX behavior is
unchanged.
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