Skip to content

fix: fail fast when interactive attach has no TTY - #956

Merged
norrietaylor merged 1 commit into
mainfrom
inbox-patch/fix-attach-nontty-hang-5883883572165c1c
Jul 25, 2026
Merged

fix: fail fast when interactive attach has no TTY#956
norrietaylor merged 1 commit into
mainfrom
inbox-patch/fix-attach-nontty-hang-5883883572165c1c

Conversation

@gominimal-aw-bot

@gominimal-aw-bot gominimal-aw-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #953
Routing-Key: inbox-route/I_kwDOSUhdos8AAAABKFe2XA

Defect

min attach <session> (and min activate --attach) hangs forever when stdin is not a terminal — e.g. min attach <session> < /dev/null, or a piped min activate -n s --attach ..

The interactive attach path shells out to ssh -tt (attach_to_session in crates/minimal/src/lib.rs), forcing a remote PTY so the daemon's shell_request session 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()) in attach_to_session on stdin being a TTY. When it is not, bail with an actionable error before exec'ing ssh:

min attach needs an interactive terminal, but stdin is not a TTY. Run it from a terminal, or use min attach --command <cmd> to run a single command non-interactively.

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 by docs/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 warningsFinished with 0 warnings.
  • cargo build --workspace --locked --manifest-path target/Cargo.tomlFinished \dev` profile`.
  • cargo test --workspace --locked --manifest-path target/Cargo.toml — all workspace suites green (0 failed), including the new tests::interactive_attach_requires_a_tty_on_stdin regression test and the existing attach_with_no_session_* cases; sessions lib 342 passed, client-flow suites 11 + 21 passed, doctests passed.

Generated by inbox-patch ·

Note

Fail fast on interactive attach when stdin is not a TTY

Adds a guard in attach_to_session that 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 --command for non-interactive execution. Behavioral Change: previously, a non-TTY stdin would cause the interactive attach to hang due to -tt forcing PTY allocation over a non-terminal stdin.

Macroscope summarized 60cc943.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented interactive attach sessions from hanging when standard input is not connected to a terminal.
    • Added a clear error message with guidance when interactive attach cannot proceed.
    • Preserved normal behavior for sessions connected to a terminal.

`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>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

min attach now fails fast when interactive mode receives non-TTY stdin, before forcing an SSH PTY. The change adds an actionable error and unit coverage for both TTY and non-TTY inputs.

Changes

Interactive attach TTY validation

Layer / File(s) Summary
Fail-fast TTY guard and test coverage
crates/minimal/src/lib.rs
Adds ensure_interactive_attach_tty, calls it before interactive ssh -tt setup, and tests both rejected non-TTY and accepted TTY input.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 360: Addresses the non-TTY interactive attach hang with a fail-fast terminal check.

Poem

A bunny hops where terminals gleam,
Guarding SSH from a hanging dream.
No TTY? “Try command mode,”
A clear sign along the road.
Tests spring up, both paths in sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the requested fail-fast TTY guard and regression tests for #953, matching the issue's stated objective.
Out of Scope Changes check ✅ Passed The changes appear narrowly focused on the TTY guard and its tests, with no unrelated code paths introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise, conventional, and accurately summarizes the main change: failing fast on non-TTY interactive attach.
Description check ✅ Passed The description covers the defect, change, and verification well, but it does not use the template's explicit Summary/Testing/Checklist sections.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@norrietaylor
norrietaylor marked this pull request as ready for review July 25, 2026 00:24
@norrietaylor
norrietaylor merged commit 3440a48 into main Jul 25, 2026
28 of 29 checks passed
@norrietaylor
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>
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.

bug: min attach without a TTY hangs indefinitely

1 participant