mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-10 01:18:29 +00:00
The code execution tool runs commands inside TTY-backed shells (local PTY and remote SSH). Commands like `git diff`/`git log` detect the TTY and pipe output through a pager (more/less). These shells never receive interactive input, so the pager blocks forever and spins at 100% CPU per process — on a 16-core host 5 pager processes pegged 5 cores for 8+ hours (#1697). Disable pagers in both session types: - LocalInteractiveSession: inject PAGER=cat / GIT_PAGER=cat into the TTY env - SSHInteractiveSession: export the same in the initial shell command `cat` streams the output through instead of blocking, and also covers other pager-using tools (man, systemctl, journalctl). Adds regression tests. Fixes #1697
32 lines
1 KiB
Python
32 lines
1 KiB
Python
"""Regression tests for issue #1697.
|
|
|
|
Pagers (more/less) must be disabled in the non-interactive shells created by the
|
|
code execution tool: without user input they block forever and spin at 100% CPU.
|
|
"""
|
|
|
|
from plugins._code_execution.helpers import shell_local, shell_ssh
|
|
|
|
|
|
def test_local_env_disables_pagers_and_preserves_existing():
|
|
env = shell_local.disable_pagers_in_env({"PATH": "/usr/bin", "PAGER": "less"})
|
|
assert env["PAGER"] == "cat"
|
|
assert env["GIT_PAGER"] == "cat"
|
|
# pre-existing keys are preserved
|
|
assert env["PATH"] == "/usr/bin"
|
|
|
|
|
|
def test_local_env_defaults_to_environ():
|
|
env = shell_local.disable_pagers_in_env()
|
|
assert env["PAGER"] == "cat"
|
|
assert env["GIT_PAGER"] == "cat"
|
|
|
|
|
|
def test_local_env_does_not_mutate_input():
|
|
src = {"PATH": "/usr/bin"}
|
|
shell_local.disable_pagers_in_env(src)
|
|
assert src == {"PATH": "/usr/bin"}
|
|
|
|
|
|
def test_ssh_command_disables_pagers():
|
|
assert "GIT_PAGER=cat" in shell_ssh.PAGER_DISABLE_COMMAND
|
|
assert "PAGER=cat" in shell_ssh.PAGER_DISABLE_COMMAND
|