Skip to content

fix: stop agent lifecycle from rewriting azure.yaml - #9397

Merged
trangevi merged 2 commits into
mainfrom
hui/fix-ai-agents-yaml-format
Aug 4, 2026
Merged

fix: stop agent lifecycle from rewriting azure.yaml#9397
trangevi merged 2 commits into
mainfrom
hui/fix-ai-agents-yaml-format

Conversation

@huimiu

@huimiu huimiu commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

  • keep resolved agent container settings in memory during lifecycle hooks
  • prevent preprovision and predeploy from rewriting user-authored azure.yaml
  • cover inline, legacy, missing-default, and $ref configuration paths

Why

The azure.ai.agents extension persisted resolved CPU and memory settings during every preprovision and predeploy event. That project mutation caused azd core to reserialize the entire azure.yaml file, which changed formatting and could remove user-authored metadata and hook fields.

Lifecycle persistence is removed because deployment already applies the same CPU and memory defaults when values are omitted. This preserves azure.yaml without changing deployed agent behavior, while explicit configuration commands such as init, adopt, and optimize continue to write intended changes.

Testing

  • go test .\internal\cmd .\internal\project -count=1
  • go build .\...

End-to-end steps

  1. Build azd and azure.ai.agents from the PR head SHA in an isolated azd profile.
  2. Install the exact-SHA extension bundle and its dependencies.
  3. Record the azure.yaml before running lifecycle commands.
  4. Run azd provision --no-prompt, azd infra create --no-prompt, azd deploy --no-prompt, and azd up --no-prompt.
  5. Confirm azure.yaml is unchanged.

Fixes #8025

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
21 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Aug 3, 2026
@huimiu
huimiu marked this pull request as ready for review August 3, 2026 10:07
Copilot AI balanced review requested due to automatic review settings August 3, 2026 10:07
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Thank you for logging this issue; our team is reviewing it. If you need urgent prioritization, tag @RickWinter and @kristenwomack to let us know.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
21 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

Prevents agent lifecycle hooks from rewriting azure.yaml while preserving runtime container defaults.

Changes:

  • Removes project persistence calls from container-setting preparation.
  • Keeps inline, legacy, missing-default, and $ref settings resolved in memory.
  • Updates tests for in-memory behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/cmd/listen.go Applies lifecycle container settings without persisting them.
internal/cmd/listen_test.go Verifies in-memory resolution across configuration paths.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified the core claim: deploy applies the same defaults, so dropping the lifecycle write doesn't change deployed behavior. service_target_agent.go falls back to DefaultCpu/DefaultMemory (same constants) when the resolved config leaves them empty, and the remaining hook writes (updateLegacyProjectDeployments, envUpdate) only touch env vars, never azure.yaml. Dropping the client parameter from prepareContainerSettings also means the function can't write back to the host at all now, which is a stronger guarantee than the assertion the tests used to carry.

One thing outside the diff worth a follow-up: the comment at cli/azd/extensions/azure.ai.agents/internal/project/service_target_agent.go:1488 still reads "$ref services never persist resolved defaults to azure.yaml, so deploy applies the extension defaults here to keep $ref and inline services consistent". After this change no service shape persists resolved defaults during preprovision/predeploy, so that fallback is now the only place defaults get applied for every service, not just the $ref ones. Rewording it would stop a future reader from assuming inline services still carry persisted values and reintroducing the write.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/listen.go Outdated
Copilot AI review requested due to automatic review settings August 4, 2026 05:57

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-reviewed at e2be080. My earlier comment about the discarded return values from SetAgentContainerSettings is addressed: it now returns only error, the doc comment no longer advertises a persistence target, and both the caller in listen.go and the test are updated to match. Confirmed listen.go is the only production caller, so nothing else loses the path/value pair.

Verified against the head commit locally: go build ./..., go vet, and go test ./internal/project ./internal/cmd -count=1 all pass.

@trangevi
trangevi merged commit 790897d into main Aug 4, 2026
30 checks passed
@huimiu
huimiu deleted the hui/fix-ai-agents-yaml-format branch August 5, 2026 00:14
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.

[Issue] azure.ai.agents extension changes the format of existing azure.yaml file

4 participants