fix(gateway): handle Windows OSError/SystemError in os.kill probes (#5760)#5762
Open
r266-tech wants to merge 2 commits into
Open
fix(gateway): handle Windows OSError/SystemError in os.kill probes (#5760)#5762r266-tech wants to merge 2 commits into
r266-tech wants to merge 2 commits into
Conversation
2 tasks
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
5 tasks
Collaborator
1 similar comment
Collaborator
2 tasks
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. On Windows,
os.kill(pid, 0)does not behave like POSIX. When the PID is invalid or the process has already exited, CPython raises:OSError: [WinError 87] The parameter is incorrect(instead ofProcessLookupError)SystemError: <built-in function kill> returned a result with an exception set(when the C-level wrapper sets an exception but returns a non-standard error)gateway/status.pyonly catches(ProcessLookupError, PermissionError)in two places, so on Windows the exception escapes and:acquire_scoped_lock(line 267) blocks the Telegram platform connectionget_running_pid(line 370) blocks gateway startup entirelyBoth happen whenever a previous gateway instance leaves a stale PID file behind, which is the common case after a crash.
Fix
Add
except (OSError, SystemError)clauses next to the existing(ProcessLookupError, PermissionError)clauses at both call sites. The new clauses follow the same code path (treat the previous owner as gone) and only widen behavior on Windows — POSIX still hits the originalProcessLookupError/PermissionErrorbranches first.Tests
Added 4 new tests in
tests/gateway/test_status.py::TestGatewayWindowsCompatibilitycovering both call sites under bothOSErrorandSystemError. They monkeypatchstatus.os.killto raise the Windows-style exception and assert:get_running_pid()returnsNoneand removes the stale PID fileacquire_scoped_lock()treats the existing record as stale and acquires the lock cleanlyVerified manually against the patched module before pushing — all four new scenarios pass and the existing "kill returns None means alive" path still works.
Test plan
os.killsucceeds -> process treated as alive) still works