Skip to content

fix: an editor behavior flag computed while the file's language server starts is computed again once that language server changes it - #2262

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/editor-behavior-flag-race
Nov 25, 2026

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2261

What

EditorBehaviorFeatureTest.testAFlagThatChangesWhileItIsComputedIsComputedAgain (from #2159) failed once in 5 runs of its class, headless, on IU 2026.3. It's a product race in EditorBehaviorFeature's flag cache, not a test bug.

Cause

compute read the tracker counts after LanguageServiceAccessor.getModificationTrackers(file) had looked up the started language servers of the file, including the project-level count that changes as a language server starts. Take a language server created after that lookup and started before the counts were read:

  • its own tracker wasn't kept;
  • the project-level count already included its start.

hasAny still computed the flag from it, so its later changes were missed until another status or definition change.

In the test, the semantic tokens file view provider of the editor can compute the flag that way while the test starts the language server. It takes the first answer (false) and misses the increment that answer makes. The test then reads the cached false.

Change

compute reads the project-level count first, through TrackerCount.of(languageServiceAccessor::getModificationCount), before the language servers of the file are looked up. The FlagValue Javadoc says why. The test is unchanged.

Behaviour change

Before After
An editor behavior flag computed while the file's language server was starting could miss that language server's later changes, counted by its own tracker, and stay cached until a language server of the project changed status or definition The flag is computed again once that language server changes it

Tests

  • On its own: 0 failures in 20 runs on IU 2026.3, 10 on IC 2024.2 and 10 on 2025.3 before the fix.
  • Red-green, with a throwaway probe (not committed): a latch holds a computation of the flag on another thread between the lookup and the count read while the language server starts. Without the fix it fails every time with the CI message (3/3 IU 2026.3, 1/1 IC 2024.2, 1/1 2025.3). With the fix it passes every time (same counts).
  • With the fix:
    • the class passes 20/20 headless on IU 2026.3 and once each on IC 2024.2 and 2025.3;
    • client.features.*, features.formatting.*, features.semanticTokens.* and features.documentation.* pass headless on all three platforms: 135 tests, 0 failures, 0 skipped each.

Not in this PR

A language server that is already started and is put back among the started servers after a cancelled replacement still changes no count.

…r starts is computed again once that language server changes it

EditorBehaviorFeatureTest.testAFlagThatChangesWhileItIsComputedIsComputedAgain failed now and then
on IU 2026.3, headless.

EditorBehaviorFeature.compute read the tracker counts after
LanguageServiceAccessor.getModificationTrackers had looked up the started language servers of the
file. A language server could be created after that lookup and have started before the counts were
read. Its own tracker then wasn't kept. The count of the project's language servers, read last,
already included its start. hasAny still computed the flag from it. Its later changes were missed,
and the flag stayed cached until a language server of the project changed status or definition.

In the test, the semantic tokens file view provider of the editor can compute the flag that way while
the test starts the language server. It then takes the language server's first answer, false, and
misses the change that the answer makes. The test's own computations get the cached false.

The count of the project's language servers is now read first, before the lookup.

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

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved the consistency of editor behavior detection when language servers are initialized while a file is being checked.
    • Updated cached results to account for changes in the project’s language-server state, helping ensure editor behavior reflects the latest state.

EditorBehaviorFeature.compute now captures the project language-server modification count before collecting file-specific trackers. It includes both in the cached flag’s dependencies.

Changes: Editor behavior flag invalidation

Layer / File(s) Summary
Track project and file server changes
src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.java
compute reads the project modification count before looking up file language servers, then combines that count with file-specific tracker counts. The documentation notes that a server created during lookup can affect the computed flag without its own tracker being recorded.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 09df8

This change fixes a rare race where an editor behavior flag could stay cached after a language server changed it during computation. The change is small and localized, and no remaining merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change: an editor behavior flag computed while the file's language server starts is recomputed once that server changes it. This matches the EditorBehaviorFeature cache rac…
Description check Passed The description states the problem (a race in EditorBehaviorFeature's flag cache), its cause, the code change, the behaviour change, and the test results. It is directly related to the changeset.
Linked Issues check Passed [#2261] The issue requires that a flag computed while the file's language server starts does not stay cached after that server changes its flag. At the reviewed head, EditorBehaviorFeature.compute rea…
Out of Scope Changes check Passed The whole-PR summary and the current-head file show that the change is limited to src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.java (+11/-4 lines). The change reorder…
Full details: Title check

Explanation

The title names the primary change: an editor behavior flag computed while the file's language server starts is recomputed once that server changes it. This matches the EditorBehaviorFeature cache race fix, which reads the project-level modification count before the file's language servers are looked up. The 'fix:' prefix and length are slightly long but the title is specific and accurate.

Full details: Linked Issues check

Explanation

[#2261] The issue requires that a flag computed while the file's language server starts does not stay cached after that server changes its flag. At the reviewed head, EditorBehaviorFeature.compute reads the project-level count (TrackerCount.of(languageServiceAccessor::getModificationCount)) before calling getModificationTrackers(file). The count is therefore read before any server of the file is looked up. A server created after the lookup changes the project count after it was read, so the cached FlagValue becomes stale and the flag is computed again. A server that existed at lookup keeps its own tracker. The FlagValue Javadoc documents this ordering. The issue's reproduction (latch-based) is a test-reproduction aid. The PR reports a throwaway probe that fails without the fix and passes with it. Committing that probe is not a requirement of the issue. Existing test EditorBehaviorFeatureTest.testAFlagThatChangesWhileItIsComputedIsComputedAgain is unchanged and still covers the behavior. The only coding change is in EditorBehaviorFeature.java, so no non-coding task is assessed.

Full details: Out of Scope Changes check

Explanation

The whole-PR summary and the current-head file show that the change is limited to src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.java (+11/-4 lines). The change reorders the project-count read before the file-server lookup, adds the project count to the FlagValue dependencies, and extends the Javadoc. All of these changes serve issue #2261. No unrelated code change appears in the summary. The changed-blob diff could not be read from the checkout, so the scope check relies on the file content at head and the PR summary.

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: 4f80fd4e-61d2-4bd7-9e31-3b6d867d198f
Commits

Reviewing files that changed from the base of the PR and between 1c74814 and 09df803.

Files selected for processing: 1

  • src/main/java/com/redhat/devtools/lsp4ij/client/features/EditorBehaviorFeature.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 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.86%. Comparing base (7b66f44) to head (09df803).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2262      +/-   ##
==========================================
+ Coverage   55.82%   55.86%   +0.04%     
==========================================
  Files         848      848              
  Lines       36265    36265              
  Branches     7502     7502              
==========================================
+ Hits        20245    20261      +16     
+ Misses      13103    13092      -11     
+ Partials     2917     2912       -5     

☔ 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 25, 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 25, 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 a713d6d into redhat-developer:main Nov 25, 2026
9 checks passed
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.

EditorBehaviorFeature keeps a flag computed while the file's language server starts across that language server's later changes

1 participant