fix: reprompt on invalid agent name instead of crashing#8769
Merged
Conversation
When a user enters an agent name that violates validation rules (e.g., longer than 63 characters) during `azd ai agent init`, the command now displays the validation error and re-prompts instead of crashing. This applies the same retry-loop pattern already used by `promptForReplacementAgentName` to the initial agent name prompt in `resolveInitAgentName`. Fixes #8381 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the interactive UX of azd ai agent init in the azure.ai.agents extension by preventing a crash when the user enters an invalid agent name during the prompt flow, instead re-prompting until a valid name is provided.
Changes:
- Wraps the interactive agent-name prompt in
resolveInitAgentName()with a retry loop that re-prompts on validation errors. - Reuses the existing validation retry display behavior (
writeValidationRetryError) to show the error + suggestion before retrying. - Adds a unit test to verify an invalid name followed by a valid name results in exactly two prompts and a successful resolution.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
cli/azd/extensions/azure.ai.agents/internal/cmd/init.go |
Adds a retry loop around the interactive prompt path in resolveInitAgentName() so invalid names no longer crash the command. |
cli/azd/extensions/azure.ai.agents/internal/cmd/init_test.go |
Adds test coverage to ensure invalid interactive input reprompts and succeeds once a valid name is entered. |
Use exterrors.FromPrompt instead of raw fmt.Errorf when wrapping prompt errors in resolveInitAgentName, matching the pattern used by all other prompt call sites. This ensures gRPC Unauthenticated errors are converted into structured auth errors with re-login suggestions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hund030
approved these changes
Jun 23, 2026
huimiu
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When a user enters an agent name longer than 63 characters (or otherwise invalid) during
azd ai agent init, the command crashes with a validation error. At that point, files may already be partially created, making it hard to undo.What changed
resolveInitAgentName()now wraps the interactive prompt in a retry loop. When validation fails, it prints the error and suggestion, then re-prompts -- matching the pattern already used by the siblingpromptForReplacementAgentName()function.--agent-nameflag path still returns an error immediately (no interactive reprompt possible).--no-promptpath is unchanged (it uses the already-validated default name).A new test (
TestResolveInitAgentName_InvalidNameRepromptsUntilValid) verifies that entering an invalid name followed by a valid one succeeds after exactly two prompts.Fixes: #8381