FFFF Tests: the LSP e2e tests time out non-deterministically in CI · Issue #73 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Tests: the LSP e2e tests time out non-deterministically in CI #73

Open

Description

@Lillecarl

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 that job is simply the
    one that lost the race this time. It was green on the previous six develop
    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

  1. Lillecarl commented on Aug 2, 2026

    @Lillecarl
    ContributorAuthor

    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 10BC8 still
    unexplained, and this issue stays open until it is.

    What changed

    tests/conftest.py wraps every async test in anyio.fail_after. That wrapper
    now catches the TimeoutError and attaches a note before re-raising, so the
    failure carries the state of the process at the deadline instead of one word.
    The note is built by tests/support/hang_report.py and has two halves:

    • Every task still alive on the loop, with the frames it is parked on.
    • Every thread, with its innermost Python frames -- which is the "is the
      evaluator thread alive" question this issue asks.

    The current task is deliberately skipped. fail_after has already unwound it
    by 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_sessions
    stalls, 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 a
    confident-looking and useless report. A suspended coroutine's frame has no
    f_back, so that method returns the task's outermost frame and stops. For
    a 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:

    - hang_report_parked_here: <coroutine object TaskHandle._run_coro>
        .../anyio/_core/_tasks.py:275 in _run_coro
    

    The awaited coroutines hang off cr_await, so the report walks that chain
    itself. The same task then reads:

    - hang_report_parked_here: <coroutine object TaskHandle._run_coro>
        tests/harness/test_hang_report.py:29 in _parked
        .../anyio/_core/_eventloop.py:107 in sleep_forever
        .../anyio/_core/_eventloop.py:95 in sleep
        .../python3.14/asyncio/tasks.py:704 in sleep
    

    Two flaws the tests caught, both from real output

    • A run with NANOPYNIX_TEST_TIMEOUT=0.4 reported "the 0s deadline". A short
      deadline is exactly what someone reproducing a hang sets, and a report that
      misstates it reads as a broken report.
    • The report runs on the thread that timed out, so that thread's innermost
      frames were hang_report.py building the report. It now filters its own.

    Where the tests live

    tests/harness/, which is new, with a rule added to tests/AGENTS.md. This
    helper has a property most of tests/support/ does not: no other test fails
    when 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_note call removed, the end-to-end
    test fails. That test drives the real _with_test_timeout rather than
    rebuilding its shape, so it also fails if the wrapper stops attaching the note.

    Still open

    • What made the first request never answer.
    • Whether test-local-git is special or just lost the race.
    • Whether the stall is the LSP server, the shared evaluator, or the transport.
  2. Lillecarl commented on Aug 12, 2026

    @Lillecarl
    ContributorAuthor

    A second instance, with a root cause -- and it is not the one this issue records

    1265fc97 fixes a race with the same symptom as this issue, in a different
    driver. This issue stays open: it records tests/pynix/test_lsp_e2e.py
    over a real client, and the fix below touches only the in-process driver.

    The mechanism

    pynix/src/pynix/_lsp/_handlers.py:294 starts _warm_module_args as a
    background 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's InProcessDriver calls _sync_document
    directly, so open returned while the warm-up still ran. A hover on a module
    argument then answered None. WireDriver was never affected, because a
    JSON-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 different
    ways, while 14 jobs that ran the same tests passed:

    job failure
    test-nogc-git 2 tests, 120s deadline -- the signature of this issue
    test-local-nix_2_31 3 tests, AssertionError: expected a hover result, got None

    A re-run of both, at the same commit, separated them:

    job re-run
    test-nogc-git success -- non-determinism, as this issue demonstrates it
    test-local-nix_2_31 failure again -- reproducible, so not a flake

    test-local-nix_2_31 loses this race reliably because it is the slowest job of
    the matrix: 12m22s against 7m39s for test-local-git (see #161).

    After the fix

    Two dispatched runs of test-local-nix_2_31 on ci-develop, both green:
    31625283471
    and 31626487823.
    Two failures before, two successes after.

    What is not fixed

    The None mode is gone from the in-process driver. The timeout mode over a
    real 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_report work from the comment above still stands as the way the next
    occurrence gets read.

    The regression test is tests/harness/test_lsp_driver_settle.py. It lives
    there 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.

  3. Lillecarl commented on Aug 16, 2026

    @Lillecarl
    ContributorAuthor

    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, the
    same two-minute spacing, and the same teardown:

    pytest_lsp/protocol.py:53 in _handle_notification
        future.set_result(params)
    concurrent.futures._base.InvalidStateError: CANCELLED: <Future ... state=cancelled>
    

    That set_result on a cancelled future is the notification arriving after
    the 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 didOpen for the same file in 1.0 s on macOS
    26.5.1 arm64. Each of these was tried, and none changed that number:

    • the exact client_capabilities("visual-studio-code") the fixture sends,
      rather than an empty capability set;
    • initialize with and without rootUri;
    • the NIX_CONFIG that _configure_worker_local_stores exports;
    • draining the stderr of the server, and leaving it undrained.

    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 the
    lsp_wire fixture: the same pytest_lsp.LanguageClient, the same
    capabilities, 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 ran
    in-process only.

    test_lsp_e2e.py keeps the two tests that need a real process, and its fixture
    now 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 lsp is now tested nowhere, and
    that gap belongs here. The round trip is the defect, so a test of it today
    asserts the defect rather than the behaviour.

    • Find why the pytest process makes the same request 120 times slower.
    • Give test_lsp_e2e.py its round-trip test back, ungated.
  4. added
    source: nanopynix
    on Oct 19, 2026
  5. added theissue type on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0