fix(sdk): clean up cancelled local shell commands - #5907
Open
Mason Daugherty (mdrxy) wants to merge 20 commits into
Open
fix(sdk): clean up cancelled local shell commands#5907Mason Daugherty (mdrxy) wants to merge 20 commits into
Mason Daugherty (mdrxy) wants to merge 20 commits into
Conversation
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
Mason Daugherty (mdrxy)
added a commit
that referenced
this pull request
Aug 27, 2026
Fixes #4329 Related: #5907 Local shell commands can no longer access the parent process's controlling terminal on POSIX systems, preventing credential prompts from stealing keyboard input from the dcode TUI. --- The dcode agent routes `execute` through `LocalShellBackend`. Although that backend gives subprocesses `stdin=subprocess.DEVNULL`, programs such as Git and SSH can bypass standard input by opening `/dev/tty` directly. When they prompt for credentials, they then compete with Textual for the same terminal input, disrupting or effectively breaking the chat input until the process exits. Start each local shell command in a new POSIX session so it no longer has access to dcode's controlling terminal. Interactive commands now fail cleanly through captured output rather than intercepting keystrokes. This also aligns the agent `execute` path with dcode's existing local `!` shell behavior. Windows behavior is unchanged because `start_new_session` is enabled only on non-Windows platforms. Focused coverage runs the backend beneath a real controlling pseudo-terminal, proves the parent can open `/dev/tty`, and verifies the detached command cannot. Made by [Open SWE](https://openswe.vercel.app/agents/58b7b723-1498-5094-af76-6ebd4bda4823) Co-authored-by: Sumit Kumar <187615421+sumit1kr@users.noreply.github.com> --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #5873
Local shell commands now clean up their supported process scope on timeout, interruption, and async cancellation so cancelled work does not continue consuming resources in the background.
LocalShellBackendcurrently inherits the protocol's thread-offloadedaexecute, so cancelling its caller cannot stop an already-running synchronous shell command. Detached descendants can also outlive timeout and interruption handling.This changes command execution from
subprocess.runtosubprocess.Popen, starts POSIX commands in an isolated session and process group, and adds cancellation-aware output collection. Cleanup kills and reaps the POSIX process group or the direct Windows shell, closes captured pipes, bounds cleanup waits, and logs failures without replacing the active control-flow exception.The async wrapper preserves
executeoverrides, prevents queued commands from starting after cancellation, retains uncooperative workers until completion, and documents that Windows descendants cannot be terminated as a group. This PR targetsmaindirectly and is independent of the narrower terminal-input fix in #5873.Test plan
uv run --no-sync --group test pytest tests/unit_tests/backends/test_local_shell_backend.py tests/unit_tests/test_local_shell.py -q