Skip to content

fix: reprompt on invalid agent name instead of crashing#8769

Merged
huimiu merged 2 commits into
mainfrom
trangevi/fix-agent-init-long-name-crash
Jun 23, 2026
Merged

fix: reprompt on invalid agent name instead of crashing#8769
huimiu merged 2 commits into
mainfrom
trangevi/fix-agent-init-long-name-crash

Conversation

@trangevi

Copy link
Copy Markdown
Member

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 sibling promptForReplacementAgentName() function.

  • The --agent-name flag path still returns an error immediately (no interactive reprompt possible).
  • The --no-prompt path is unchanged (it uses the already-validated default name).
  • Only the interactive prompt path gains the retry loop.

A new test (TestResolveInitAgentName_InvalidNameRepromptsUntilValid) verifies that entering an invalid name followed by a valid one succeeds after exactly two prompts.

Fixes: #8381

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>
Copilot AI review requested due to automatic review settings June 22, 2026 22:57
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Review may take a bit longer — reach out to @RickWinter or @kristenwomack if you'd like to discuss prioritization.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Jun 22, 2026
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>
@huimiu huimiu merged commit 44e00a2 into main Jun 23, 2026
25 checks passed
@huimiu huimiu deleted the trangevi/fix-agent-init-long-name-crash branch June 23, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azd ai agent init crashes if the agent name is too long

4 participants