Skip to content

The agent that grows with you

fix(lsp): eventlog path shortener survives a removed process cwd

teknium16b3005c4c8b8
diff --git a/agent/lsp/eventlog.py b/agent/lsp/eventlog.py
index 7b374063cc1..0a8d3b19318 100644
--- a/agent/lsp/eventlog.py
+++ b/agent/lsp/eventlog.py
@@ -32,7 +32,9 @@ def _short_path(file_path: str) -> str:
return file_path
try:
rel = os.path.relpath(file_path)
- except ValueError:
+ except (ValueError, OSError):
+ # Different drive (ValueError) or the process cwd was removed (OSError from getcwd):
+ # a log-line shortener must never turn a delivered diagnostic into a swallowed error.
return file_path
return file_path if rel.startswith(".." + os.sep) or rel == ".." else rel
diff --git a/tests/agent/lsp/test_workspace.py b/tests/agent/lsp/test_workspace.py
index ce05320b2bf..252a2903fae 100644
--- a/tests/agent/lsp/test_workspace.py
+++ b/tests/agent/lsp/test_workspace.py
@@ -85,6 +85,11 @@ def test_resolve_workspace_for_file_survives_deleted_cwd(tmp_path: Path, monkeyp
assert root == str(repo)
assert gated is True
+ # The diagnostics path logs through eventlog; its cwd-relative shortener must
+ # not raise either, or the write succeeds with diagnostics silently dropped.
+ from agent.lsp.eventlog import _short_path
+
+ assert _short_path(str(file_path)) == str(file_path)
def test_normalize_path_expands_tilde(monkeypatch):