Add TTY detection for interactive prompts to prevent agent hangs#1547
Add TTY detection for interactive prompts to prevent agent hangs#1547garrytrinder merged 5 commits intomainfrom
Conversation
- CertCommand: detect non-interactive stdin before prompting, fail with clear error directing users to --force flag - ProxyEngine: skip first-run cert trust prompt in non-interactive mode, default to trusting the certificate - Update --force option help text to note it's required for non-interactive use Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent Dev Proxy CLI commands from hanging indefinitely in non-interactive environments (CI, piped stdin, automation/agents) by adding stdin/TTY detection around interactive prompts.
Changes:
- Add
Console.IsInputRedirectedchecks to avoidConsole.ReadLine()prompts in non-interactive mode. - Update
cert remove’s--forcehelp text to clarify non-interactive requirements. - Default first-run macOS certificate trust prompt to “yes” when stdin is redirected, and log that decision.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| DevProxy/Proxy/ProxyEngine.cs | Avoids first-run certificate trust prompt when stdin is redirected by auto-selecting the default choice. |
| DevProxy/Commands/CertCommand.cs | Prevents cert remove from prompting in non-interactive mode unless --force is set; updates --force help text. |
…t code - CertCommand and ProxyEngine: check both Console.IsInputRedirected and CI env var for non-interactive detection, matching ExecuteAsync pattern - RemoveCert returns int: exit code 1 for non-interactive failure or exceptions, 0 for success Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
garrytrinder
left a comment
There was a problem hiding this comment.
Tested: non-interactive detection works correctly via piped stdin and CI env var. cert remove fails immediately with exit code 1 and actionable message. --force bypasses prompt. ProxyEngine first-run guard consistent. No hangs observed.
cert removeand first-run setup useConsole.ReadLine()which hangs indefinitely in non-interactive contexts (CI, piped stdin, AI agents). The--forceflag exists but nothing prevents the prompt from blocking.Changes
CertCommand.cs: CheckConsole.IsInputRedirectedandCIenv var before prompting. If non-interactive and--forcenot set, fail immediately with exit code 1 and actionable error:CertCommand.cs:RemoveCertnow returnsintexit code (1 for non-interactive failure or exceptions, 0 for success) so System.CommandLine propagates failure correctly.ProxyEngine.cs: Skip first-run cert trust prompt when stdin is redirected orCIenv var is set; default to trusting (matches the Y/n default). Logs the decision.--forcehelp text: Updated to note it's required for non-interactive use.Non-interactive detection consistently uses both
Console.IsInputRedirectedand theCIenvironment variable, matching the existing pattern inProxyEngine.ExecuteAsyncto handle CI environments that provide a pseudo-TTY.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.