Skip to content

cleanup instance is a no-op - AgenticAppId/AgenticUserId are never populated in generated config #259

@pratapladhani

Description

@pratapladhani

Description

a365 cleanup instance reads AgenticAppId and AgenticUserId from a365.generated.config.json to find the identity SP and agentic user to delete. However, these fields are never populated by any a365 command (setup, publish, deploy). They are always empty/null, so cleanup instance silently does nothing.

Steps to Reproduce

  1. a365 setup all --skip-infrastructure --verbose
  2. a365 publish --verbose
  3. Admin activates blueprint, user creates instance
  4. Examine a365.generated.config.jsonAgenticAppId and AgenticUserId are not present
  5. Run a365 cleanup instance — says "Starting instance cleanup..." then immediately completes without deleting anything

Expected Behavior

One of:

  • Option A (Recommended): Deprecate this command. Since create-instance was already deprecated ("bypassed required registration steps"), and instances are now created through M365 Admin Center + Teams, the CLI never has the opportunity to write instance IDs to local config. cleanup instance should be deprecated and instance cleanup folded into cleanup blueprint (with cascade deletion or warnings).
  • Option B: Discover instances dynamically using the blueprint ID. The AgentBlueprintId is already populated in a365.generated.config.json. Use it to query for child instances via Graph API — e.g., GET /beta/servicePrincipals/microsoft.graph.agentIdentity filtered by the blueprint's parent app, then resolve agentic users via identityParentId. This would make the command functional without requiring any new config fields.
  • Option C: a365 publish or some other command should populate AgenticAppId and AgenticUserId in the generated config after instance creation is detected.

Actual Behavior

cleanup instance guards every deletion behind if (!string.IsNullOrWhiteSpace(config.AgenticAppId)) and if (!string.IsNullOrWhiteSpace(config.AgenticUserId)). Since these are never populated, all deletion blocks are skipped. The command completes "successfully" without cleaning up anything.

Code Reference

CleanupCommand.cs lines ~355-366:

// Delete agent identity application
if (!string.IsNullOrWhiteSpace(config.AgenticAppId))  // Always empty -> skipped
{
    logger.LogInformation("Deleting agent identity application...");
    await executor.ExecuteAsync("az", $"ad app delete --id {config.AgenticAppId}", ...);
}

// Delete agent user
if (!string.IsNullOrWhiteSpace(config.AgenticUserId))  // Always empty -> skipped
{
    logger.LogInformation("Deleting agent user...");
    await executor.ExecuteAsync("az", $"ad user delete --id {config.AgenticUserId}", ...);
}

Impact

Users believe they have cleaned up their instances but orphaned resources remain in Entra ID. Combined with the cleanup blueprint issue (which also doesn't clean up instances), there is no CLI path to properly clean up agent instances.

Additional Context

The create-instance command was deprecated per official docs: "bypassed required registration steps." Instance creation now happens exclusively through M365 Admin Center + Teams. Since the CLI no longer manages the instance lifecycle (create -> cleanup), this command is effectively dead code. Deprecating it and moving instance cleanup responsibility into cleanup blueprint (or a new cleanup all enhancement) would align the CLI with the current platform design.

Metadata

Metadata

Assignees

Labels

P1Very high prioritybugSomething isn't workingescalatedIssue has breached SLA and been escalatedsecuritySecurity-related issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions