Skip to content

fix(prompt): fail fast when stdin is not a terminal - #280

Open
stantheman0128 wants to merge 1 commit into
zeabur:mainfrom
stantheman0128:fix/278-non-tty-prompt
Open

stantheman0128 wants to merge 1 commit into
zeabur:mainfrom
stantheman0128:fix/278-non-tty-prompt

Conversation

@stantheman0128

@stantheman0128 stantheman0128 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Description (required)

Every interactive prompt goes through pkg/prompt, which calls survey. When stdin is an open pipe that never sends input (CI step, agent shell, cron), survey draws the selector and blocks forever. On Windows it fails with the raw Incorrect function. instead.

This adds a stdin terminal check before each prompter method. Without a terminal it returns prompt.ErrNonInteractive:

ERROR	cannot prompt "Select a service": stdin is not a terminal; pass the required flags (see --help) or use -i=false

Selectors that auto-pick the only project or service never reach the prompter, so scripts that rely on that keep working. Piping answers into a prompt (printf 'y\n' | zeabur ...) already failed with EOF on main, so nothing that used to work is refused now.

I kept #279 out of this PR. It is a separate code path: on current main deployment log --deployment-id does not show the service prompt, but runtime logs then fail with serviceID is required for runtime logs because the command never looks up the deployment's service. I have a small fix for that and can open it separately.

Testing:

  • New pkg/prompt/prompter_test.go swaps stdin for an open pipe. Before the fix, Select and MultiSelect hit the 3s timeout on Linux (WSL Ubuntu 24.04) and returned Incorrect function. on Windows. After the fix all six methods return ErrNonInteractive on both.
  • Built Linux binaries of main and this branch, ran context clear and template get with stdin on an open FIFO and a dummy token: main hung until timeout (exit 124), this branch exits 1 right away with the message above.
  • go test ./..., go build, golangci-lint run ./... (0 issues), gofumpt clean. I don't have make on this machine, so I ran the commands the Makefile wraps.

Written with help from Cursor (AI). I reviewed the change and ran the tests above.

Related issues & labels (optional)


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

survey renders the selector and then blocks reading stdin. When stdin is an
open pipe (CI steps, agent shells, cron) the process hangs forever at
"Select project" or "Select a service" with no error. On Windows it fails
with the raw "Incorrect function." instead.

Check that stdin is a terminal before every prompt and return
ErrNonInteractive with the prompt text and a hint to pass flags or use
-i=false. Selectors that auto-pick a single option never reach the
prompter, so they keep working in scripts.

Closes zeabur#278

Co-authored-by: Cursor <cursoragent@cursor.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.

Interactive selection prompts hang forever in non-TTY contexts instead of erroring

1 participant