Fix auth store file lock for Windows#455
Merged
teknium1 merged 1 commit intoNousResearch:mainfrom Mar 10, 2026
Merged
Conversation
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.
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.
Problem
_auth_store_lockinhermes_cli/auth.pyusesfcntl.flockfor cross-process locking, which doesn't exist on Windows. Without a lock backend, auth operations silently skip locking entirely.Additionally,
resolve_codex_runtime_credentialsacquires the lock and then calls_save_codex_tokens, which tries to acquire it again from the same thread.fcntl.flockhandles 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 aTimeoutError.Fix
msvcrt.lockingas the lock backend whenfcntlis unavailable (Windows).threading.local()so nested acquisitions from the same thread pass through without re-acquiring the underlying lock.msvcrt-specific requirements: file opened inr+mode (nota+), at least 1 byte of content, file pointer at position 0.Testing
Ran
hermes doctoron Windows 11. Before:TimeoutErrorafter 15s on Codex auth check. After: completes normally.