Skip to content

Fix canceled Program queries caching empty results#4502

Open
LumiaGG wants to merge 1 commit into
Flow-Launcher:devfrom
LumiaGG:fix/program-query-cancel-cache
Open

Fix canceled Program queries caching empty results#4502
LumiaGG wants to merge 1 commit into
Flow-Launcher:devfrom
LumiaGG:fix/program-query-cancel-cache

Conversation

@LumiaGG
Copy link
Copy Markdown

@LumiaGG LumiaGG commented Jun 1, 2026

Summary by cubic

Stops caching empty results when Program queries are canceled, so follow-up searches return the correct apps. Adds a unit test to ensure canceled searches never poison the cache.

  • Summary of changes

    • Changed: Handle OperationCanceledException at the top of QueryAsync around cache.GetOrCreateAsync(...), letting cancellation bubble out so no cache entry is created; simplified lock acquire/release with try + finally (no inner catches).
    • Added: Top-level catch returns emptyResults for canceled queries, without caching.
    • Removed: Inner catch (OperationCanceledException) blocks during Win32 and UWP preparation and scoring.
    • Memory: Avoids caching empty result lists; slight reduction in cache memory usage.
    • Security: No impact or new risks.
    • Tests: Added ProgramPluginTest.QueryAsync_DoesNotCacheCanceledResultsAsync to verify canceled queries don’t cache and subsequent queries return expected results.
  • Release Note
    Canceled searches no longer cache empty results, so future searches show the right apps.

Written for commit 70348b1. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added this to the 2.2.0 milestone Jun 1, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 13d019c0-f154-40b2-9b56-864b8ad34fd6

📥 Commits

Reviewing files that changed from the base of the PR and between ef7d89d and 70348b1.

📒 Files selected for processing (2)
  • Flow.Launcher.Test/Plugins/ProgramPluginTest.cs
  • Plugins/Flow.Launcher.Plugin.Program/Main.cs

📝 Walkthrough

Walkthrough

This PR improves cancellation handling in the Program plugin's QueryAsync method to prevent canceled searches from populating the cache. The implementation refactors lock acquisition to use try/finally patterns with outer-scope exception handling, while a new test fixture comprehensively validates that canceled queries return empty results without caching.

Changes

Cancellation Handling and Testing

Layer / File(s) Summary
Refactored lock acquisition and cancellation handling
Plugins/Flow.Launcher.Plugin.Program/Main.cs
Win32 and UWP lock acquisition uses try/finally with acquired flags for safe cleanup. OperationCanceledException handling moves to the outer cache factory scope. Task.Run receives the cancellation token directly, ensuring cancellation returns empty results without caching.
Test fixture for canceled result caching behavior
Flow.Launcher.Test/Plugins/ProgramPluginTest.cs
ProgramPluginTest fixture includes TearDown state reset, main test that triggers mid-query cancellation and validates empty results without caching, mock IPublicAPI factory with controlled cancellation behavior on first invocation, and reflection helpers to manipulate plugin internal state for testing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Flow-Launcher/Flow.Launcher#4072: Both PRs modify Plugins/Flow.Launcher.Plugin.Program/Main.cs to improve cancellation behavior during synchronized lock/semaphore acquisition in QueryAsync, preventing canceled operations from leaving synchronization primitives unreleased.
  • Flow-Launcher/Flow.Launcher#3978: Both PRs modify Plugins/Flow.Launcher.Plugin.Program/Main.cs to refactor lock acquisition/release logic in QueryAsync using safer try/finally patterns, with this PR extending that to ensure canceled searches aren't cached.

Suggested reviewers

  • jjw24
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: preventing empty results from canceled Program queries from being cached.
Description check ✅ Passed The description thoroughly explains the problem, solution, and changes made, directly relating to the fix for canceled query caching behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

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.

1 participant