fix: fail fast when interactive attach has no TTY - #956
Merged
norrietaylor merged 1 commit intoJul 25, 2026
Conversation
`min attach` with stdin redirected from /dev/null or a pipe forced `ssh -tt`, which allocates a remote PTY the interactive shell then reads. That read never sees EOF from a non-terminal local stdin, so the command blocked indefinitely instead of failing fast (#953). Guard the interactive path on stdin being a TTY and bail with an actionable message pointing at a real terminal or `--command` otherwise. The e2e and networking suites drive attach through a real pty (scripts/e2e-attach-pty.py), so their stdin stays a terminal and the guard never fires. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesInteractive attach TTY validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
norrietaylor
marked this pull request as ready for review
July 25, 2026 00:24
norrietaylor
approved these changes
Jul 25, 2026
norrietaylor
deleted the
inbox-patch/fix-attach-nontty-hang-5883883572165c1c
branch
July 25, 2026 00:25
norrietaylor
added a commit
that referenced
this pull request
Jul 28, 2026
Replace the `exec()` process replacement at the end of the attach path with spawn + wait, so control returns to the client after the session shell exits — the seam client-driven post-attach flows hook into. Observable behavior is preserved: - The child's exit code is propagated verbatim via `std::process::exit` (signal death maps to the shell's 128+N convention, the same $? an exec()'d ssh produced). - `-tt` PTY semantics are unchanged, and the interactive path now fails fast when stdin is not a TTY instead of blocking forever in `ssh -tt` (ports the #956 guard, which this branch's base predates). - SIGINT/SIGQUIT are ignored in the waiting parent for exactly as long as the child runs — the POSIX system(3) discipline — so Ctrl-C reaches the foreground ssh / in-session process, and the saved dispositions are restored once the child exits. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 29, 2026
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.
Fixes #953
Routing-Key: inbox-route/I_kwDOSUhdos8AAAABKFe2XA
Defect
min attach <session>(andmin activate --attach) hangs forever when stdin is not a terminal — e.g.min attach <session> < /dev/null, or a pipedmin activate -n s --attach ..The interactive attach path shells out to
ssh -tt(attach_to_sessionincrates/minimal/src/lib.rs), forcing a remote PTY so the daemon'sshell_requestsession shell can start. With a redirected local stdin ssh still forces that PTY, but the interactive shell reading it never receives an EOF through the PTY from a non-terminal local stdin — so the command blocks indefinitely instead of failing fast.Change
Guard the interactive branch (
command.is_none()) inattach_to_sessionon stdin being a TTY. When it is not, bail with an actionable error before exec'ing ssh:The check is factored into a small pure helper (
ensure_interactive_attach_tty) so both branches are unit-testable, with a regression test asserting the fail-fast message and that a real terminal passes the guard.The e2e and networking suites drive attach through a real pty (
scripts/e2e-attach-pty.py), so their stdin stays a terminal and the guard never fires — the per-session networking assertions run the full interactive session path and never use a non-tty pipe (informed bydocs/specs/03-spec-networking/test-plan.md). Scope is limited to the reported hang; the broader non-interactive exec surface (minimal#865) is untouched.Verification
All commands run from the workspace root with
--locked, matching CI. Each exited 0.cargo fmt --all --check --manifest-path target/Cargo.toml— clean, no formatting drift.cargo clippy --workspace --locked --manifest-path target/Cargo.toml -- -D warnings—Finishedwith 0 warnings.cargo build --workspace --locked --manifest-path target/Cargo.toml—Finished \dev` profile`.cargo test --workspace --locked --manifest-path target/Cargo.toml— all workspace suites green (0 failed), including the newtests::interactive_attach_requires_a_tty_on_stdinregression test and the existingattach_with_no_session_*cases; sessions lib 342 passed, client-flow suites 11 + 21 passed, doctests passed.Note
Fail fast on interactive attach when stdin is not a TTY
Adds a guard in
attach_to_sessionthat checks whether stdin is a TTY before proceeding with an interactive attach. When stdin is not a TTY, the command exits immediately with an error advising the user to run from a terminal or use--commandfor non-interactive execution. Behavioral Change: previously, a non-TTY stdin would cause the interactive attach to hang due to-ttforcing PTY allocation over a non-terminal stdin.Macroscope summarized 60cc943.
Summary by CodeRabbit