Skip to content

Extract reusable CopilotToolInvocationService from FixVulnerabilitiesService - #7418

Merged
donnie-msft merged 13 commits into
devfrom
dev-donnie-msft-copilotInvokeRefactor
Jun 1, 2026
Merged

donnie-msft merged 13 commits into
devfrom
dev-donnie-msft-copilotInvokeRefactor

Conversation

@donnie-msft

@donnie-msft donnie-msft commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/3795

Description

Extracts the shared Copilot pre-flight logic (auth check, service available, etc) into a reusable ICopilotToolInvocationService so it can be shared across multiple GH Copilot entry points.

File Change type Notes
ICopilotToolInvocationService.cs New Interface defining the shared pre-flight contract.
CopilotToolInvocationService.cs Moved Logic extracted from FixVulnerablitiesService; minimal refactoring to accept parameters instead of hard-coded values.
CopilotToolSession.cs New Bundles CopilotThread + discovered functions + disposables into a single IAsyncDisposable so callers don'tmanage lifetimes manually.
CopilotToolSessionResult.cs New Discriminated success/failure struct replacing nullable out-params.
CopilotToolSessionError.cs New Enum cataloguing the pre-flight failure modes (previously inline early-returns inFixVulnerablitiesService).
FixVulnerablitiesService.cs Modified Now importsICopilotToolInvocationService; method is ~40 lines shorter and focuses only on prompt construction and request dispatch.

Copilot service availability handling

Per the latest Copilot extensibility guidance, callers should treat a successful IServiceBroker.GetProxyAsync<ICopilotService> as confirmation that the service is available, and subscribe to IServiceBroker.AvailabilityChanged when holding the service long-term. ICopilotService.CheckAvailabilityAsync and
SubscribeToAvailabilityAsync are deprecated.

ICopilotToolInvocationService now exposes an AvailabilityChanged event that forwards broker notifications filtered to the Copilot service moniker, so future long-lived consumers can react. Today's consumer (FixVulnerablitiesService) uses sessions per-invocation via await using and does not need to subscribe.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests - existing tests pass
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@donnie-msft
donnie-msft requested a review from a team as a code owner May 26, 2026 19:07

@jebriede jebriede left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This extraction is clean and the CopilotToolSessionResult pattern nicely encapsulates the session lifecycle, failure checks, resource ownership, and resource cleanup, so callers can focus on their responsibility! Left a few comments on null safety and resource disposal.

@donnie-msft
donnie-msft requested a review from jebriede May 27, 2026 22:35
@donnie-msft
donnie-msft force-pushed the dev-donnie-msft-copilotInvokeRefactor branch from e4a7365 to 10e1d96 Compare May 29, 2026 01:06

@jebriede jebriede left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 !!

@donnie-msft
donnie-msft requested a review from Nigusu-Allehu May 29, 2026 01:19

@Nigusu-Allehu Nigusu-Allehu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Vamos

@donnie-msft
donnie-msft merged commit 67f2203 into dev Jun 1, 2026
17 of 18 checks passed
@donnie-msft
donnie-msft deleted the dev-donnie-msft-copilotInvokeRefactor branch June 1, 2026 19:30
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.

3 participants