Skip to content

Conversation

@jiripolasek
Copy link
Collaborator

@jiripolasek jiripolasek commented Jan 14, 2026

Summary of the Pull Request

This PR introduces a rough hotfix for several indexer-related issues.

  • Premise: patch what we can in-place and fix the core later (reworking SeachEngine and SearchQuery is slightly trickier). This patch also removes some dead code for future refactor.
  • Adds search cancellation to the File Search page and the indexer fallback.
    • Prevents older searches from overwriting newer model state and reduces wasted work.
  • Stops reusing the search engine; creates a new instance per search to avoid synchronization issues.
    • That SeachEngine and SearchQuery are not multi-threading friendly.
  • Removes search priming to simplify the code and improve performance.
    • Since SearchQuery cancels and re-primes on every search, priming provides little benefit and can hide extra work (for example, cancellation triggering re-priming).
  • Fixes the indexer fallback subject line not updating when there is more than one match.
    • It previously kept the old value, which was confusing.
  • Shows the number of matched files in the fallback result.
    • Fetching total number of rows was reverted, performance was not stable :(
  • Optimizes the indexer fallback by reducing the number of items processed but not used.
    • Only fetches the item(s) needed for the fallback itself—no extra work on the hot path.
    • Stops reusing the fallback result when navigating to the File Search page to show more results. This requires querying again, but it simplifies the flow and keeps components isolated.
  • Fixes the English mnemonic keyword kind being hardcoded in the search page filter. Windows Search uses localized mnemonic keyword names, so this PR replaces it with canonical keyword System.Kind that is universaly recognized.
  • Adds extra diagnostics to SearchQuery and makes logging more precise.
  • DataPackage for the IndexerListItem now defers including of storage items - boost performance and we avoid touching the item until its needed.
  • IndexerPage with a prepopulated query will delay loading until the items are actually enumerated (to avoid populating from fallback hot path) and it no longer takes external SearchEngine. It just recreates everything.

PR Checklist

  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

- Add search cancellation to the file search page and the indexer fallback.
- Stop reusing the search engine; create a new instance per search to avoid synchronization issues.
- Remove search priming to simplify the code and improve performance.
- Fix the subject line not updating in some branches of the indexer fallback flow.
- Show the number of matched files in the fallback result.
- Fix the English keyword "kind" being hardcoded in the search page filter.
- Optimize the indexer fallback by reducing the number of items processed but not used.
- Adds some extra diagnostics to SearchQuery and makes logging more precise.
@jiripolasek jiripolasek added the Product-Command Palette Refers to the Command Palette utility label Jan 14, 2026
@jiripolasek jiripolasek changed the title CmdPal: Make Indexer great again - part 1 - hotri CmdPal: Make Indexer great again - part 1 - hotfix Jan 14, 2026
@github-actions

This comment has been minimized.

@jiripolasek jiripolasek added the CmdPal - Indexer Issues related to the Indexer (file search) built-in extension label Jan 14, 2026
- Stop reading total count from the rowset and remove exact count from the UI
- Add fine-grained locking to the indexer fallback
- Fix icon blinking
@github-actions

This comment has been minimized.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a hotfix for several indexer-related issues in the CmdPal file search functionality. The changes focus on improving search cancellation, thread-safety, and performance by creating new SearchEngine instances per search rather than reusing them, removing search priming logic, and optimizing the fallback behavior.

Changes:

  • Adds search cancellation support using CancellationTokenSource to prevent stale results from overwriting newer searches
  • Replaces SearchEngine reuse with per-search instantiation to avoid multi-threading issues
  • Removes search priming logic from QueryStringBuilder and SearchQuery to simplify code and improve performance
  • Fixes fallback subject line to update correctly when multiple matches are found
  • Optimizes DataPackage creation by deferring storage item loading until needed
  • Fixes hardcoded English "kind" mnemonic keyword by using canonical "System.Kind" property name

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
SearchEngine.cs Adds nullable support, returns int from Query (though always 0), adds noIcons parameter to FetchItems, improves disposal pattern
Resources.resx Adds new localized string for multiple results subtitle
Resources.Designer.cs Auto-generated code updated to version 18.0.0.0
IndexerPage.cs Implements cancellation with CancellationTokenSource, adds Lock-based synchronization, recreates SearchEngine per search, implements deferred loading, fixes System.Kind filter keywords
QueryStringBuilder.cs Removes priming query generation and ReuseWhere functionality, simplifies to static class
SearchQuery.cs Adds QueryState tracking, removes ReuseWhere mechanism, improves diagnostics and error handling, adds ALLNOISE constant
DataPackageHelper.cs Defers storage item loading using SetDataProvider for lazy evaluation
FallbackOpenFileItem.cs Adds cancellation support, implements async icon loading, adds result locking, creates new SearchEngine per query
expect.txt Adds ALLNOISE to spell-check dictionary
Files not reviewed (1)
  • src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Properties/Resources.Designer.cs: Language not supported

OnPropertyChanged(nameof(EmptyContent));
}
},
ct);
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

Unobserved exceptions from Task.Run can cause application crashes. The fire-and-forget pattern with Task.Run should handle exceptions explicitly. Consider wrapping the task body in a try-catch block or using await with proper exception handling.

Suggested change
ct);
ct).ContinueWith(
t =>
{
_ = t.Exception;
},
TaskContinuationOptions.OnlyOnFaulted);

Copilot uses AI. Check for mistakes.
{
var pQueryHelper = (SearchQuery)state;
pQueryHelper.ExecuteSyncInternal();
return 0;
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The Execute method returns 0 unconditionally, making the return value meaningless. If the method signature was changed to return int to provide total results count, it should return the actual count. Otherwise, consider changing the return type to void.

Suggested change
return 0;
return SearchResults.Count;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CmdPal - Indexer Issues related to the Indexer (file search) built-in extension Product-Command Palette Refers to the Command Palette utility

Projects

None yet

1 participant