From e8bb346eb926c49db3b7e89498f766bcd74df895 Mon Sep 17 00:00:00 2001 From: yiqi-017 <22300246009@m.fudan.edu.cn> Date: Sat, 2 May 2026 17:46:13 +0800 Subject: [PATCH] fix: mark ACP stdout fd as non-inheritable to prevent child process pollution - os.set_inheritable(_stdout_fd, False) on both Windows and Unix - Unix path now uses os.dup() + os.fdopen() consistent with Windows - Prevents subprocess.Popen children from inheriting the ACP JSON-RPC file descriptor, which could corrupt the protocol stream Co-Authored-By: Claude Opus 4.6 --- genericagent_acp_bridge.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/genericagent_acp_bridge.py b/genericagent_acp_bridge.py index 03f8663a..04e7f827 100644 --- a/genericagent_acp_bridge.py +++ b/genericagent_acp_bridge.py @@ -13,11 +13,15 @@ if sys.platform == "win32": msvcrt.setmode(_stdout_fd, os.O_BINARY) _acp_stdout = os.fdopen(_stdout_fd, "wb", buffering=0) msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) + # Mark the ACP fd as non-inheritable so child processes can't write to it. + os.set_inheritable(_stdout_fd, False) # Redirect the original stdout fd to stderr so child processes # (tool calls) don't write into the ACP JSON-RPC channel. os.dup2(sys.stderr.fileno(), sys.__stdout__.fileno()) else: - _acp_stdout = sys.__stdout__.buffer if hasattr(sys.__stdout__, 'buffer') else sys.__stdout__ + _stdout_fd = os.dup(sys.__stdout__.fileno()) + os.set_inheritable(_stdout_fd, False) + _acp_stdout = os.fdopen(_stdout_fd, "wb", buffering=0) os.dup2(sys.stderr.fileno(), sys.__stdout__.fileno())