fix: detect sudo password prompt and exit cleanly instead of hanging#1729
fix: detect sudo password prompt and exit cleanly instead of hanging#1729octo-patch wants to merge 1 commit intoopeninterpreter:mainfrom
Conversation
|
It doesn't actually block, you can type the password and it runs. I usually just press enter so it says incorrect password and then type the correct password so I know it's going into the right place. Definitely should be handled better though |
|
Thanks for the context! You're right that you can type the password and it will work — the blocking behavior just means there's no visible prompt to indicate what's happening, which can confuse users who don't realize sudo is waiting. This PR aims to make that situation explicit (detect and exit cleanly with a clear message) so the user knows to either run their command without sudo or set up passwordless sudo. Happy to revisit the approach if you have a different preference for handling this UX issue. |
|
I wonder if there's a way to just show the password prompt? |
|
We could replace sudo with pkexec. This may break if run through ssh? |
|
Actually Cursor was able to fix this in my fork by changing one line: endolith@2e43fec Not sure if that has other side effects or if it only works in my fork vs in the original, though. see also #1694 |
Fixes #1694
Problem
When the LLM generates a
sudocommand (e.g.,sudo journalctl -xe), the subprocess usessubprocess.PIPEwhich has no terminal for interactive password input. The[sudo] password for <user>:prompt appears on stderr but the process then blocks indefinitely waiting for input that can never arrive through the pipe. OI hangs for ~120 seconds with no output before timing out.Solution
Added a check in
handle_stream_output()insubprocess_language.pyfor the[sudo] password forpattern in the output stream. When detected, OI immediately:doneevent so therun()loop exits without waiting for the execution timeoutThe subprocess remains blocked but gets cleaned up on the next execution or when OI exits, consistent with how other error cases are handled.
Testing
[sudo] password prompt detected — OI cannot provide a password through a pipe. Please run this command manually in your terminal.Existing
True/Falseauto_run behavior and non-sudo commands are completely unaffected.