Skip to content

feat(ai): add State Store inspection and item management - #10106

Open
Wei Meng (m5i-work) wants to merge 7 commits into
mainfrom
m5i/10081-state-stores
Open

Wei Meng (m5i-work) wants to merge 7 commits into
mainfrom
m5i/10081-state-stores

Conversation

@m5i-work

@m5i-work Wei Meng (m5i-work) commented Sep 21, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #10081.

Add azd ai agent state-stores support for the publicly documented durable State Store for Microsoft Foundry hosted agents (public preview), to inspect existing stores and manage their JSON object items:

state-stores list
state-stores select [store-name]
state-stores show [store-name]
state-stores items list
state-stores items show <key>
state-stores items set <key>
state-stores items delete <key>
  • Reuse agent_api.AgentClient, with focused State Store operations/models rather than a new client.
  • Save one active store per project endpoint and deployed agent name. Explicit targets do not change selection; protocol and version do not partition it.
  • Support project/service resolution and explicit endpoints outside a project. Honor --environment without falling back to another environment's deployment metadata.
  • Accept object-valued inline/file/stdin input while preserving JSON number precision. set upserts via one PUT and replaces the complete value/tag map.
  • Preserve If-Match, reject stale writes without an unconditional fallback, and require delete confirmation or --yes.
  • Add forward-only, single-page cursor pagination (--after + --limit, with --order), JSON/table output, a paged store picker, documentation, help snapshots, and regression tests.

Store creation/update/deletion, create-only item writes, delegated identity flags, and list-time tag filtering are out of scope.

Size policy: The public service limits state 1 MB of serialized JSON per item value. The code uses the service's byte definition, 1,048,576 bytes (1 MiB), as one shared constant for value validation and the raw-input guard—no arbitrary multiplier. The raw guard conservatively includes whitespace, so larger formatted input must be compacted externally first. The serialized-value check accounts for JSON escaping and excludes the request envelope and tags; undocumented larger-value behavior is not assumed.

Validation

From the agents extension module:

  • go build
  • go fix ./...
  • go test ./... -short -count=1
  • Focused race tests for State Store commands/client, configuration validation, and agent resolution
  • golangci-lint v2.11.4 on the affected command/API packages: 0 issues
  • Spell checks and git diff --check

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
23 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 Sep 21, 2026
@github-actions github-actions Bot added the ext-foundry azure.ai.{agents,connections,inspector,projects,routines,skills,toolboxes}, microsoft.foundry label Sep 22, 2026
@m5i-work
Wei Meng (m5i-work) marked this pull request as ready for review September 22, 2026 06:30
Copilot AI balanced review requested due to automatic review settings September 22, 2026 06:30
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
23 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

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 Rick Winter (@RickWinter) and Kristen Womack (@kristenwomack) to let us know.

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.

Copilot review overview

🟡 Changes recommended

Input must be size-bounded, error guidance corrected, and the required interactive CLI scenario added.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 2 Low severity

Open (3)
What changed in this PR

Adds State Store inspection and item management to the Azure AI Agents extension.

Changes:

  • Adds list, select, show, set, and delete commands with pagination and ETag support.
  • Persists active-store selection per endpoint and agent.
  • Adds documentation, help snapshots, and unit coverage.
File Description
README.md Introduces State Store documentation.
state_store_operations.go Implements State Store REST operations.
state_store_operations_test.go Tests requests, responses, and privacy behavior.
state_store_models.go Defines API models and pagination options.
codes.go Adds structured error codes.
TestAgentHelp-state-stores.snap Captures root State Store help.
TestAgentHelp-state-stores_show.snap Captures store-show help.
TestAgentHelp-state-stores_select.snap Captures store-selection help.
TestAgentHelp-state-stores_list.snap Captures store-list help.
TestAgentHelp-state-stores_items.snap Captures item command help.
TestAgentHelp-state-stores_items_show.snap Captures item-show help.
TestAgentHelp-state-stores_items_set.snap Captures item-set help.
TestAgentHelp-state-stores_items_list.snap Captures item-list help.
TestAgentHelp-state-stores_items_delete.snap Captures item-delete help.
TestAgentHelp-root.snap Adds State Stores to root help.
state_stores.go Defines commands, flags, execution, and errors.
state_stores_test.go Tests command contracts and behavior.
state_store_output.go Implements responsive table output.
state_store_items.go Handles item input and mutations.
state_store_context.go Resolves targets and persists selection.
state_store_context_test.go Tests targeting, selection, and pagination.
root.go Registers the new command group.
helpers.go Supports explicit environment resolution.
config_store.go Allows persisted State Store selections.
config_store_test.go Tests the new configuration field.
go.mod Adds the required indirect test dependency.
docs/​state-stores.md Documents commands, safety, and pagination.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/state_store_items.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/root.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/state_stores.go Outdated
Copilot AI review requested due to automatic review settings September 22, 2026 07:50

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.

Copilot review overview

🟡 Changes recommended

The REST contract mismatch, unsafe terminal rendering, and misleading omitted-tag output should be resolved before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
Resolved since last review (2)
Previously missed (4)

In code that hasn't changed since last review

Medium severity Encode control characters in store picker labels

cli/​azd/​extensions/​azure.ai.agents/​internal/​cmd/​state_store_context.go:156

Store names come from the service and the contract permits arbitrary strings beyond length bounds. Passing them directly as prompt labels allows embedded terminal control sequences to be rendered when the picker opens. Encode control characters in Label while keeping the original name in Value/selection logic.

Medium severity Sanitize terminal control characters in table output

cli/​azd/​extensions/​azure.ai.agents/​internal/​cmd/​state_store_output.go:34

These table columns render .Name verbatim for both service-provided store names and item keys. PrettyTableFormatter preserves terminal escape-bearing values in full/compact layouts, so a crafted key can inject terminal control sequences during --output table. Encode control characters for display while retaining raw values in JSON output and API operations.

Medium severity Hide Tags detail when write responses omit tags

cli/​azd/​extensions/​azure.ai.agents/​internal/​cmd/​state_store_output.go:92

Write responses omit tags, so itemDetail.Tags is nil even when the request successfully set tags; this prints Tags: null and falsely suggests the resulting item has no tags. Only render the Tags detail when the response actually includes it.

Medium severity Preserve omitted tags in default JSON output

cli/​azd/​extensions/​azure.ai.agents/​internal/​pkg/​agents/​agent_api/​state_store_models.go:29

Write responses intentionally omit tags (the new response test exercises this), but this field re-encodes an omitted property as "tags": null in the default JSON output. After a successful write with --tag, that looks like the tags were cleared. Preserve the service omission in JSON output.

Copilot AI review requested due to automatic review settings September 22, 2026 08:37

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.

Copilot review overview

🔵 Needs a closer look

Transport-level write failures omit the required guidance to inspect potentially committed state before retrying.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Add retry safety guidance for transport failures in item writes

cli/​azd/​extensions/​azure.ai.agents/​internal/​cmd/​state_stores.go:284

Non-HTTP write failures still lose the write-safety guidance. A timeout or connection reset from pipeline.Do reaches this fallback rather than the status-code branch, even though the service may already have committed the PUT/DELETE; the resulting internal error has no suggestion and a retry can overwrite or misreport state. Preserve auth/cancellation guidance, but classify transport failures from items set and items delete with “check the item's current state before retrying,” and cover that path with a transport-error test.

Copilot AI review requested due to automatic review settings September 22, 2026 09:25
@m5i-work

Copy link
Copy Markdown
Member Author

Latest Copilot follow-up is in 8ca7176: display-only identifier escaping, omitted response-tag preservation, and uncertain-write transport/decode guidance with focused tests. Full extension short tests, State Store race tests, scoped lint, spell checks, and diff checks pass. CI triage is documented in the PR description: GitHub Tier 1 reproduces on the exact base commit; ADO Tier 2 hit the shared subscription deployment-history quota before deployment. No retained State Store test resources were changed.

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.

Copilot review overview

🟡 Changes recommended

JSON tag presence is currently ambiguous, and output failures can misreport already-committed writes as failed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Report committed mutation when output writing fails

cli/​azd/​extensions/​azure.ai.agents/​internal/​cmd/​state_stores.go:301

Handle output failures differently after items set and items delete. At this point execute has already received and decoded a successful service response, so returning a generic stdout error can lead automation to retry a mutation that already committed. Report that the write succeeded but its result could not be written, and advise inspecting current state before retrying.

Copilot AI review requested due to automatic review settings September 22, 2026 09:35

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.

Copilot review overview

🟢 Approval recommended

The implementation aligns with the stated contract and includes strong API, command, boundary, documentation, and regression coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@glharper Glenn Harper (glharper) 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.

Two State Store integration gaps remain in #10106.

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.

Has this gone through an experience review? A new set of commands like this needs to go through that process

Copilot AI review requested due to automatic review settings September 23, 2026 02:27

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.

Copilot review overview

🔵 Needs a closer look

Four moderate issues remain in deletion handling, tag validation, selection cleanup, and scenario cleanup reliability.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

azure.ai.agents PR build

Note

This is an unsigned development build. Install it only if you trust this PR.

Install the extension:

azd ext install "https://azuresdkartifacts.z5.web.core.windows.net/azd/extensions/pr/10106/azure-ai-agents.zip"
  • Version: 1.0.0-beta.16.pr.10106.6871053
  • Merge commit: 45432fb

This branch has not been deployed

No deployments
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 ext-foundry azure.ai.{agents,connections,inspector,projects,routines,skills,toolboxes}, microsoft.foundry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support State Store inspection and item management in azd ai agent

4 participants