-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Labels
Description
Summary
During a365 publish, the MOS prerequisites check acquires a new Graph API token for every single API call by spawning 2 az CLI subprocesses each time. A single publish command spawns ~22 subprocesses just for token acquisition.
Evidence
Captured from a365 publish --verbose output:
- 11 separate token acquisitions during MOS prerequisites check alone
- Each acquisition spawns 2
azCLI processes = 22 subprocess spawns - The token is valid for ~60 minutes but is never cached/reused
Breakdown of calls in CheckMosPrerequisitesAsync:
| Operation | Graph API calls | Token acquisitions |
|---|---|---|
| 1 SP lookup (first-party) | 1 | 1 |
| 3 SP lookups (resource apps) | 3 | 3 |
| 3 admin consent checks (SP lookup + grant query each) | 6 | 6 |
| MOS token acquisition | 1 | 1 |
| Total | 11 | 11 x 2 = 22 az processes |
Redundant lookups
Admin consent verification re-looks up service principals that were already verified in the service principal check phase.
Root Cause
GraphApiService.EnsureGraphHeadersAsync() is called before every GraphGetAsync/GraphPostAsync call, and in the Azure CLI path it always calls GetGraphAccessTokenAsync() which spawns fresh az subprocesses. There is no token caching for the Azure CLI code path (though the IMicrosoftGraphTokenProvider path does cache).
Proposed Fix
- Cache the Azure CLI token in
GraphApiServicewith a reasonable TTL (e.g., 5 minutes or until expiry) - Pass cached service principal IDs from the first check phase into the admin consent check phase to avoid redundant lookups
- Consider batching Graph API calls where possible
Impact
- Publish command takes significantly longer than necessary due to subprocess overhead
- Each
azprocess spawn adds ~2-3 seconds, so ~22 spawns = ~45-60 seconds of token acquisition overhead - User experience: verbose output is cluttered with repetitive 'Acquiring Graph token' debug messages
Related
- Issue PublishCommand: All error paths return exit code 0 instead of non-zero #264 (PublishCommand exit codes)
Reactions are currently unavailable