Skip to content

The agent that grows with you

fix(lsp): honor lsp.wait_timeout in baseline snapshot

Christopher631baa40c21b
diff --git a/agent/lsp/manager.py b/agent/lsp/manager.py
index 60021afab8c..7e9e543c927 100644
--- a/agent/lsp/manager.py
+++ b/agent/lsp/manager.py
@@ -202,8 +202,12 @@ class LSPService:
if not self.enabled_for(file_path):
return
try:
- # Outer budget must exceed the inner wait or a slow-but-alive server gets falsely marked broken.
- t = max(8.0, self._wait_timeout + 3.0)
+ # Outer join budget must exceed the inner wait budget or a
+ # slow-but-alive server gets falsely marked broken. The
+ # floor keeps the default behavior (8s with default config)
+ # while letting larger user-configured wait_timeout values
+ # scale the join budget instead of capping it at 8s.
+ t = max(DIAGNOSTICS_DOCUMENT_WAIT + 3.0, self._wait_timeout + 3.0)
diags = self._loop.run(self._snapshot_async(file_path), timeout=t)
except Exception as e: # noqa: BLE001
logger.debug("baseline snapshot failed for %s: %s", file_path, e)
@@ -342,7 +346,7 @@ class LSPService:
if not snapshot:
await client.save_file(file_path)
fresh = await client.wait_for_diagnostics(
- file_path, version, mode=self._wait_mode, timeout=None if snapshot else self._wait_timeout,
+ file_path, version, mode=self._wait_mode, timeout=self._wait_timeout,
)
except Exception as e: # noqa: BLE001
if snapshot:
diff --git a/tests/agent/lsp/_mock_lsp_server.py b/tests/agent/lsp/_mock_lsp_server.py
index a12a963204f..5dbd41202bf 100644
--- a/tests/agent/lsp/_mock_lsp_server.py
+++ b/tests/agent/lsp/_mock_lsp_server.py
@@ -141,6 +141,12 @@ def main():
"message": "synthetic error from mock-lsp",
}
]
+ if script == "silent":
+ # Never publishes diagnostics and the pull endpoint is
+ # rejected (below). Models a slow server that only
+ # re-reports after a didChange it never receives — the
+ # baseline snapshot has to wait out its full budget.
+ continue
if script == "stale":
# Ghost scenario: publish an error for the ORIGINAL
# content, then never publish again after edits.
@@ -180,7 +186,7 @@ def main():
continue
if msg.get("method") == "textDocument/diagnostic":
- if script in {"stale", "slow_push", "versionless"}:
+ if script in {"stale", "slow_push", "versionless", "silent"}:
# These scripts model push-only servers so the ghost
# can't be papered over by the pull channel.
write_message(
diff --git a/tests/agent/lsp/test_service.py b/tests/agent/lsp/test_service.py
index ef5ab70adc0..baf603a9f7f 100644
--- a/tests/agent/lsp/test_service.py
+++ b/tests/agent/lsp/test_service.py
@@ -8,6 +8,7 @@ on.
from __future__ import annotations
import asyncio
+import os
import sys
import time
from pathlib import Path
@@ -84,6 +85,99 @@ def mock_pyright(monkeypatch, tmp_path):
pass
+def mock_pyright_silent(monkeypatch, tmp_path):
+ """Install the silent mock as ``pyright`` (never pushes diagnostics).
+
+ The silent server accepts the open but never publishes diagnostics
+ for the pre-edit content and rejects the pull channel, so the
+ baseline snapshot has to wait out its full budget — exactly the
+ slow-server shape from the wait_timeout report.
+ """
+ repo = tmp_path / "repo"
+ repo.mkdir()
+ (repo / ".git").mkdir()
+ (repo / "pyproject.toml").write_text("")
+ monkeypatch.chdir(str(repo))
+ gen = _install_mock_server(monkeypatch, "silent", "pyright")
+ next(gen)
+ yield repo
+ try:
+ next(gen)
+ except StopIteration:
+ pass
+
+
+def test_snapshot_baseline_honors_wait_timeout(mock_pyright_silent):
+ """``snapshot_baseline`` must wait at most ``lsp.wait_timeout``, not
+ the hardcoded client fallback of 5s.
+
+ Regression for the report that a 2s wait_timeout was ignored by the
+ baseline path: the wait ran without a timeout and fell back to
+ ``DIAGNOSTICS_DOCUMENT_WAIT`` (5s). The silent mock never pushes,
+ so the elapsed time directly exposes the effective wait budget.
+ """
+ repo = mock_pyright_silent
+ f = repo / "x.py"
+ f.write_text("print('hi')\n")
+
+ svc = LSPService(
+ enabled=True,
+ wait_mode="document",
+ wait_timeout=2.0,
+ install_strategy="manual",
+ )
+ try:
+ start = time.monotonic()
+ svc.snapshot_baseline(str(f))
+ elapsed = time.monotonic() - start
+
+ # The wait is deadline-based: it always runs the full budget
+ # (never less than wait_timeout) and the server never pushes,
+ # so both bounds are stable under load.
+ assert elapsed >= 1.5, f"baseline returned before the wait budget: {elapsed:.2f}s"
+ assert elapsed < 4.5, (
+ f"baseline ignored wait_timeout=2.0 and ran the 5s fallback: {elapsed:.2f}s"
+ )
+ assert svc.get_status()["broken"] == []
+ # No fresh data pre-edit -> empty (never stale) baseline.
+ assert svc._delta_baseline[os.path.abspath(str(f))] == []
+ finally:
+ svc.shutdown()
+
+
+def test_snapshot_baseline_scales_join_budget_past_8s(mock_pyright_silent):
+ """The outer join budget must scale with ``wait_timeout`` instead of
+ capping at 8s.
+
+ With wait_timeout=10.0 the inner wait takes 10s; an 8s outer cap
+ would fire first, falsely mark the server broken, and truncate the
+ snapshot. The elapsed time must land between the inner budget and
+ the (now scaled) outer budget, with the server still healthy.
+ """
+ repo = mock_pyright_silent
+ f = repo / "x.py"
+ f.write_text("print('hi')\n")
+
+ svc = LSPService(
+ enabled=True,
+ wait_mode="document",
+ wait_timeout=10.0,
+ install_strategy="manual",
+ )
+ try:
+ start = time.monotonic()
+ svc.snapshot_baseline(str(f))
+ elapsed = time.monotonic() - start
+
+ assert elapsed >= 9.5, f"baseline cut short by the outer cap: {elapsed:.2f}s"
+ assert elapsed < 12.5, f"baseline overran the scaled join budget: {elapsed:.2f}s"
+ # A slow-but-alive server must not be marked broken.
+ assert svc.get_status()["broken"] == []
+ finally:
+ svc.shutdown()
+
+