Skip to content

Fix stale cached match count in AbstractTextSearchResult - #4453

Merged
vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:lv/flaky-textsearchresulttest
Oct 9, 2026
Merged

vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:lv/flaky-textsearchresulttest

Conversation

@vogella

@vogella vogella commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

ResultUpdaterTest.testRemoveFile (expected: <792> but was: <887>) and TextSearchResultTest.testBatchRemoveElements keep failing intermittently on Windows CI, even after #4343. The cause is in AbstractTextSearchResult.getMatchCount(): its cache used 0 as "invalid", so a reader summing while matches were still being added, such as the Search view during a foreground search, could publish an undercount that stayed cached until the next change. The cache is now tagged with a modification counter and only reused while that counter is unchanged, which keeps the cheap cached path but can no longer return a stale count. A new regression test reads the count concurrently with adds and fails on the old implementation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Partial exceptional removals can retain stale counts, and the regression test does not deterministically reproduce the race.

2 open findings
What changed in this PR

Fixes stale cached match counts during concurrent search-result updates.

Changes:

  • Tags cached counts with a modification counter.
  • Invalidates counts after add/remove operations.
  • Adds a concurrent regression test and registers it in the suite.
File Description
AbstractTextSearchResult.java Reworks match-count cache invalidation.
AbstractTextSearchResultMatchCountTest.java Adds concurrent-add regression coverage.
AllSearchTests.java Registers the new test.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

getMatchCount() cached its sum using 0 as "invalid" and writers reset it
with set(0) before mutating. A reader that started summing while matches
were still being added, for example the Search view updating its label on
the UI thread during a forked foreground search, could publish an
undercount through compareAndSet(0, n), because it cannot see that
writers kept storing 0. The stale value survived until the next change,
which made TextSearchResultTest.testBatchRemoveElements and
ResultUpdaterTest.testRemoveFile flaky.

The cache is now tagged with a modification counter that writers bump
after mutating, and a cached value is only used while the counter is
unchanged.

Assisted-by: multiple AI agents and layers of automated tooling 🤖
@vogella
vogella force-pushed the lv/flaky-textsearchresulttest branch from 2e86171 to 01248cd Compare October 8, 2026 07:39
@vogella
vogella requested a balanced review from Copilot October 8, 2026 07:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The concurrency fix correctly prevents completed mutations from leaving a reusable stale count, with focused regression coverage.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@vogella

vogella commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@iloveeclipse fine for you now?

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Test Results

   864 files  ±0     864 suites  ±0   1h 19m 14s ⏱️ + 30m 35s
 8 396 tests +1   8 154 ✅ +1  242 💤 ±0  0 ❌ ±0 
21 057 runs  +3  20 380 ✅ +3  677 💤 ±0  0 ❌ ±0 

Results for commit 01248cd. ± Comparison against base commit 21e6248.

@vogella
vogella merged commit 0cf5104 into eclipse-platform:master Oct 9, 2026
18 checks passed
@vogella
vogella deleted the lv/flaky-textsearchresulttest branch October 9, 2026 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants