fix: cleanup agent instances in a365 cleanup blueprint#284
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
This pull request enhances the blueprint cleanup process in the Agent365 DevTools CLI by implementing cascading deletion of agent instances and improving error handling for partial failures. When cleaning up a blueprint, the CLI now queries for all agent instances linked to that blueprint, presents a detailed preview of resources to be deleted (including agentic users and identity service principals), and deletes these resources before deleting the blueprint itself. If any deletions fail, the user receives a clear summary of orphaned resources that need manual cleanup.
Changes:
- Added
AgentInstanceInfomodel to represent agent instances with their identity SP and optional agentic user - Enhanced
AgentBlueprintServicewith methods to query and delete agent instances and users, with virtual modifiers for testability - Updated blueprint cleanup command to cascade delete instances, use
IConfirmationProviderfor user confirmation, and provide detailed preview and orphan summaries - Added comprehensive test coverage for the new cascading deletion behavior and proper resource disposal in test infrastructure
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.Agents.A365.DevTools.Cli/Models/AgentInstanceInfo.cs | New record to represent agent instances linked to a blueprint with identity SP ID, display name, and optional agentic user ID |
| src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs | Added methods to query agent instances, delete agentic users, and made deletion methods virtual for testability; includes placeholder API property names that need verification |
| src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs | Enhanced blueprint cleanup to cascade delete instances with preview, confirmation, failure tracking, and orphan summaries; now uses IConfirmationProvider |
| src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Services/AgentBlueprintServiceTests.cs | Added tests for querying and deleting agent instances/users; added Dispose implementation to FakeHttpMessageHandler for proper resource cleanup |
| src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Commands/CleanupCommandTests.cs | Added tests for cascading deletion behavior with instances, no instances, and partial failures; updated all mock calls to include optional correlationId parameter |
| src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Commands/CleanupCommandBotEndpointTests.cs | Updated mock setup to include optional correlationId parameter for endpoint deletion |
| src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Commands/BlueprintSubcommandTests.cs | Updated all mock calls and assertions to include optional correlationId parameter for endpoint deletion |
|
@gwharris7 I've opened a new pull request, #297, to work on those changes. Once the pull request is ready, I'll request review from you. |
…ts (#297) * Initial plan * Fix FakeHttpMessageHandler disposal to use using statements Co-authored-by: gwharris7 <96964444+gwharris7@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gwharris7 <96964444+gwharris7@users.noreply.github.com>
…Service.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@gwharris7 I've opened a new pull request, #305, to work on those changes. Once the pull request is ready, I'll request review from you. |
#305) * Initial plan * Surface query failure explicitly in GetAgentInstancesForBlueprintAsync Co-authored-by: gwharris7 <96964444+gwharris7@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gwharris7 <96964444+gwharris7@users.noreply.github.com>
…thub.com/microsoft/Agent365-devTools into users/grantharris/fix-orphaned-instances
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request introduces significant improvements to the blueprint cleanup process in the CLI tool, focusing on cascading deletion of agent instances and better handling/reporting of partial failures. The changes enhance user experience by previewing all resources that will be deleted, confirming destructive actions, and providing clear warnings and summaries if any resources could not be deleted. Additionally, several new methods were added to support querying and deleting agent instances and users, and the test code was updated for compatibility. This PR addresses issue #258.
Blueprint cleanup enhancements:
The blueprint cleanup command now queries for all agent instances linked to a blueprint, shows a detailed preview of what will be deleted (including agentic users and identity service principals), and deletes these resources before deleting the blueprint itself. If any deletions fail, the user receives a summary of orphaned resources to clean up manually. [1] [2] [3] [4] [5]
The command now uses an injected
IConfirmationProviderfor user confirmation, replacing directConsole.ReadLinecalls, making the code more testable and consistent. [1] [2]Agent instance management:
Added a new
AgentInstanceInforecord inModels/AgentInstanceInfo.csto represent agent instances linked to a blueprint, including identity SP and optional agentic user.Introduced new methods in
AgentBlueprintServiceto:GetAgentInstancesForBlueprintAsync)DeleteAgentUserAsync)DeleteAgentBlueprintAsyncandDeleteAgentIdentityAsyncvirtual for easier testing/mocking. [1] [2] [3]Test updates: