Skip to content

fix(cli): fall back to SelectSelector when kqueue can't watch stdin on macOS#26077

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-a58567b6
May 15, 2026
Merged

fix(cli): fall back to SelectSelector when kqueue can't watch stdin on macOS#26077
teknium1 merged 2 commits into
mainfrom
hermes/hermes-a58567b6

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Salvage of #20948 by @outdoorsea onto current main.

Summary

Prevents the OSError: [Errno 22] Invalid argument startup crash that hits uv-managed cPython 3.11 on macOS (issue #5884). Probes KqueueSelector.register(0, EVENT_READ) at CLI startup; on failure, installs an event-loop policy that returns a SelectorEventLoop(SelectSelector()) so prompt_toolkit's add_reader(0, …) works. Also widens the existing except (KeyError, OSError) net to match EINVAL / EBADF / "Invalid argument" so any future leak hits the friendly "reinstall Python via pyenv/Homebrew" message instead of a raw traceback.

Changes

  • cli.py: kqueue probe + SelectSelector fallback before app.run(); widened post-app.run() except. Gated on sys.platform == 'darwin', no-op on Linux/Windows and on Homebrew/pyenv/system Python.
  • scripts/release.py: AUTHOR_MAP entry for jeremy@geocaching.comoutdoorsea.

Validation

  • Cherry-picked cleanly onto current main.
  • py_compile cli.py ok.
  • Lands next to the existing #6393 os.fstat(0) stdin pre-check.

Fan-out

~15 sibling PRs (#19501, #21660, #20482, #18363, #11253, #12111, #11866, #8796, #13251, #9996, #15720, #8843, #15706, etc.) target the same crash but only widen the except. This PR is the only one that actually prevents the failure. They'll be closed pointing here.

Closes #5884
Supersedes #20482, #21660, #19501, #18363, #11253, #12111, #11866, #8796, #13251, #9996, #15720, #8843, #15706

geocaching-jeremy and others added 2 commits May 14, 2026 20:14
On macOS with uv-managed cPython 3.11, the default kqueue selector cannot
register fd 0, so prompt_toolkit's loop.add_reader raises
OSError(EINVAL) ("[Errno 22] Invalid argument") from kqueue.control()
and the agent crashes immediately on startup (#5884, also reported in
#6393).

Probe KqueueSelector.register(0, EVENT_READ) before launching
prompt_toolkit. If it fails, install an event-loop policy that returns a
SelectorEventLoop backed by SelectSelector — select() works fine on
stdin in this Python build, so add_reader succeeds and the agent
launches normally.

Also extend the existing #6393 fallback handler to recognize EINVAL /
EBADF / "Invalid argument" so that any future selector failure on stdin
shows the friendly "reinstall Python via pyenv or Homebrew" guidance
instead of an opaque traceback.

Verified on macOS (Darwin 24.6.0) with uv-managed cPython 3.11.15: the
kqueue probe fails, the policy switch fires, and `hermes` launches
cleanly. No effect on platforms where kqueue can register fd 0.
@github-actions
Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-a58567b6 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8374 on HEAD, 8374 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4408 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/cli CLI entry point, hermes_cli/, setup wizard labels 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 P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Setup]: OSError: [Errno 22] Invalid argument:[prompt_toolkit crash]

3 participants