Skip to content

The agent that grows with you

fix(lsp): document that wait_timeout bounds both waits; tighten the salvaged tests

teknium10bd59ba134e8
diff --git a/agent/lsp/manager.py b/agent/lsp/manager.py
index 7e9e543c927..fb51c5202ea 100644
--- a/agent/lsp/manager.py
+++ b/agent/lsp/manager.py
@@ -202,11 +202,8 @@ class LSPService:
if not self.enabled_for(file_path):
return
try:
- # 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.
+ # Outer join budget must exceed the inner wait or a slow-but-alive server gets falsely
+ # marked broken; it is a ceiling only — the inner wait returns as soon as it completes.
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
@@ -336,7 +333,7 @@ class LSPService:
"""Open + wait for FRESH diagnostics: ``[]`` = checked clean, ``None`` = no verdict in budget.
Callers must not substitute stale data for either. ``snapshot`` mode
- (pre-write baseline) skips didSave and uses the default wait budget.
+ (pre-write baseline) skips didSave; both modes wait at most ``lsp.wait_timeout``.
"""
client = await self._get_or_spawn(file_path)
if client is None:
diff --git a/tests/agent/lsp/test_service.py b/tests/agent/lsp/test_service.py
index baf603a9f7f..cfb46dfb663 100644
--- a/tests/agent/lsp/test_service.py
+++ b/tests/agent/lsp/test_service.py
@@ -146,14 +146,10 @@ def test_snapshot_baseline_honors_wait_timeout(mock_pyright_silent):
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.
+def test_snapshot_baseline_honors_wait_timeout_above_default(mock_pyright_silent):
+ """A ``wait_timeout`` above the 5s client default must also reach the
+ baseline wait (it was silently truncated to 5s), and the outer join
+ budget must scale with it so the slow-but-alive server is not marked broken.
"""
repo = mock_pyright_silent
f = repo / "x.py"
@@ -162,7 +158,7 @@ def test_snapshot_baseline_scales_join_budget_past_8s(mock_pyright_silent):
svc = LSPService(
enabled=True,
wait_mode="document",
- wait_timeout=10.0,
+ wait_timeout=7.0,
install_strategy="manual",
)
try:
@@ -170,8 +166,8 @@ def test_snapshot_baseline_scales_join_budget_past_8s(mock_pyright_silent):
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"
+ assert elapsed >= 6.5, f"baseline truncated to the 5s client default: {elapsed:.2f}s"
+ assert elapsed < 9.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:
diff --git a/website/docs/user-guide/features/lsp.md b/website/docs/user-guide/features/lsp.md
index c34ac0e9c01..b4a05fba0c6 100644
--- a/website/docs/user-guide/features/lsp.md
+++ b/website/docs/user-guide/features/lsp.md
@@ -151,8 +151,9 @@ lsp:
# How long to wait for diagnostics after each write.
wait_mode: document # "document" or "full"
- # Max seconds to wait for the server to re-check the file after an
- # edit. Only *fresh* diagnostics (produced for the post-edit
+ # Max seconds to wait for the server on each of the two waits an
+ # edit makes: the pre-edit baseline snapshot and the post-edit
+ # re-check. Only *fresh* diagnostics (produced for the post-edit
# content) are ever reported; if the server doesn't finish within
# this budget, the edit reports "no LSP data" rather than stale
# errors from before the edit. Raise this for slow servers on big
@@ -220,7 +221,9 @@ The LSP layer adds a few milliseconds to clean writes when no
diagnostics are emitted. When diagnostics are emitted, the wait
budget is `wait_timeout` seconds — typically the server responds in
tens of milliseconds for pyright/tsserver and a few seconds for
-rust-analyzer mid-indexing.
+rust-analyzer mid-indexing. Each edit waits twice (a pre-edit
+baseline snapshot for the delta, then the post-edit re-check), so a
+server that never answers costs at most `2 × wait_timeout` per edit.
Diagnostics are **freshness-gated**: a result only counts when the
server produced it for the content of the current edit (a