fix(tools): stop unsandboxed shell hang after output cap - #69
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
When sandbox is off (the default), filling the result buffer exited the drain loop and then blocked forever in waitpid. Commands that emit a burst then sleep froze the agent. Truncated copies also skipped the NUL terminator, so later strlen/cJSON reads ran off the heap. Reap leftover children like sandbox_exec, kill the process group, and always NUL-terminate the capture buffer. Co-authored-by: esadrianno <[email protected]>
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.
Summary
Unsandboxed
shell(sandbox off by default) hung the whole agent after a command filled the output cap.run_unsandboxedleft the drain loop whentotal >= max_len - 1, then called blockingwaitpid. A command that prints a burst and then sleeps (or otherwise stays alive without writing) never closes the pipe, so the main loop, WebChat, and inbound ASAPagent_runfreeze until restart.The same fill path copied
add + 1bytes and skipped a NUL terminator, so laterstrlen/cJSON_CreateStringcould read pasttool_result_bufs.Fix
WNOHANG+ SIGKILL, same idea assandbox_exec.sleep/grandchild processes die with the shell.Trigger
Sandbox disabled (default). Tool call:
{"command":"printf '%080d' 0; sleep 9999"}With a 64-byte result buffer this used to hang until SIGALRM in the new unit test; it now returns in well under a second.
Test plan
tests/test_shell—test_shell_caps_output_without_hanging(5s alarm watchdog, NUL check)CI=true make test_shell(-Werror)tests/test_sandboxstill passes