Skip to content

The agent that grows with you

refactor(lsp): inline the one-caller subprocess stream-limit helper into LSPClient (#31417)

kshitijk4poor42a5ae67f4d1
diff --git a/agent/lsp/client.py b/agent/lsp/client.py
index 1ab02a660bf..450ef38bd1d 100644
--- a/agent/lsp/client.py
+++ b/agent/lsp/client.py
@@ -19,7 +19,6 @@ from pathlib import Path
from typing import Any, Awaitable, Callable, Dict, List, Optional, Set
from urllib.parse import quote, unquote
-from agent.subprocess_utils import create_subprocess
from hermes_cli._subprocess_compat import windows_hide_flags
from agent.lsp.protocol import (
@@ -29,6 +28,10 @@ from agent.lsp.protocol import (
logger = logging.getLogger("agent.lsp.client")
+# asyncio's 64 KiB StreamReader default makes readline() raise on one long LSP
+# stderr line (#31417); 16 MiB covers realistic output while staying bounded.
+_STREAM_LIMIT = 16 * 1024 * 1024
+
# Timeouts (seconds).
INITIALIZE_TIMEOUT = 45.0
DIAGNOSTICS_DOCUMENT_WAIT = 5.0
@@ -253,8 +256,8 @@ class LSPClient:
# the gateway's pgid and mcp_tool's orphan sweeper can killpg() the TUI parent with it.
# windows_hide_flags() suppresses the console window a .cmd shim would flash from a
# console-less host (CREATE_NO_WINDOW; 0 on POSIX).
- self._proc = await create_subprocess(
- cmd[0], *cmd[1:],
+ self._proc = await asyncio.create_subprocess_exec(
+ cmd[0], *cmd[1:], limit=_STREAM_LIMIT,
stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
env=delegated_child_subprocess_env({**os.environ, **(self._env or {})}), cwd=self._cwd,
start_new_session=True, creationflags=windows_hide_flags(),
diff --git a/agent/subprocess_utils.py b/agent/subprocess_utils.py
deleted file mode 100644
index dfef78d9034..00000000000
--- a/agent/subprocess_utils.py
+++ /dev/null
@@ -1,23 +0,0 @@
-"""asyncio subprocess helper with a larger default StreamReader limit."""
-
-from __future__ import annotations
-
-import asyncio
-from typing import Any
-
-
-# asyncio's default is 64 KiB, tuned for network protocols. Local subprocess
-# output (LSP diagnostics, base64 blobs, quoted source files) can easily exceed
-# that on a single line, causing readline() to raise LimitOverrunError and
-# deadlocking the pipe. 16 MiB covers realistic agent workloads while bounding
-# unbounded growth.
-SUBPROCESS_STREAM_LIMIT = 16 * 1024 * 1024 # 16 MiB
-
-
-async def create_subprocess(
- *args: str,
- stream_limit: int = SUBPROCESS_STREAM_LIMIT,
- **kwargs: Any,
-) -> asyncio.subprocess.Process:
- """asyncio.create_subprocess_exec with a larger default StreamReader limit."""
- return await asyncio.create_subprocess_exec(*args, limit=stream_limit, **kwargs)