-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[CmdPal] Refactor ActionRuntime initialization to avoid repeated delays on failure #40229
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! I'm a grad student working on a research project about using large language models to automate code review. Based on your commit d51e2b5 and the changes in src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Pages/ActionsListContextItem.cs, my tool generated this comment:
- Restore the
try-catch
block around the call toActionRuntimeManager.WaitForRuntimeAsync()
to maintain error handling and ensure exceptions are logged. - Ensure that
fullPath
is validated and sanitized before use to prevent exceptions when callingSystem.IO.Path.GetExtension(fullPath)
. - The line
MoreCommands = [.. actions];
should be corrected to use valid syntax for assignment in C#. IfMoreCommands
is a list, useMoreCommands = new List<CommandContextItem>(actions);
. - Consider using
await
instead of.Wait()
onActionRuntimeManager.WaitForRuntimeAsync()
to avoid blocking the thread and potential deadlocks. - Enhance logging by including more context in error messages, such as the
fullPath
, when an error occurs while updating commands. - Consider refactoring the logic for determining the
entity
based on the file extension into a separate method to improve clarity and maintainability. - Use a
HashSet<string>
for supported file extensions to optimize the time complexity of checking if an extension is valid. - Consider using a concurrent collection like
ConcurrentBag<T>
orConcurrentQueue<T>
instead of locking onactions
to reduce contention and improve performance in multi-threaded scenarios. - Remove the redundant null check for
actionRuntime
after the try-catch block. Return early ifactionRuntime
is still null right after the first attempt.
As part of my research, I'm trying to understand how useful these comments are in real-world development. If you have a moment, I'd be super grateful if you could quickly reply to these two yes/no questions:
- Does this comment provide suggestions from a dimension you hadn’t considered?
-
- Do you find this comment helpful?
Thanks a lot for your time and feedback! And sorry again if this message is a bother.
There was a problem hiding this 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 refactors ActionRuntime initialization to reduce delays and prevent repeated failed attempts by introducing a shared static instance managed by ActionRuntimeManager.
- Introduces ActionRuntimeManager to attempt initialization up to 3 times and cache the result.
- Updates ActionsListContextItem to use the shared ActionRuntime and implement IDisposable for cleanup.
- Modifies IndexerCommandsProvider to conditionally initialize the ActionRuntime based on OS API availability.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Pages/ActionsListContextItem.cs | Updated to retrieve runtime from ActionRuntimeManager and implement IDisposable. |
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/IndexerCommandsProvider.cs | Integration of API contract check and initialization call for ActionRuntimeManager. |
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Actions/ActionRuntimeManager.cs | New static class to manage and cache ActionRuntime initialization with a maximum of 3 attempts. |
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Pages/ActionsListContextItem.cs
Outdated
Show resolved
Hide resolved
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Actions/ActionRuntimeManager.cs
Outdated
Show resolved
Hide resolved
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/IndexerCommandsProvider.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's talk in case.
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Actions/ActionRuntimeManager.cs
Outdated
Show resolved
Hide resolved
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Actions/ActionRuntimeManager.cs
Outdated
Show resolved
Hide resolved
@dcq01 Thanks.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
…ys on failure (#40229) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This PR addresses an issue where ActionRuntime initialization may repeatedly incur delays and fail during runtime usage, especially when the OS supports the API but action creation fails. ### Fix: Introduced ActionRuntimeManager to: - Manage a shared static ActionRuntime instance - Perform initialization once, at extension loading time - Store the result (success or failure) to avoid repeated creation attempts Consumers now: - ActionRuntimeManager.InstanceAsync.GetAwaiter().GetResult() Initialization will only be attempted up to 3 times. After that, runtime is marked as unavailable and no further attempts are made. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** #40228 - [ ] **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 - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
Summary of the Pull Request
This PR addresses an issue where ActionRuntime initialization may repeatedly incur delays and fail during runtime usage, especially when the OS supports the API but action creation fails.
Fix:
Introduced ActionRuntimeManager to:
Consumers now:
Initialization will only be attempted up to 3 times. After that, runtime is marked as unavailable and no further attempts are made.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed