fix: handle asyncio/selector failures in interactive prompt gracefully#1579
Conversation
Greptile code reviewThis repo uses Greptile for automated review. Before merge, aim for Confidence Score: 5/5 with zero unresolved review threads — see CONTRIBUTING.md. Run a review — add a PR comment with: Give it ~30–60 seconds (sometimes longer) for results, then fix feedback and re-trigger until you reach Confidence Score: 5/5. Optional: automate with the greploop skill. |
Greptile SummaryThis PR adds a targeted exception handler to
Confidence Score: 5/5Safe to merge — the change is a narrow, well-targeted exception handler at the exact failure site with no impact on the normal code path. The handler catches only two specific exception types (OSError, KeyError) that correspond to confirmed crash cases, logs the full traceback at debug level, and exits via sys.exit(1) which propagates cleanly through the existing main() handler. The normal execution path is entirely unaffected. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["_patched_ask() called"] --> B["unsafe_ask()"]
B -->|"clean result"| C["reset _last_ctrl_c\nreturn result"]
B -->|"KeyboardInterrupt"| D{"_HardQuitInterrupt?"}
D -->|"yes"| E["re-raise (Ctrl+Q hard quit)"]
D -->|"no"| F{"second Ctrl+C\nwithin 2s?"}
F -->|"yes"| G["print Goodbye\nsys.exit(0)"]
F -->|"no"| H["print hint\nloop back"]
B -->|"OSError / KeyError"| I["log at DEBUG\nwith exc_info"]
I --> J["print platform I/O\nerror message"]
J --> K["sys.exit(1) → SystemExit\ncaught by main()"]
Reviews (2): Last reviewed commit: "PR fixes" | Re-trigger Greptile |
|
@greptileai review |
|
🛸 Aliens watching our repo just upgraded @Dhaxor's threat level to: do not engage — too competent. 👽 👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome. |
Pulls in Tracer-Cloud#1576 (E402/ARG001 noqa cleanup) and Tracer-Cloud#1579 (asyncio/selector failure handling). Conflict resolved in app/main.py: kept upstream's refactor that defers load_dotenv + module imports into main() to drop the E402 noqas, and reapplied this branch's `init_sentry(entrypoint= "cli")` on top.
Tracer-Cloud#1579) * fix: handle asyncio/selector failures in interactive prompt gracefully * PR fixes

Fixes #1569
Describe the changes you have made in this PR -
app/cli/support/prompt_support.py: In _patched_ask(), added except (OSError, KeyError, RuntimeError) to catch asyncio/selector failures when prompt_toolkit registers stdin (fd 0) in the event loop. Prints a clear message and calls sys.exit(1) so the process exits cleanly instead of crashing with a cryptic tracebackDemo/Screenshot for feature changes and bug fixes -
Before (crash):
After (clean exit):
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
Checklist before requesting a review
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.