Skip to content

fix: cleanup agent instances in a365 cleanup blueprint#284

Merged
gwharris7 merged 22 commits intomainfrom
users/grantharris/fix-orphaned-instances
Mar 4, 2026
Merged

fix: cleanup agent instances in a365 cleanup blueprint#284
gwharris7 merged 22 commits intomainfrom
users/grantharris/fix-orphaned-instances

Conversation

@gwharris7
Copy link
Copy Markdown
Contributor

@gwharris7 gwharris7 commented Feb 24, 2026

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 IConfirmationProvider for user confirmation, replacing direct Console.ReadLine calls, making the code more testable and consistent. [1] [2]

Agent instance management:

  • Added a new AgentInstanceInfo record in Models/AgentInstanceInfo.cs to represent agent instances linked to a blueprint, including identity SP and optional agentic user.

  • Introduced new methods in AgentBlueprintService to:

    • Query all agent instances for a given blueprint (GetAgentInstancesForBlueprintAsync)
    • Delete an agentic user (DeleteAgentUserAsync)
    • Made DeleteAgentBlueprintAsync and DeleteAgentIdentityAsync virtual for easier testing/mocking. [1] [2] [3]

Test updates:

  • Updated tests to accommodate the new method signatures for endpoint deletion, adding the optional correlation ID parameter where appropriate. [1] [2] [3] [4] [5]

@gwharris7 gwharris7 requested review from a team as code owners February 24, 2026 08:34
Copilot AI review requested due to automatic review settings February 24, 2026 08:34
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 24, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown
Contributor

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 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 AgentInstanceInfo model to represent agent instances with their identity SP and optional agentic user
  • Enhanced AgentBlueprintService with methods to query and delete agent instances and users, with virtual modifiers for testability
  • Updated blueprint cleanup command to cascade delete instances, use IConfirmationProvider for 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

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs Outdated
Copilot AI review requested due to automatic review settings February 24, 2026 18:25
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs Outdated
Copilot AI review requested due to automatic review settings February 27, 2026 10:32
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

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

Copilot AI and others added 4 commits February 27, 2026 09:47
…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>
Copilot AI review requested due to automatic review settings February 27, 2026 19:41
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs Outdated
…Service.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 3, 2026 00:54
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

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

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs
#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>
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Copilot AI review requested due to automatic review settings March 4, 2026 02:25
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 4, 2026 07:39
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs
Copilot AI review requested due to automatic review settings March 4, 2026 07:54
@gwharris7 gwharris7 enabled auto-merge (squash) March 4, 2026 07:54
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/GraphApiService.cs
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/GraphApiService.cs
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Commands/CleanupCommand.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs Outdated
Comment thread src/Microsoft.Agents.A365.DevTools.Cli/Services/AgentBlueprintService.cs Outdated
@gwharris7 gwharris7 merged commit 03d78a6 into main Mar 4, 2026
8 checks passed
@gwharris7 gwharris7 deleted the users/grantharris/fix-orphaned-instances branch March 4, 2026 21:16
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.

5 participants