Skip to content

Comments

fix: add Windows compatibility to hook scripts#110

Open
DIV7NE wants to merge 1 commit intomixedbread-ai:mainfrom
DIV7NE:fix/windows-compatibility
Open

fix: add Windows compatibility to hook scripts#110
DIV7NE wants to merge 1 commit intomixedbread-ai:mainfrom
DIV7NE:fix/windows-compatibility

Conversation

@DIV7NE
Copy link

@DIV7NE DIV7NE commented Dec 28, 2025

Fixes #109

The hook scripts fail on Windows due to Unix-specific APIs:

  • os.setsid doesn't exist on Windows
  • signal.SIGKILL doesn't exist on Windows
  • Hardcoded /tmp/ paths don't exist on Windows
  • subprocess.Popen can't find .cmd files without shell=True

Changes:

  • Use tempfile.gettempdir() for cross-platform temp paths
  • Add find_mgrep_executable() to locate mgrep.cmd on Windows
  • Use shell=True + CREATE_NEW_PROCESS_GROUP on Windows
  • Use taskkill instead of SIGKILL on Windows
  • Add graceful error handling

Tested on Windows 11 with Python 3.14 and mgrep 0.1.6.


Note

Adds Windows support and hardens the mgrep hook flow.

  • Use tempfile.gettempdir() for PID/log files; replace hardcoded /tmp/*
  • New find_mgrep_executable() resolves mgrep/mgrep.cmd (including %APPDATA%\npm)
  • Windows-specific spawn: shell=True with CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS; Unix uses preexec_fn=os.setsid
  • Cross-platform termination: taskkill /F /PID on Windows; SIGKILL on Unix
  • Better resilience: handle missing payloads, skip when mgrep not found, avoid duplicate sessions via PID file, structured hook response always printed, expanded debug logging

Written by Cursor Bugbot for commit 4dd1dbd. This will update automatically on new commits. Configure here.

return True
except (OSError, ProcessLookupError) as e:
debug_log(f"Failed to kill process {pid}: {e}")
return False
Copy link

Choose a reason for hiding this comment

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

Windows taskkill result ignored causing false success reporting

The kill_process function has inconsistent behavior between platforms. On Windows, subprocess.run with check=False ignores taskkill's exit code, so the function always returns True even when the kill fails (e.g., process not found or access denied). On Unix, os.kill properly raises ProcessLookupError when the process doesn't exist, returning False. This causes incorrect "Killed mgrep watch process" logging on Windows and could lead to orphaned processes if taskkill fails but the PID file is still deleted.

Fix in Cursor Fix in Web

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.

Windows compatibility issues in hook scripts

1 participant