Repository navigation
Description
Five tests in tests/pynix/test_lsp_e2e.py timed out in one CI job, and the
same job passed on a re-run of the same commit with the same inputs. The
non-determinism is demonstrated, not suspected, so it is recorded here rather
than dismissed.
Evidence
Run 30712707907,
job test-local-git, commit 17a26249:
FAILED tests/pynix/test_lsp_e2e.py::test_e2e_bare_attrpath_completion_falls_back_to_the_options_tree - TimeoutError
FAILED tests/pynix/test_lsp_e2e.py::test_e2e_pkgs_completion_lists_real_nixpkgs_attributes - TimeoutError
FAILED tests/pynix/test_lsp_e2e.py::test_e2e_hover_shows_the_declared_option - TimeoutError
FAILED tests/pynix/test_lsp_e2e.py::test_e2e_go_to_definition_on_a_nixos_option_reference_lands_on_its_declaration - TimeoutError
FAILED tests/pynix/test_lsp_e2e.py::test_e2e_renaming_a_let_binding_updates_every_reference_over_real_stdio - TimeoutError
ERROR tests/pynix/test_lsp_e2e.py::test_e2e_renaming_a_let_binding_updates_every_reference_over_real_stdio - RuntimeError: JsonRpcException: CANCELLED
= 5 failed, 1887 passed, 7 skipped, 1888 warnings, 1 error in 1021.17s (0:17:01) =
A re-run of the failed job, at the same commit, passed. That is the proof
of non-determinism: identical tree, identical lock, one red and one green.
What the shape of the failure says
The five failures are two minutes apart to the second — 18:41:02, 18:43:02,
18:45:02, 18:47:02, 18:49:03 — so each one waited out the same 120s deadline
rather than failing on its own account:
asyncio.exceptions.CancelledError: Cancelled via cancel scope ...; reason: deadline exceeded
All five request the session-scoped _shared_pynix_sessions fixture
(tests/pynix/conftest.py:396), which shares one Nix session, store and
evaluator across the pynix commands. The teardown error is pygls setting a
result on an already-cancelled future:
concurrent.futures._base.InvalidStateError: CANCELLED: <Future ... state=cancelled>
pygls/protocol/json_rpc.py:509 in handle_message
pytest_lsp/protocol.py:53 in _handle_notification
That reads as one stall poisoning the shared session, and the remaining four
tests each paying the full deadline behind it — not five independent failures.
So the thing to find is what made the first request never answer.
Why this matters beyond one red run
Five tests each burning 120s adds ten minutes to a job that otherwise takes
about seven. The failure is also indistinguishable, from the terminal output
alone, from a real regression in the LSP server — which is exactly the shape
that trains people to re-run CI instead of reading it.
Not yet known
- Whether it is specific to
test-local-git, or whether 8000 that job is simply the
one that lost the race this time. It was green on the previous sixdevelop
runs, so there is no pattern to point at yet. - Whether the stall is in the LSP server process, in the shared evaluator, or
in the stdio transport between them. - Whether a deadline that is generous enough to be safe would also be long
enough to be useless as a signal.
Suggested first step
Make the failure legible before making it rare. The deadline currently reports
TimeoutError and nothing about what the server was doing, so the next
occurrence produces the same six lines and no more. Capturing the server-side
state at the deadline — the pending request, and whether the evaluator thread
is alive — would turn the next red run into evidence instead of another
re-run.
Activity
Lillecarl commentedon Aug 2, 2026
Step one done: the next occurrence will carry evidence. The flake is not fixed.
This does the "suggested first step" and nothing beyond it. The stall is still
unexplained, and this issue stays open until it is.
What changed
tests/conftest.pywraps every async test inanyio.fail_after. That wrappernow catches the
TimeoutErrorand attaches a note before re-raising, so thefailure carries the state of the process at the deadline instead of one word.
The note is built by
tests/support/hang_report.pyand has two halves:evaluator thread alive" question this issue asks.
The current task is deliberately skipped.
fail_afterhas already unwound itby then, and pytest's own traceback already shows where it was. What the
traceback cannot show is the task a module-scoped or session-scoped fixture
owns, which sits outside the cancel scope and is still parked exactly where it
stalled. That is precisely the shape described here:
_shared_pynix_sessionsstalls, and the four tests behind it each pay the full 120s.
One thing worth knowing for anything else that reads task state
asyncio.Task.get_stack()is not enough, and using it would have produced aconfident-looking and useless report. A suspended coroutine's frame has no
f_back, so that method returns the task's outermost frame and stops. Fora task started by a task group, that frame is anyio's own runner and contains
no line of the caller's code. Measured on a deliberately parked task:
The awaited coroutines hang off
cr_await, so the report walks that chainitself. The same task then reads:
Two flaws the tests caught, both from real output
NANOPYNIX_TEST_TIMEOUT=0.4reported "the 0s deadline". A shortdeadline is exactly what someone reproducing a hang sets, and a report that
misstates it reads as a broken report.
frames were
hang_report.pybuilding the report. It now filters its own.Where the tests live
tests/harness/, which is new, with a rule added totests/AGENTS.md. Thishelper has a property most of
tests/support/does not: no other test failswhen it breaks. It runs only when a test is already failing, so a version that
returned an empty string would keep every run green while being useless at the
one moment it matters. The rule is: if a bug in the helper makes some other
test fail, write no test; if it just stops helping, it needs its own.
Verified red-before-green -- with the
add_notecall removed, the end-to-endtest fails. That test drives the real
_with_test_timeoutrather thanrebuilding its shape, so it also fails if the wrapper stops attaching the note.
Still open
test-local-gitis special or just lost the race.test(harness): say what the process was doing when a test hit its dea…
perf(ci): give the ASAN job the tests that ASAN can report on
perf(ci): give the ASAN job the tests that ASAN can report on
test(harness): let the in-process LSP driver wait for the warm-up
Lillecarl commentedon Aug 12, 2026
A second instance, with a root cause -- and it is not the one this issue records
1265fc97fixes a race with the same symptom as this issue, in a differentdriver. This issue stays open: it records
tests/pynix/test_lsp_e2e.pyover a real client, and the fix below touches only the in-process driver.
The mechanism
pynix/src/pynix/_lsp/_handlers.py:294starts_warm_module_argsas abackground task and returns without awaiting it. That is deliberate, and the
docstring above it gives the reason: a real editor cannot wait for the module
arguments of a file to resolve.
tests/support/lsp_drivers.py'sInProcessDrivercalls_sync_documentdirectly, so
openreturned while the warm-up still ran. A hover on a moduleargument then answered
None.WireDriverwas never affected, because aJSON-RPC round trip usually outlasts the warm-up.
That explains a detail this issue could not: only the
[in_process-...]parametrisation failed.
The evidence
Run 31618055409,
on
develop. Two jobs failed on the same easykubenix hovers, in two differentways, while 14 jobs that ran the same tests passed:
test-nogc-gittest-local-nix_2_31AssertionError: expected a hover result, got NoneA re-run of both, at the same commit, separated them:
test-nogc-gittest-local-nix_2_31test-local-nix_2_31loses this race reliably because it is the slowest job ofthe matrix: 12m22s against 7m39s for
test-local-git(see #161).After the fix
Two dispatched runs of
test-local-nix_2_31onci-develop, both green:31625283471
and 31626487823.
Two failures before, two successes after.
What is not fixed
The
Nonemode is gone from the in-process driver. The timeout mode over areal client is untouched, and that is what this issue is about: a stall in the
shared session that no amount of waiting in a test driver explains. The
hang_reportwork from the comment above still stands as the way the nextoccurrence gets read.
The regression test is
tests/harness/test_lsp_driver_settle.py. It livesthere because no other test reports when the wait goes away -- the scenarios
pass on a development machine, where the warm-up wins the race every time. I
could not reproduce the CI failure locally on Nix 2.31 either with or without
the fix.
Lillecarl commentedon Aug 16, 2026
The macOS job reproduces this every run, which turns the non-determinism of
this issue into something that can be measured. I filed #188 for it before
finding this one; that is a duplicate and I have closed it. Everything it
learned is below.
It is the same defect
Run 31955684530,
test-darwin-nix_2_34: the same five tests, the same 120-second deadline, thesame two-minute spacing, and the same teardown:
That
set_resulton a cancelled future is the notification arriving afterthe deadline cancelled the waiter. So this is slowness, not a deadlock. The
answer does come.
What it is not
The same server, spawned by hand over real stdio and driven with the same three
messages, answers the same
didOpenfor the same file in 1.0 s on macOS26.5.1 arm64. Each of these was tried, and none changed that number:
client_capabilities("visual-studio-code")the fixture sends,rather than an empty capability set;
initializewith and withoutrootUri;NIX_CONFIGthat_configure_worker_local_storesexports;It is not one test poisoning another either: it fails the same way when it is
the only test of the run.
So the difference is the process pytest runs in, and not the protocol, the
capabilities, the environment or the order. That matches the shape here: a
shared session-scoped fixture, and a server that is slow to answer rather than
stuck.
What was done meanwhile
The five behavioural tests moved to
pynix/tests/test_lsp_protocol.py, on thelsp_wirefixture: the samepytest_lsp.LanguageClient, the samecapabilities, the same JSON-RPC framing and serialization, both halves in one
process, and a live reference to the server.
The same five assertions run in 3.4 s there, against 10 minutes of deadlines
over stdio. Coverage went up rather than down: two of the five already ran at
the wire tier through
test_lsp_scenarios.py, and the other three ranin-process only.
test_lsp_e2e.pykeeps the two tests that need a real process, and its fixturenow reports the stderr of the server on a failure -- it collected nothing
before, which is why the list above took six experiments by hand.
What is left for this issue
A document round trip against a spawned
pynix lspis now tested nowhere, andthat gap belongs here. The round trip is the defect, so a test of it today
asserts the defect rather than the behaviour.
test_lsp_e2e.pyits round-trip test back, ungated.docs(tests): point the LSP notes at #44, the issue that already had it
test(hang-report): say what the kernel is waiting for at a deadline
test(hang-report): say what the kernel is waiting for at a deadline
test(harness): say what the process was doing when a test hit its dea…
perf(ci): give the ASAN job the tests that ASAN can report on
test(harness): let the in-process LSP driver wait for the warm-up
docs(tests): point the LSP notes at #44, the issue that already had it
test(hang-report): say what the kernel is waiting for at a deadline
pynixd: an execute pass under its target returns before weighing