fix: resolve BashTool hanging on background commands #1254
+1,046
−4
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.
BashTool hung indefinitely on background commands (
sleep 5 &
,node server.js &
) due to file descriptor inheritance.await process.exited
blocked because background processes inherited stdout/stderr pipes from the parent bash shell.Bun.spawn()
creates bash withstdout: "pipe", stderr: "pipe"
command &
and exitsprocess.exited
waits for all descriptors to closeAdded background command detection with selective I/O redirection:
Background detection handles:
sleep 5 &
(cmd1; cmd2) &
,nohup cmd &
,cmd & disown
Now:
isBackgroundCommand
function is 83 lines long and tries to handle a lot of cases. This might be a bit much for an issue that doesn't seem to occur for a lot of developers (haven't seen an open issue about this). At the same time, this PR might be a segway to fixing other issues with BashTool I/O as well such as #652 (App becomes unresponsive when executing commands requiring sudo password).