# Design Decision: Fix Subprocess Hang on Interactive Commands **Date:** 2024-02-24 **Scope:** src/tools/executor.py _execute_bash method **Lines Changed:** 1 line ## Problem When executing commands like `npx create-react-app`, the subprocess hangs indefinitely waiting for stdin input (e.g., "Ok to proceed? (y)"). This causes: 1. 300s timeout to be reached 2. opencode to hang waiting for response 3. Poor user experience ## Root Cause `subprocess.run()` by default inherits stdin from parent process. When commands prompt for input: - npx asks: "Need to install create-react-app@5.1.0 Ok to proceed? (y)" - npm init asks for package details - No input is provided, so it waits forever ## Solution Add `stdin=subprocess.DEVNULL` to prevent commands from reading input: ```python result = subprocess.run( command, shell=True, capture_output=True, text=True, timeout=timeout, cwd=cwd, stdin=subprocess.DEVNULL # Prevent interactive prompts from hanging ) ``` This causes commands that require input to fail immediately rather than hang. ## Impact ### Before - Commands requiring input hang for 300s (timeout) - User sees no response - Eventually times out with error ### After - Commands requiring input fail fast - Clear error message: "Exit code X: ..." - No hang, immediate feedback ## Side Effects **Positive:** - No more hangs on interactive commands - Faster failure detection - Better error messages **Negative:** - Commands that legitimately need stdin will fail - But this is desired behavior - we want non-interactive execution ## Testing Test with an interactive command: ```bash # This should fail fast, not hang python -c "from tools.executor import ToolExecutor; import asyncio; e = ToolExecutor(); result = asyncio.run(e.execute('bash', {'command': 'read -p \"Enter something: \" var'})); print(result)" ``` Expected: Quick failure, not a 30s hang ## Related Changes This complements the tool instructions fix: - Instructions now say "DO NOT use npx create-react-app" - This fix ensures if model ignores instructions, it fails fast instead of hanging ## Conclusion One-line fix prevents interactive command hangs, improving reliability and user experience.