Skip to content

fix(init): use isatty(0) for TTY detection and add diagnostic probe#767

Merged
betegon merged 1 commit intomainfrom
fix/init-tty-stdin-hardening
Apr 17, 2026
Merged

fix(init): use isatty(0) for TTY detection and add diagnostic probe#767
betegon merged 1 commit intomainfrom
fix/init-tty-stdin-hardening

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 17, 2026

Summary

  • Align the init wizard's TTY guard with the rest of the codebase by using isatty(0) from node:tty instead of process.stdin.isTTY (unreliable in Bun on inherited fds)
  • Defensively backfill process.stdin.isTTY when isatty(0) reports true but the property is undefined, preventing @clack/core from silently skipping setRawMode
  • Add an opt-in diagnostic probe (SENTRY_INIT_DIAGNOSTICS=1) for future TTY-related bug reports

Context

A user reported that curl -fsSL https://cli.sentry.dev/install | SENTRY_INIT=1 bash installs the binary but the first @clack/prompts confirm prompt doesn't register keystrokes. The install script correctly runs exec "$sentry_bin" init </dev/tty to reattach stdin to the terminal.

Investigation result: We could not reproduce the bug with the current HEAD binary. Both the piped reproducer (bash -c 'exec ./sentry init </dev/tty' < /dev/null) and the plain interactive run showed healthy TTY signals and accepted keystrokes normally.

However, the init wizard was the last remaining site in the codebase still using process.stdin.isTTY for TTY detection. Six other sites (src/cli.ts, mutate-command.ts, commands/log/view.ts, commands/auth/login.ts, seer-trial.ts, commands/trial/start.ts) already use isatty(0) precisely because process.stdin.isTTY is known to be unreliable in Bun's single-file binary. This change closes that consistency gap.

Diagnostic probe

The new SENTRY_INIT_DIAGNOSTICS=1 env var dumps a snapshot of stdin/stdout TTY state to stderr at two points: wizard entry and before the first prompt. If the bug resurfaces, reporters can include this output for targeted diagnosis instead of us guessing. Zero overhead when disabled.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

Init

  • Use isatty(0) for TTY detection and add diagnostic probe by BYK in #767
  • Reuse detected existing project data by betegon in #766
  • Ensure project reuse and spinner states by MathurAditya724 in #763

Internal Changes 🔧

  • Regenerate docs by github-actions[bot] in e02799c1

🤖 This preview updates automatically when you update the PR.

@betegon betegon force-pushed the fix/init-tty-stdin-hardening branch from c0c3009 to 53407f7 Compare April 17, 2026 16:06
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-767/

Built to branch gh-pages at 2026-04-17 16:27 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@betegon betegon marked this pull request as ready for review April 17, 2026 16:07
@betegon betegon force-pushed the fix/init-tty-stdin-hardening branch from 53407f7 to 0a33220 Compare April 17, 2026 16:08
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 2026

Codecov Results 📊

134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1649 uncovered lines.
✅ Project coverage is 95.5%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.50%    95.50%        —%
==========================================
  Files          253       254        +1
  Lines        36666     36676       +10
  Branches         0         0         —
==========================================
+ Hits         35019     35027        +8
- Misses        1647      1649        +2
- Partials         0         0         —

Generated by Codecov Action

Comment thread src/lib/init/stdin-reopen.ts
Comment thread src/lib/init/stdin-reopen.ts
Comment thread src/lib/init/stdin-reopen.ts
Bun's single-file binaries don't deliver keypresses through TTY fds inherited
via shell redirection (e.g. `curl | bash` → `exec sentry init </dev/tty` in
install.sh) even though isatty(0) and setRawMode report success. A freshly
opened /dev/tty fd from inside the process works, so open one in preamble()
and forward its data events onto process.stdin. Route setRawMode to the fresh
fd, and no-op pause/resume/_read on process.stdin to keep the stream
machinery from hitting kqueue EINVAL on the broken fd between prompts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@betegon betegon force-pushed the fix/init-tty-stdin-hardening branch from 0a33220 to a435af8 Compare April 17, 2026 16:26
Comment thread src/lib/init/stdin-reopen.ts
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a435af8. Configure here.

Comment thread src/lib/init/wizard-runner.ts
@betegon betegon merged commit 9b70860 into main Apr 17, 2026
27 checks passed
@betegon betegon deleted the fix/init-tty-stdin-hardening branch April 17, 2026 16:43
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