fix(cli): fall back to PollSelector when kqueue can't register stdin (macOS 26+)#12111
Closed
evanstinger wants to merge 1 commit into
Closed
fix(cli): fall back to PollSelector when kqueue can't register stdin (macOS 26+)#12111evanstinger wants to merge 1 commit into
evanstinger wants to merge 1 commit into
Conversation
…(macOS 26+) macOS 26 introduced a kqueue regression where registering stdin (fd 0) for EVENT_READ raises OSError [Errno 22] Invalid argument. This crashes prompt_toolkit on startup via Vt100Input._attached_input() → loop.add_reader(0, ...). Detect the broken kqueue early in startup (before prompt_toolkit is imported) and replace selectors.DefaultSelector with PollSelector. Upstream issue: prompt-toolkit/python-prompt-toolkit#1943 Upstream PR (unmerged): prompt-toolkit/python-prompt-toolkit#2065
13 tasks
Contributor
|
Closing — superseded by #26077 (merged as commit d3d5916), which preventively probes kqueue at startup and falls back to SelectSelector when fd 0 cannot be registered. The widened except-clause matching EINVAL / EBADF / 'Invalid argument' — which most PRs in this cluster including yours added — is also included. Thanks for the fix; closing as duplicate of the merged work. |
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.
What does this PR do?
Fixes a crash on macOS 26+ where
hermes(interactive chat mode) fails immediately with:macOS 26 introduced a kqueue regression where registering stdin (fd 0) for
EVENT_READraisesOSError [Errno 22] Invalid argument.prompt_toolkittriggers this vialoop.add_reader(0, ...)inVt100Input._attached_input().Root Cause
Python's
selectors.KqueueSelector(default on macOS) can no longer register fd 0 on macOS 26+. The existing workaround from #8560 (fstat guard + exception handler) doesn't prevent this crash because theOSErrorfires insideprompt_toolkit's context manager__enter__, before our exception handler is reached.Fix
Probe kqueue early in startup (after
_apply_profile_override(), before anyprompt_toolkitimport). IfKqueueSelectorcan't register stdin, replaceselectors.DefaultSelectorwithPollSelector, which works correctly.Only activates on
sys.platform == "darwin"when kqueue is actually broken — zero impact on other platforms or older macOS versions.Related Issue
Type of Change
Changes Made
hermes_cli/main.py: Add kqueue probe + PollSelector fallback after_apply_profile_override(), before anyprompt_toolkitimportHow to Test
hermes— previously crashed withOSError [Errno 22], now starts normallypython -c "import selectors; s=selectors.DefaultSelector(); s.register(0, selectors.EVENT_READ); s.unregister(0)"— fails on macOS 26+ withKqueueSelector, passes withPollSelectorChecklist
Code
Documentation & Housekeeping