Repository navigation
fix(search): run the debounced work once when both timers fire - #4030
Merged
Merged
Conversation
Every pending space has a debounce timer and a timeout timer, and both call the same work function. The function checked for a run in progress before taking the mutex, so when both timers were due together, both calls passed the check and the space was indexed twice at the same time. Take the mutex first and return when the work item is no longer the pending one. This is also what made "fires at the timeout even when continuously debounced" flaky: its two timers are due about 50ms apart, which is close enough on a busy CI runner.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
🟢 Coverage 100.00% diff coverage · +0.00% coverage variation
Metric Results Coverage variation ✅ +0.00% coverage variation (-1.00%) Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (2032e85) 94240 28200 29.92% Head commit (ca733e7) 94243 (+3) 28201 (+1) 29.92% (+0.00%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#4030) 7 7 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
dschmidt
marked this pull request as ready for review
November 17, 2026 11:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SpaceDebouncerkeeps a debounce timer and a timeout timer per space, and both call the same work function. That function checked for a run in progress before taking the mutex. When both timers are due together, both calls pass the check and the space is indexed twice at the same time.The work function now takes the mutex first and returns when its work item is no longer the pending one.
This is also the cause of the flaky unit test
SpaceDebouncer fires at the timeout even when continuously debounced(Expected 2 to equal 1). Its timers are due about 50ms apart, which a busy CI runner can turn into "together". In production the timers are 1s and 30s, so it needs steady events on one space close to the 30s mark, or a stalled process.Tested on current main:
The package is green with
-race. Not tested against a running instance.AI usage: the flake was reproduced and traced with Claude Code (claude-fable-5-2), which also wrote the patch and the test.