Skip to content

fix(tools): stop unsandboxed shell hang after output cap - #69

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-ec0b
Draft

fix(tools): stop unsandboxed shell hang after output cap#69
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-ec0b

Conversation

@cursor

@cursor cursor Bot commented Aug 18, 2026

Copy link
Copy Markdown

Summary

Unsandboxed shell (sandbox off by default) hung the whole agent after a command filled the output cap.

run_unsandboxed left the drain loop when total >= max_len - 1, then called blocking waitpid. 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 ASAP agent_run freeze until restart.

The same fill path copied add + 1 bytes and skipped a NUL terminator, so later strlen / cJSON_CreateString could read past tool_result_bufs.

Fix

  • Reap leftover children with WNOHANG + SIGKILL, same idea as sandbox_exec.
  • Put the command in its own process group so sleep/grandchild processes die with the shell.
  • Always NUL-terminate the capture buffer.

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_shelltest_shell_caps_output_without_hanging (5s alarm watchdog, NUL check)
  • CI=true make test_shell (-Werror)
  • tests/test_sandbox still passes
Open in Web View Automation 

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]>
@cursor
cursor Bot requested a review from adriannoes August 18, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant