Skip to content

Fix auth store file lock for Windows#455

Merged
teknium1 merged 1 commit intoNousResearch:mainfrom
shitcoinsherpa:fix/windows-auth-lock-reentrancy
Mar 10, 2026
Merged

Fix auth store file lock for Windows#455
teknium1 merged 1 commit intoNousResearch:mainfrom
shitcoinsherpa:fix/windows-auth-lock-reentrancy

Conversation

@shitcoinsherpa
Copy link
Copy Markdown
Contributor

Problem

_auth_store_lock in hermes_cli/auth.py uses fcntl.flock for cross-process locking, which doesn't exist on Windows. Without a lock backend, auth operations silently skip locking entirely.

Additionally, resolve_codex_runtime_credentials acquires the lock and then calls _save_codex_tokens, which tries to acquire it again from the same thread. fcntl.flock handles this fine because it's reentrant per-thread on Unix. The Windows equivalent (msvcrt.locking) is not reentrant, so this nested call deadlocks for 15 seconds and then throws a TimeoutError.

Fix

  • Add msvcrt.locking as the lock backend when fcntl is unavailable (Windows).
  • Track lock depth per thread using threading.local() so nested acquisitions from the same thread pass through without re-acquiring the underlying lock.
  • Handle msvcrt-specific requirements: file opened in r+ mode (not a+), at least 1 byte of content, file pointer at position 0.

Testing

Ran hermes doctor on Windows 11. Before: TimeoutError after 15s on Codex auth check. After: completes normally.

fcntl is not available on Windows. This adds msvcrt.locking as a
fallback for cross-process advisory locking on Windows.

msvcrt.locking is not reentrant within the same thread, unlike fcntl.flock.
This matters because resolve_codex_runtime_credentials holds the lock and
then calls _save_codex_tokens, which tries to acquire it again. Without
reentrancy tracking, this deadlocks on Windows after a 15-second timeout.

Uses threading.local() to track lock depth per thread, allowing nested
acquisitions to pass through without re-acquiring the underlying lock.

Also handles msvcrt-specific requirements: file must be opened in r+ mode
(not a+), must have at least 1 byte of content, and the file pointer must
be at position 0 before locking.
@teknium1 teknium1 merged commit 3e352f8 into NousResearch:main Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants