Skip to content

Do not cancel tasks which requires clearing existing results #3577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented May 23, 2025

Follows on from #3553

And I think the update flow is:

if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query,
->
UpdateResultView(queue.Values);
->
Results.AddResults(resultsForUpdates, token, reSelect);
.

So I removed all token check after we write in _resultsUpdateChannelWriter if the update task will require result clearing.

Resolve #3576

@Jack251970 Jack251970 requested a review from Copilot May 23, 2025 06:17
@Jack251970 Jack251970 added the Dev branch only An issue or fix for the Dev branch build label May 23, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone May 23, 2025
Copy link
Contributor

@Copilot 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 updates task handling to ensure that tasks flagged for clearing existing results are not cancelled even if their cancellation tokens have been triggered.

  • Adjusts the queue insertion logic in UpdateActionAsync to include tasks that clear existing results.
  • Modifies the token selection logic in UpdateResultView to use a default token when any update task is for clearing results.
Comments suppressed due to low confidence (1)

Flow.Launcher/ViewModel/MainViewModel.cs:1878

  • Using Distinct().SingleOrDefault() may throw an exception if more than one distinct cancellation token exists. If multiple tokens are expected, consider implementing logic to handle them appropriately.
token = resultsForUpdates.Select(r => r.Token).Distinct().SingleOrDefault();

Copy link

gitstream-cm bot commented May 23, 2025

🥷 Code experts: onesounds

Jack251970, onesounds have most 👩‍💻 activity in the files.
Jack251970 has most 🧠 knowledge in the files.

See details

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970 onesounds
MAY 529 additions & 316 deletions
APR 35 additions & 28 deletions
MAR 695 additions & 628 deletions 293 additions & 201 deletions
FEB 63 additions & 21 deletions 23 additions & 25 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions

Knowledge based on git-blame:
Jack251970: 40%

To learn more about /:\ gitStream - Visit our Docs

Copy link

gitstream-cm bot commented May 23, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented May 23, 2025

📝 Walkthrough

"""

Walkthrough

The changes update the logic in the asynchronous result update queue within MainViewModel.cs to ensure that tasks intended to clear existing results are always processed, even if their cancellation tokens have been triggered. The handling of cancellation tokens is adjusted to guarantee that clearing actions are not skipped due to cancellation.

Changes

File(s) Change Summary
Flow.Launcher/ViewModel/MainViewModel.cs Modified result update logic: ensures items flagged to clear results are enqueued even if canceled, and adjusts cancellation token selection to always process clearing updates. No changes to public API signatures.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainViewModel
    participant UpdateQueue

    User->>MainViewModel: Initiates result update (may include clear flag)
    MainViewModel->>UpdateQueue: Enqueue update (check cancellation token and clear flag)
    UpdateQueue-->>MainViewModel: Processes update
    alt shouldClearExistingResults is true
        MainViewModel->>UpdateResultView: Use default (non-canceled) token
    else
        MainViewModel->>UpdateResultView: Use derived cancellation token
    end
    UpdateResultView-->>MainViewModel: Results updated/cleared
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure home query results are cleared when typing from empty to one word (#3576)

Possibly related PRs

  • Fix clearing of results logic & minor adjustment to results update #3524: The main PR extends the clearing logic by ensuring updates flagged to clear existing results are processed despite cancellation tokens, building directly on the deferred clearing approach and the shouldClearExistingResults flag introduced and refined in the retrieved PR.
  • Fix result missing + not updating issues #3513: The main PR and this PR both modify cancellation token handling in the MainViewModel class to improve result update processing, but the main PR specifically ensures that updates flagged to clear existing results are processed despite cancellation, while the retrieved PR focuses on safely managing token disposal and avoiding exceptions.

Suggested labels

bug

Suggested reviewers

  • Jack251970
  • taooceros

Poem

A bunny hopped through lines of code,
Where results once stubbornly showed.
Now with a fix, so clever and neat,
Old home queries swiftly retreat.
No cancellation can block this clear—
The search is fresh, the view sincere!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 445ca9a and 634e829.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

215-216: Minor grammar improvement in comment.

The logic correctly ensures clearing tasks are always queued regardless of cancellation status. However, the comment has a minor grammatical issue.

-        // If this update task is for clearing existing results, we must need to add it to the queue
+        // If this update task is for clearing existing results, we must add it to the queue
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2026bb7 and 3ee52d7.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Spelling
Flow.Launcher/ViewModel/MainViewModel.cs

[warning] 1846-1846: Spell check warning: VSTHRD is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

870-879: Excellent implementation for preventing cancellation of clearing tasks.

The logic correctly handles the case where clearing tasks should not be cancelled by using a default token. This ensures that UI updates for clearing existing results are always processed, which aligns perfectly with the PR objective.

The implementation is thread-safe and handles the edge case appropriately by falling back to the default token in the catch block.

@Jack251970 Jack251970 requested review from Copilot and jjw24 May 23, 2025 06:33
Copy link
Contributor

@Copilot 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 pull request adjusts task cancellation behavior to ensure that tasks meant for clearing existing results are not cancelled. Key changes include adding an extra condition to bypass cancellation tokens, modifying the token passed to result update tasks, and setting a default token in the result view update when clearing results.

Comments suppressed due to low confidence (1)

Flow.Launcher/ViewModel/MainViewModel.cs:1880

  • Using SingleOrDefault may throw an exception if there are multiple distinct tokens; consider using FirstOrDefault or ensuring that all tokens are identical.
token = resultsForUpdates.Select(r => r.Token).Distinct().SingleOrDefault();

This comment has been minimized.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 13

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@Jack251970 Jack251970 enabled auto-merge May 23, 2025 07:01
@@ -1460,8 +1462,9 @@ void QueryHistoryTask(CancellationToken token)
_lastQuery = query;
_previousIsHomeQuery = currentIsHomeQuery;

// If this update task is for clearing existing results, do not pass token to make sure it is handled
Copy link
Member

Choose a reason for hiding this comment

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

What scenario could have this occur?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If one task which needs to clear existing results, we should make sure it is handled in Results. So we need to ignore its origin token here.

Copy link
Member

@jjw24 jjw24 May 23, 2025

Choose a reason for hiding this comment

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

In the original code if a task is cancelled, it wouldn't get to this part of the code right

Copy link
Contributor Author

@Jack251970 Jack251970 May 23, 2025

Choose a reason for hiding this comment

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

Please see the update flow above in desc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still in the process to update the results though.

Copy link
Member

Choose a reason for hiding this comment

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

Hm show me what exactly do you mean.

Copy link
Member

Choose a reason for hiding this comment

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

Actually in this PR we are just trying to handle the case where token is cancelled but require clearing results still, so we can just capture this where token is cancelled and require clearing are true then return empty result set in that NewResults method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jjw24 Please go ahead with this. I find I am unable to do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually in this PR we are just trying to handle the case where token is cancelled but require clearing results still, so we can just capture this where token is cancelled and require clearing are true then return empty result set in that NewResults method.

Feel free to change anything you would like

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am little unfamiliar with this clear logic and the only thing I can change is about handling with token cancellation.

@jjw24 jjw24 added the review in progress Indicates that a review is in progress for this PR label May 23, 2025
@jjw24 jjw24 changed the title Do not cancel tasks which is for clearing existing results Do not cancel tasks which requires clearing existing results May 25, 2025
@jjw24 jjw24 removed review in progress Indicates that a review is in progress for this PR 1 min review labels May 25, 2025
@Jack251970
Copy link
Contributor Author

Continue in #3588.

@Jack251970 Jack251970 closed this May 26, 2025
auto-merge was automatically disabled May 26, 2025 12:35

Pull request was closed

@Jack251970 Jack251970 removed this from the 1.20.0 milestone May 26, 2025
@jjw24 jjw24 deleted the do_not_check_token_after_update branch May 29, 2025 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dev branch only An issue or fix for the Dev branch build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dev Branch: Results Clear Issue
2 participants