-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
agentscope.tool.execute_shell_command can deadlock when the child process writes more to stdout/stderr than the OS pipe buffer (often ~64KB). The parent waits for the process to exit with proc.wait() while not reading the pipes; the child blocks on writing once the buffer is full. Neither side progresses.
To Reproduce
- Code (async):
import asyncio
from agentscope.tool import execute_shell_command
async def main():
# GitHub releases API returns a large JSON (often >64KB)
resp = await execute_shell_command(
command='curl -s -H "Accept: application/vnd.github+json" '
'"https://api.github.com/repos/agentscope-ai/agentscope/releases"',
timeout=60,
)
print(resp)
asyncio.run(main())-
Run:
python repro.py -
Observe: The script hangs and never prints. The same
curlcommand runs to completion in a normal terminal.
Expected behavior
The tool should return with <returncode>0</returncode>, <stdout>...</stdout> containing the API response, and no hang.
Error messages
There is no exception or error message; the call simply blocks indefinitely (until timeout, if any).
Environment
- AgentScope Version: 1.0.13
- Python Version: 3.12
- OS: macOS (darwin)
Additional context
Root cause: In _shell.py, the implementation does:
await asyncio.wait_for(proc.wait(), timeout=timeout)
stdout, stderr = await proc.communicate()Waiting for the process with proc.wait() without reading stdout/stderr allows the pipe buffers to fill. Once they are full, the child blocks on write() and never exits, so proc.wait() never returns → deadlock.