Reuse existing azd environment on azd ai agent init reruns#7327
Reuse existing azd environment on azd ai agent init reruns#7327
azd ai agent init reruns#7327Conversation
Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com> Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/83ae2408-eb24-4ff5-b22a-67ad44375e09
Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com> Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/83ae2408-eb24-4ff5-b22a-67ad44375e09
Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com> Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/83ae2408-eb24-4ff5-b22a-67ad44375e09
azd ai agent init reruns
|
/azp run azure-dev - cli |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR makes azd ai agent init reruns resilient by reusing a previously-created azd environment when it already exists, and by surfacing duplicate-environment failures structurally through core environment management and the workflow gRPC service.
Changes:
- Wrap duplicate-environment creation failures with the
environment.ErrExistssentinel forerrors.Issupport. - Map
environment.ErrExiststo gRPCcodes.AlreadyExistsin the workflow service (with tests). - Make the extension’s
createNewEnvironment(...)reuse an existing named environment instead of always runningazd env new(with tests).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cli/azd/pkg/environment/manager.go | Wrapes duplicate creation with ErrExists for structural detection. |
| cli/azd/internal/grpcserver/workflow_service.go | Maps ErrExists to codes.AlreadyExists over gRPC. |
| cli/azd/internal/grpcserver/workflow_service_test.go | Adds coverage for the new gRPC status mapping. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers.go | Reuses an existing named environment before attempting env new. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers_test.go | Adds a test ensuring reuse avoids workflow execution. |
cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers.go
Show resolved
Hide resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9d02465 to
0b20dee
Compare
|
/azp run azure-dev - cli |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Fixes #7286
azd ai agent initfails on a second attempt when a prior run created the target environment but exited before finishing. The init flow treated the pre-existing environment as a hard conflict instead of reusing it.Environment creation is now idempotent for named environments.
createNewEnvironment(...)checks for an existing named environment before runningazd env newand reuses it immediately if found. If a concurrent process creates the environment during the workflow call, thecodes.AlreadyExistsgRPC status is caught and the environment is re-fetched.The duplicate-environment error is now surfaced structurally through the stack:
environment.Manager.Create()wraps the existingErrExistssentinel, and the workflow gRPC service maps it tocodes.AlreadyExistsinstead of flattening all runner errors tocodes.Internal.Also refactored
getExistingEnvironmentto accept anenvName stringparameter instead of*initFlags, removing unnecessary coupling.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.