Skip to content

fix(AI-CLI-if5u): resolve real tty device before backgrounding agent stdin - #147

Merged
sergeiwallace merged 1 commit into
mainfrom
wt/ai-cli-1/AI-CLI-ai-c-launcher-fails-start-bun-if5u
Sep 15, 2026
Merged

sergeiwallace merged 1 commit into
mainfrom
wt/ai-cli-1/AI-CLI-ai-c-launcher-fails-start-bun-if5u

Conversation

@sergeiwallace

Copy link
Copy Markdown
Owner

Summary

  • ai c 1 failed to launch/resume a CC session on macOS: Claude Code (Bun-compiled) crashed with EINVAL: invalid argument, kqueue after commit 6f0127b (fix(AI-CLI-1rk1): retain pi's terminal stdin when backgrounded, add consecutive-failure circuit breaker #145) started redirecting a backgrounded agent's stdin from the literal /dev/tty alias.
  • Root cause: on macOS, kqueue refuses to poll an fd opened through the generic /dev/tty alias path (ttyname_r resolves it back to /dev/tty itself rather than a real device). Externally confirmed: oven-sh/bun#41504.
  • Fix: resolve the controlling terminal's real device path via tty before backgrounding, and redirect from that resolved path. Falls back to the literal /dev/tty when resolution fails, same as before.

Test plan

  • Regression test test_given_terminal_stdin_when_agent_is_backgrounded_then_resolved_device_path_is_preferred added, confirmed RED on unfixed code, GREEN after the fix.
  • ruff check / ruff format --check pass.
  • Focused suite (tests/test_session_launch_shell_resolution.py): 11 passed.
  • Verified full-suite failures (test_public_repo_hygiene.py, test_native_deps.py, test_session_reload_mtime.py, test_stale_session_reaper.py[zsh]) are pre-existing/environmental — reproduced identically on the pre-fix commit, unrelated to this change (the [zsh] supervisor failures trace to this worktree's unapproved .envrc, tracked separately as AI-CLI-np2i).
  • Live ai c 1 re-launch on the real host to close the loop (orchestrator/user follow-up, not verifiable in this sandbox).

docs/bugs/ai-cli-if5u-kqueue-dev-tty-einval.md has the full root-cause writeup.

…stdin

commit 6f0127b redirected a backgrounded agent's stdin from the literal
/dev/tty alias. On macOS, kqueue refuses to poll an fd opened through that
alias path (ttyname_r resolves it to /dev/tty again rather than a real
device) -- Bun-compiled claude then crashes with EINVAL on launch. Resolve
the controlling terminal's actual device path via `tty` first and redirect
from that instead, falling back to the literal /dev/tty when resolution
fails. Root cause corroborated externally: oven-sh/bun#41504.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PFi83LbqMTznL3DW2sVm9d
@sergeiwallace
sergeiwallace merged commit acaaad0 into main Sep 15, 2026
3 of 10 checks passed
@sergeiwallace
sergeiwallace deleted the wt/ai-cli-1/AI-CLI-ai-c-launcher-fails-start-bun-if5u branch September 15, 2026 02:33
sergeiwallace pushed a commit that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants