fix(gateway): use ctypes.OpenProcess for Windows process existence check#13587
Closed
zhanggttry wants to merge 3 commits into
Closed
fix(gateway): use ctypes.OpenProcess for Windows process existence check#13587zhanggttry wants to merge 3 commits into
zhanggttry wants to merge 3 commits into
Conversation
Replace os.kill(pid, 0) with _process_exists() helper that uses: - Windows: ctypes.windll.kernel32.OpenProcess() (avoids SystemError WinError 87) - POSIX: os.kill(pid, 0) (unchanged behavior) Fixes NousResearch#5760, NousResearch#8978, NousResearch#12359
3 tasks
Collaborator
zhanggttry
added a commit
to zhanggttry/hermes-agent
that referenced
this pull request
Apr 22, 2026
…g to file reads - os.kill(pid, 0) on Windows raises OSError (WinError 87) for non-existent PIDs instead of ProcessLookupError. Catch OSError everywhere to prevent crash on Windows process-existence checks. - Path.read_text() and open() default to gbk on Chinese Windows. Add explicit encoding='utf-8' to all file reads to prevent UnicodeDecodeError when config files or skill manifests contain non-ASCII characters. Files changed: - gateway/run.py, gateway/status.py (os.kill + read_text) - hermes_cli/*.py (read_text + open) - tools/*.py (read_text) Closes: NousResearch#13587 NousResearch#5762 NousResearch#7835 NousResearch#9024
1 task
Contributor
Author
|
Superseded by #13986 which uses a safer pure-Python approach (no ctypes/windll) to avoid Supply Chain Audit failures. |
This was referenced Apr 23, 2026
Closed
2 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5760, #8978, #12359 —
os.kill(pid, 0)raisesSystemError: [WinError 87]on Windows, blocking gateway startup.Root Cause
Windows does not support Unix signal 0 (existence check).
os.kill(pid, 0)on Windows raises:This crashes gateway startup at two locations:
acquire_scoped_lock()(line 363) — blocks Telegram platform connectionget_running_pid()(line 598) — blocks gateway startup entirelySolution
Add
_process_exists(pid: int) -> boolhelper function that uses:ctypes.windll.kernel32.OpenProcess()— native Windows API for process existence checkos.kill(pid, 0)— unchanged behaviorChanges
gateway/status.py: Add_process_exists()helper, replace 2os.kill(pid, 0)callsTesting
Related Issues