Skip to content

fix: a language server that fails to start no longer takes away the features of the file's other language servers - #2160

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/start-failure-keeps-other-servers
Nov 23, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/start-failure-keeps-other-servers

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2158

What

A request for the language servers of a file starts each matching language server, and connects the file to it, in one CompletableFuture.allOf().

  • When one server failed to start (a wrong command, a failing initialize), allOf failed, and so did the whole request. The file lost the features of the language servers that had started too. Ctrl+hover on a working server's semantic tokens, for instance, showed no hint.
  • The same fault was in requests for the language servers of definitions: workspace symbols, and LanguageServerManager.getLanguageServers(id) for a definition with several instances.

Change

In LanguageServiceAccessor, a language server of a request that fails to start, or to connect the file, is left out, and the others serve the request.

  • A cancellation (the server is stopped or restarted while the request waits) leaves it out without a failure, as before.
  • A start failure (LanguageServerException) has already been reported by the language server: the "Cannot start server" notification, and the Language Servers view. So it's logged at debug level only.
  • Any other failure is unexpected and reported nowhere else, so it's logged as a warning.
  • An Error still fails the request.
  • No language server left: the request still fails, with the first failure, as a request for one language server did. That way a feature keeps no result, and asks again after the restart pause.

handleFutureException is unchanged: LanguageServerManager.getInitializedServer(wrapper), which waits for one server, still uses it.

Behaviour change

Situation Before After
One of several language servers of a file fails to start or to connect it The request fails, and the file gets no LSP feature from any server The failed server is left out, and the others serve the file
Its start failure Notification, and the Language Servers view The same, not logged again
Another, unexpected failure of one of several servers Fails the request The server is left out, and a warning is logged
Every language server of the request fails The request fails The request fails, with the same exception
A server is stopped while the request waits for it Left out Left out

Backward compatibility

  • No API change.
  • Requests that used to fail when one of their language servers failed now complete with the others, and requests whose servers all fail still fail as before.
  • A feature that caches its result (semantic tokens, folding, code lens, inlay hints) can keep a result without the failed server until the file changes or its features refresh; a restart by the user refreshes them. Before, the file had no feature from any server in that time, until the failed restarts disabled the server.

Test

  • LSPSemanticTokenDocumentationProviderTest: Ctrl+hover gives the hint of the first server when the second fails its initialize.
  • ServerStartFailureTest:
    • the other servers serve a file request and a workspace request;
    • a request whose only server can't start still fails;
    • the start failure is still notified, and not logged again;
    • an unexpected failure is logged once, as a warning, and leaves the server out;
    • a server stopped while the request waits is left out without a failure.
  • Without the change in LanguageServiceAccessor, the 6 new tests fail.
  • Affected packages (com.redhat.devtools.lsp4ij and …features.*): 1,160 tests, 0 failures, on IC 2024.2, 2025.3 and IU 2026.3.
  • Full suite on 2024.2: 2,091 tests, 0 failures, 7 skipped, as before.

…eatures of the file's other language servers

A request for the language servers of a file starts each language server that
serves the file, and connects the file to it, all in one
CompletableFuture.allOf(). A language server that failed to start, as one with
a wrong command or one that fails its initialize, failed allOf, and with it the
whole request: a feature of the file then got none of its language servers, not
even those that had started. Ctrl+hover, for instance, showed no hint. A request
for the language servers of definitions, as for workspace symbols, or for
LanguageServerManager.getLanguageServers(id) of a definition with several
instances, had the same fault.

A language server that fails to start, or to connect the file, is now left out
of the request, and the other language servers serve it. When the request leaves
out all of them, it still fails with the failure of the first one, as a request
for a single language server did: a feature keeps no failed result, and asks
again, as once the pause after a failed restart is over, while it would keep an
empty one until the file changes.

Nothing fails silently. A language server that cannot start, or that stopped,
fails with a LanguageServerException, which it has reported already, with its
"Cannot start server" notification and in the Language Servers view: it is
logged at the debug level only. Any other failure of a language server that is
left out is unexpected, and nothing else reports it: it is logged as a warning.
A cancellation, as when the language server is stopped while the request waits
for it, leaves it out without a failure, as before, and an Error still fails
the request.

Fixes redhat-developer#2158
@lagergren lagergren added this to the 0.30.2 milestone Nov 23, 2026
@lagergren lagergren added the bug Something isn't working label Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Language server startup or file-connection failures are now reported when no applicable server is available, rather than being silently skipped.
    • When one server fails but another is available, requests can still be handled by the working server.
    • A server stopped during initialization is excluded without being reported as a failure.

Server collection now handles startup and file-connection failures per language server. Successful servers remain available when another server fails. If no server succeeds, the first recorded failure is propagated. Cancellation remains excluded from failure reporting.

Changes: Language server failure isolation

Layer / File(s) Summary
Classify and report server failures
src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java
The accessor distinguishes cancellations, Error causes, and other failures. It logs recorded failures and propagates the first recorded failure when no server succeeds.
Apply failure policy to server collection
src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java
Definition-based and file-based requests record failures for individual servers. Each request returns successful servers when available.
Verify server selection and failure reporting
src/test/java/com/redhat/devtools/lsp4ij/features/ServerStartFailureTest.java, src/test/java/com/redhat/devtools/lsp4ij/features/semanticTokens/viewProvider/LSPSemanticTokenDocumentationProviderTest.java
Tests cover failure propagation, use of another matching server, notification and log behavior, cancellation during initialization, and hover results when another server cannot initialize.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr, d-biehl

Merge Risk: Minimal · up to fe82d

This change keeps the remaining language servers for a file working when one fails to start or connect, and still reports that server's failure. It adds targeted tests for failure, cancellation and hover cases. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: a language server that fails to start no longer removes the features served by the file's other language servers. The raw summary confirms that LanguageServiceAccesso…
Description check Passed The description is directly related to the changeset. It explains the allOf() failure path, the change in LanguageServiceAccessor, the handling of cancellations, start failures, and Error, the behavio…
Linked Issues check Passed Issue #2158 requires that a language server that fails to start is left out of a file's request, its error is still reported, and the other servers keep serving the file. At the reviewed head, Languag…
Out of Scope Changes check Passed The changes stay within the fault described in #2158: a single failing server removes the other servers from a CompletableFuture.allOf(...) request. The main change is in LanguageServiceAccessor. The …
Full details: Title check

Explanation

The title states the main change: a language server that fails to start no longer removes the features served by the file's other language servers. The raw summary confirms that LanguageServiceAccessor now leaves failed servers out and keeps the successful ones. The title is long, though, at 113 characters, and it could be shorter.

Full details: Description check

Explanation

The description is directly related to the changeset. It explains the allOf() failure path, the change in LanguageServiceAccessor, the handling of cancellations, start failures, and Error, the behavior change table, and the tests added in LSPSemanticTokenDocumentationProviderTest and ServerStartFailureTest.

Full details: Linked Issues check

Explanation

Issue #2158 requires that a language server that fails to start is left out of a file's request, its error is still reported, and the other servers keep serving the file. At the reviewed head, LanguageServiceAccessor adds leaveOut(...), which records a failure for each server that fails to start or connect the file. Cancellations and ProcessCanceledException leave the server out without a failure. An Error still fails the request. serversOrFailure(...) returns the servers that started when at least one did. A LanguageServerException is logged at debug level because the server already reported it through its 'Cannot start server' notification and the Language Servers view. Other failures are logged as warnings. If every server fails, the first failure is rethrown as a CompletionException. The PR summary and the raw change summary both describe this behavior. Test coverage is claimed in LSPSemanticTokenDocumentationProviderTest and ServerStartFailureTest. Those test files were not read directly, so test behavior is taken from the PR description and summary. Limitation: the full text diff was truncated at 16000 bytes, so the file-connection path was read only in part.

Full details: Out of Scope Changes check

Explanation

The changes stay within the fault described in #2158: a single failing server removes the other servers from a CompletableFuture.allOf(...) request. The main change is in LanguageServiceAccessor. The PR also applies the same leave-out logic to workspace-symbol requests and to LanguageServerManager.getLanguageServers(id) for definitions with several instances. Those paths use the same allOf pattern, so the change is a direct extension of the same fault and not unrelated work. handleFutureException is unchanged, as the PR states. The test changes (LSPSemanticTokenDocumentationProviderTest, ServerStartFailureTest) cover the modified behavior and do not add unrelated functionality. The raw summary reports no API or public declaration changes. Limitation: the full diff could not be read beyond the truncated portion, so the workspace-symbol and definitions code paths were not inspected directly.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2dec8c42-470c-462f-a2cc-7ed3d7cd5e98
Commits

Reviewing files that changed from the base of the PR and between 661b774 and fe82d03.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/ServerStartFailureTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/semanticTokens/viewProvider/LSPSemanticTokenDocumentationProviderTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.31034% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.59%. Comparing base (53fd2f9) to head (fe82d03).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...edhat/devtools/lsp4ij/LanguageServiceAccessor.java 79.31% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2160      +/-   ##
==========================================
+ Coverage   53.23%   53.59%   +0.35%     
==========================================
  Files         826      827       +1     
  Lines       34728    34956     +228     
  Branches     7147     5477    -1670     
==========================================
+ Hits        18487    18733     +246     
+ Misses      13470    13434      -36     
- Partials     2771     2789      +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit 937c2a4 into redhat-developer:main Nov 23, 2026
13 of 14 checks passed
lagergren added a commit that referenced this pull request Nov 23, 2026
…ion that it shuts down (#2162)

## What

`CancelRequestAfterShutdownTest.testTheAnswerToARequestOfTheLanguageServerIsSentOnceTheShutdownIsSent`, which came with #2151, failed once on CI, on macOS 2024.2 (run [45231743923](https://github.com/redhat-developer/lsp4ij/actions/runs/45231743923), in #2160):

    The language server must read the answer to its request, and exit, after shutdown expected:<[shutdown, ResponseMessage, exit]> but was:<[shutdown, exit]>

It's a bug in the test, not in LSP4IJ or #2151: LSP4IJ did answer the request, but over another connection.

## Cause

- **A restart:** the test stops the language server while its editor is open. A stop that doesn't disable the language server lets a feature of the editor start it again, over a second connection (`start()` with the status `stopping`). The code vision does that when its first lookup of the language servers comes after the stop.
- **The wrong client:** the mock language server then has two clients. The test sent `workspace/configuration` through the last of `getRemoteProxies()`, which was the new connection's, and that connection answered it. The connection that the test stops, and whose reads it checks, read only `shutdown` and `exit`.
- **Reproduced:** under CPU load on macOS, with probes, main failed 2 of 2,100 runs. Each time, the second connection read the answer:

      [[initialize, initialized, didOpen, diagnostic, shutdown, exit], [initialize, ResponseMessage, initialized, didOpen, diagnostic, codeLens, $/cancelRequest]]

  With a 20 ms delay before the code vision's lookup of the language servers, 7 of 100 runs fail. Asking for the file's language servers right after the shutdown is read fails 20 of 20.

## Change

- The test's connection keeps the client that it gives the language server.
- The test sends the request through the client of the connection that it stops.
- The test checks that the request ends with an answer: `isDone()` is also true for a request that couldn't be sent.

## Test

- **With the fix:** 0 of 20 runs fail with the forced restart, and 0 of 100 with the delayed code vision (55 of them with two clients when the request was sent).
- **`CancelRequestAfterShutdownTest`:** 8 tests, 0 failures, on IC 2024.2, IC 2025.3 and IU 2026.3.
- **Full suite on IC 2024.2:** 2,134 tests, 0 failures, 0 errors, 7 skipped, as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A language server that fails to start takes away the features of the other language servers of the file

1 participant