Skip to content

Fix result missing + not updating issues #3513

New issue

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

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

Already on GitHub? # to your account

Merged
merged 8 commits into from
May 7, 2025
Merged

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented May 6, 2025

Fix result missing issue

  • Dispose _updateSource when creating new one.
  • Use _updateToken instead of _updateSource.Token to resolve ObjectDisposeException.
  • Use local variable for stability to resolve possible token cancellation issue.

Fix #3508, #3511 from #3314

@prlabeler prlabeler bot added the bug Something isn't working label May 6, 2025
@Jack251970 Jack251970 added the Dev branch only An issue or fix for the Dev branch build label May 6, 2025
@Jack251970 Jack251970 removed the bug Something isn't working label May 6, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented May 6, 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 413 additions & 228 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: 41%

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

Copy link

gitstream-cm bot commented May 6, 2025

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

1 similar comment
Copy link

gitstream-cm bot commented May 6, 2025

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

@prlabeler prlabeler bot added the bug Something isn't working label May 6, 2025
@Jack251970 Jack251970 linked an issue May 6, 2025 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented May 6, 2025

📝 Walkthrough

"""

Walkthrough

The changes refactor cancellation token handling in the MainViewModel class by introducing a dedicated _updateToken field, which is updated whenever the associated _updateSource is replaced. This prevents ObjectDisposedException issues and ensures consistent, safe cancellation during asynchronous query operations and event handling.

Changes

File(s) Change Summary
Flow.Launcher/ViewModel/MainViewModel.cs Introduced _updateToken field, updated all usages from _updateSource.Token to _updateToken, ensured proper disposal and reassignment of _updateSource and _updateToken in async query methods and event handlers, clarified _ignoredQueryText initialization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainViewModel
    participant Plugins
    participant UI

    User->>MainViewModel: Types query
    MainViewModel->>MainViewModel: Dispose old _updateSource, create new _updateSource and _updateToken
    MainViewModel->>Plugins: Query plugins with _updateToken
    Plugins-->>MainViewModel: Return results or cancel if _updateToken is cancelled
    MainViewModel->>UI: Update results display
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix issue where Programs plugin results no longer return for global queries (#3508) The changes improve cancellation token handling but do not explicitly address the Programs plugin query issue described. Further verification needed.

Suggested reviewers

  • jjw24
  • taooceros

Poem

A token anew, no longer disposed,
Ensures that the queries are properly closed.
Results now refresh, no more old ghosts remain,
The launcher responds, swift and sane.
With every new search, a rabbit’s delight—
Bugs hop away, and all works right! 🐇✨
"""


📜 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 2672512 and 297643c.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (9 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: build
✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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: 1

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

48-50: Consider the lifetime of the new _updateToken field

Introducing a cached CancellationToken simplifies null-checking and avoids ObjectDisposedException, nice work!
However, because _updateToken is re-assigned on every new query, any long-running background handler that reads this field (instead of the copy it was originally handed) will suddenly be looking at a token unrelated to its own operation. A typical example is the ResultsUpdated event where some plugins may forget to supply e.Token.

If you keep the field, please be sure every async workflow captures the token immediately (e.g. var token = _updateToken;) and never reads the field again. Another safe alternative is to remove the field entirely and always capture _updateSource.Token into a local variable each time you spawn work.


255-257: Use CanBeCanceled instead of default to detect an “empty” token

default(CancellationToken) and CancellationToken.None are equivalent, but comparing a struct to default is a bit obscure and may cause confusion.
A clearer (and slightly safer) pattern is:

-var token = e.Token == default ? _updateToken : e.Token;
+var token = !e.Token.CanBeCanceled ? _updateToken : e.Token;

This also works for the (rare) case where a plugin intentionally returns CancellationToken.None to indicate “never cancelled”.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6799b87 and 639a5ae.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (2)
Flow.Launcher/ViewModel/MainViewModel.cs (2)

1334-1343: Good cancellation propagation for the progress-bar delay

Passing _updateToken into Task.Delay and its continuation ensures the progress bar never appears for a query that has already been cancelled. This is an elegant, cheap way to keep the UI responsive.


1455-1461: Consistent use of the shared token in history updates

QueryHistoryTask now respects _updateToken, guaranteeing that history results are not shown for obsolete queries. This closes the race that led to issue #3511 – great catch!

This comment has been minimized.

This comment has been minimized.

@Jack251970 Jack251970 enabled auto-merge May 6, 2025 06:19
@Jack251970 Jack251970 added this to the 1.20.0 milestone May 6, 2025
@Jack251970 Jack251970 removed the bug Something isn't working label May 6, 2025
@jjw24
Copy link
Member

jjw24 commented May 6, 2025

Didn't seem to resolve the missing results issue. All Program results are gone even when using the action keyword 'progr'. But Chrome stuck around for whatever reason it keeps popping up 🤣

test log.txt

Copy link

github-actions bot commented May 6, 2025

@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 19

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
Copy link
Member Author

Didn't seem to resolve the missing results issue. All Program results are gone even when using the action keyword 'progr'. But Chrome stuck around for whatever reason it keeps popping up 🤣

test log.txt

Damn. That is really weird. I reverted all codes to master branch. And could you please check if this can work?

@Jack251970
Copy link
Member Author

Luckily, now we can confirm that this issue comes from CancellationToken.

@jjw24
Copy link
Member

jjw24 commented May 6, 2025

Have you been able to reproduce the issue?

@Jack251970
Copy link
Member Author

Have you been able to reproduce the issue?

No. I have not encountered this issue before. After heavy usage (type edge and clear for more than 60 times), I still cannot reproduce that.

@Jack251970
Copy link
Member Author

Jack251970 commented May 6, 2025

Have you been able to reproduce the issue?

I have set up python script for testing that. And after about 360/600/1000 times, I still cannot reproduce that issue.

@jjw24
Copy link
Member

jjw24 commented May 6, 2025

Typing edge and deleting it repeatedly won't reproduce it i find.

I can repro with typing giberrish several times, as you have seen in the logs. Maybe try typing random giberrish, then type teams hdjdiiejendjoxownwbbw or chrome jsjjdiejn+727+2 if you don't have teams installed, then continue with some more gibberish.

@Jack251970
Copy link
Member Author

Jack251970 commented May 7, 2025

chrome jsjjdiejn+727+2

I have tried this python script:

import pyautogui
import random

# Input Alt-Whitespace to open Flow.Launcher
pyautogui.hotkey('alt', 'space')

# Get random character
def get_random_char():
    return random.choice('abcdefghijklmnopqrstuvwxyz')

times = 0
while True:
    # Get random value 3 to 10
    random_value = random.randint(3, 10)
    for i in range(random_value):
        # Get random character
        char = get_random_char()
        # Type the character
        pyautogui.typewrite(char)
        # Sleep for a random time between 0.1 and 0.2 seconds
        pyautogui.sleep(random.uniform(0.1, 0.2))

    for i in range(random_value):
        # Type the character
        pyautogui.typewrite(['backspace'])
        # Sleep for a random time between 0.0 and 0.15 seconds
        pyautogui.sleep(random.uniform(0.0, 0.15))
    times += 1
    print(f"Times: {times}")

    if times % 15 == 0:
        str1 = 'chrome'
        str2 = 'jsjjdiejn+727+2'
        # Type chrome jsjjdiejn+727+2
        pyautogui.typewrite(str1)
        pyautogui.sleep(random.uniform(0.1, 0.2))
        pyautogui.typewrite(str2)
        # Sleep for a random time between 0.1 and 0.2 seconds
        pyautogui.sleep(random.uniform(0.1, 0.2))
        # Type backspace
        for h in range(len(str2)):
            pyautogui.typewrite(['backspace'])
        pyautogui.sleep(random.uniform(0.1, 0.2))
        for h in range(len(str1)):
            pyautogui.typewrite(['backspace'])
        pyautogui.sleep(random.uniform(0.1, 0.2))

But I still cannot reproduce that after 381 times.

image

@Jack251970
Copy link
Member Author

Or could you please share me with a script that you can reproduce the issue on your device?

@jjw24
Copy link
Member

jjw24 commented May 7, 2025

Tested both issues resolved.

Do you think any additional logging should be added or this is good to merge?

@Jack251970
Copy link
Member Author

Tested both issues resolved.

Do you think any additional logging should be added or this is good to merge?

Good! I think it is good to merge.

@prlabeler prlabeler bot added the bug Something isn't working label May 7, 2025
@Jack251970 Jack251970 removed the bug Something isn't working label May 7, 2025
@prlabeler prlabeler bot added the bug Something isn't working label May 7, 2025
@jjw24 jjw24 removed the bug Something isn't working label May 7, 2025
@jjw24 jjw24 changed the title Fix result missing issue Fix result missing + not updating issue May 7, 2025
@prlabeler prlabeler bot added the bug Something isn't working label May 7, 2025
@jjw24 jjw24 changed the title Fix result missing + not updating issue Fix result missing + not updating issues May 7, 2025
@jjw24 jjw24 removed the bug Something isn't working label May 7, 2025
# for free to join this conversation on GitHub. Already have an account? # 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 not changing/updating Dev branch - Programs result not longer returning for global query
2 participants