Repository navigation
Fix system.run hanging indefinitely for IPC-connected CLI tools (regression after v0.4.3) - #29
Closed
shanselman with Copilot wants to merge 2 commits into
Closed
shanselman with Copilot wants to merge 2 commits into
shanselman with Copilot wants to merge 2 commits into
Conversation
Co-authored-by: shanselman <[email protected]>
Copilot
AI
changed the title
[WIP] Fix system.run hanging issue for CLI tools
Fix system.run hanging indefinitely for IPC-connected CLI tools (regression after v0.4.3)
Feb 26, 2026
shanselman
marked this pull request as ready for review
March 4, 2026 18:07
36 tasks
shanselman
added a commit
that referenced
this pull request
Mar 17, 2026
Address review findings from PRs #29 and #32: - QuoteArgIfNeeded: check all shell metacharacters (& | ; < > etc.), not just whitespace/quotes — prevents command injection - cmd.exe: use doubled-quote escaping (%"%") instead of backslash which cmd doesn't recognize - FormatExecCommand: align metacharacter checks with QuoteArgIfNeeded so system.run.prepare shows the same command that actually executes - StringBuilder: add lock around stdout/stderr event handlers and ToString() reads to prevent concurrent-access corruption Co-authored-by: danedane <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Copilot <[email protected]>
Collaborator
|
Hey @copilot-swe-agent — thank you for the solid fix here! The \Exited\ event approach is exactly right for avoiding the \WaitForExitAsync\ EOF hang. This work has been cherry-picked into #38, which also includes the argv quoting improvements from #32. As part of review, we added \lock\ synchronization around the \StringBuilder\ stdout/stderr handlers to address a thread-safety issue with the concurrent event callbacks. Thanks again — and thanks to @milosm for the excellent bug report in #28! 🙏 |
Collaborator
|
Closing — this fix has been cherry-picked into #38 (now merged) along with additional hardening (StringBuilder thread safety). Thank you @copilot-swe-agent for the fix and @milosm for reporting #28! 🙏 |
This was referenced Jun 26, 2026
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.
system.runhangs forever when invoking CLI tools that connect to a running process via local IPC (e.g.Obsidian.com version,docker version). Commands that completed in ~400ms on v0.4.3 never return on v0.4.5+.Root cause
WaitForExitAsync()in .NET 6+ internally callsWaitForExit()after the process exits, which blocks until async stream reads (BeginOutputReadLine) reach EOF. When an IPC CLI spawns child processes during its socket/pipe handshake, those children inherit the stdout pipe write handle. After the CLI exits, the pipe stays open — EOF never arrives — andWaitForExitAsync()hangs indefinitely.Fix
LocalCommandRunner.cs— swapWaitForExitAsyncfor theExitedevent:After the process exits, remaining buffered output is drained by running
WaitForExit()on a background thread, bounded byOutputDrainTimeoutMs = 500. If orphaned children are still holding the write handle, we log a warning and proceed with whatever output was already received — no indefinite hang.SystemRunTests.cs— adds a WindowsIntegrationFact(Run_CompletesPromptly_WhenOrphanChildProcessHoldsStdoutHandle) that starts a background child process inheriting the pipe handle and asserts the command completes in under 3 s.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.