Skip to content

fix: Windows compatibility for process lock check#12490

Closed
phpoh wants to merge 1 commit into
NousResearch:mainfrom
phpoh:fix-windows-pid-check
Closed

fix: Windows compatibility for process lock check#12490
phpoh wants to merge 1 commit into
NousResearch:mainfrom
phpoh:fix-windows-pid-check

Conversation

@phpoh

@phpoh phpoh commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Problem

On Windows, os.kill(pid, 0) raises OSError: [WinError 87] (invalid parameter) instead of ProcessLookupError. This causes the gateway to fail on startup when checking for existing process locks.

Solution

Simply add OSError to the exception list. This is a minimal fix that requires no additional dependencies.

Testing

Tested on Windows 10/11 with Git Bash (MINGW64). Gateway now starts successfully.

Error Before Fix

ERROR gateway.platforms.telegram: [Telegram] Failed to connect to Telegram: [WinError 87] 参数错误。
OSError: [WinError 87] 参数错误。

After Fix

Gateway starts normally and connects to Telegram successfully.

@phpoh phpoh force-pushed the fix-windows-pid-check branch from 64981a8 to ee4a461 Compare April 19, 2026 09:34
On Windows, os.kill(pid, 0) raises OSError with WinError 87
instead of ProcessLookupError. Adding OSError to the except
clause fixes the gateway startup failure on Windows.

Fixes two locations:
- acquire_scoped_lock() line 344
- get_running_pid() line 580

No additional dependencies required.
@phpoh phpoh force-pushed the fix-windows-pid-check branch from ee4a461 to 5efe15c Compare April 19, 2026 09:43
teknium1 pushed a commit that referenced this pull request Apr 23, 2026
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.

Adapted @phpoh's fix in #12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).

Co-authored-by: phpoh <1352808998@qq.com>
@teknium1

Copy link
Copy Markdown
Contributor

Thanks @phpoh! Your Windows-compat fix was reapplied onto current main and merged via #14504. The main file was refactored since your PR (get_running_pid now iterates primary/fallback records), so I had to adapt the OSError catch to the new shape — added it after PermissionError since PermissionError is an OSError subclass and except-clause ordering matters. Authorship preserved.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels Apr 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Superseded by #14504 which salvaged this fix onto current main.

ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.

Adapted @phpoh's fix in NousResearch#12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).

Co-authored-by: phpoh <1352808998@qq.com>
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.

Adapted @phpoh's fix in NousResearch#12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).

Co-authored-by: phpoh <1352808998@qq.com>
donald131 pushed a commit to donald131/hermes-agent that referenced this pull request May 2, 2026
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.

Adapted @phpoh's fix in NousResearch#12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).

Co-authored-by: phpoh <1352808998@qq.com>
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.

Adapted @phpoh's fix in NousResearch#12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).

Co-authored-by: phpoh <1352808998@qq.com>
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.

Adapted @phpoh's fix in NousResearch#12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).

Co-authored-by: phpoh <1352808998@qq.com>
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.

Adapted @phpoh's fix in NousResearch#12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).

Co-authored-by: phpoh <1352808998@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants