Skip to content

fix: catch kqueue EINVAL selector error on uv-managed macOS Python#18363

Closed
henrytran1803 wants to merge 1 commit into
NousResearch:mainfrom
henrytran1803:fix/kqueue-einval-stdin-macos
Closed

fix: catch kqueue EINVAL selector error on uv-managed macOS Python#18363
henrytran1803 wants to merge 1 commit into
NousResearch:mainfrom
henrytran1803:fix/kqueue-einval-stdin-macos

Conversation

@henrytran1803
Copy link
Copy Markdown

Summary

  • On macOS with uv-managed cPython, the kqueue selector fails to register stdin (fd 0) with OSError: [Errno 22] Invalid argument. The existing error handlers only caught errno.EIO and string-matched "is not registered" / "Bad file descriptor", causing an unhandled crash.

Changes

  1. Selector probe — Before launching prompt_toolkit, actively tries to register fd 0 with selectors.DefaultSelector(). Catches the failure early with a user-friendly message instead of a traceback.
  2. Async exception handler — Added errno.EINVAL alongside errno.EIO so kqueue EINVAL errors are suppressed in the event loop handler.
  3. app.run() exception handler — Added errno.EINVAL to the errno check and "Invalid argument" to the string match.

Test plan

  • Reproduced the crash on macOS with uv-managed cPython 3.11 (/Users/henrytran/.local/share/uv/python/cpython-3.11.15-macos-aarch64-none/)
  • Verified the fix shows a clean error message instead of a traceback
  • Existing tests for stdin/stdout error handling remain unaffected

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists labels May 1, 2026
@alt-glitch
Copy link
Copy Markdown
Collaborator

Likely duplicate of #11253, #8796, #13251, #11866, #9996 — same kqueue EINVAL on macOS stdin selector registration. Multiple competing PRs already exist for #6393.

@alt-glitch
Copy link
Copy Markdown
Collaborator

Likely duplicate of #11253, #8796, #13251, #11866, #9996 — same kqueue EINVAL on macOS stdin selector registration.

@teknium1
Copy link
Copy Markdown
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.

@teknium1 teknium1 closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists 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