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

Co-authored-by: leavedrop <1433810735@qq.com>
This commit is contained in:
kshitijk4poor
2026-09-24 16:32:18 +05:30
committed by kshitij
parent d516575df3
commit 42a5ae67f4
2 changed files with 6 additions and 26 deletions

View File

@@ -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(),

View File

@@ -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)