Skip to content

Clone AdditionalProperties in AlwaysApprove tool-approval responses#741

Open
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:clone-additionalproperties-alwaysapprove
Open

Clone AdditionalProperties in AlwaysApprove tool-approval responses#741
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:clone-additionalproperties-alwaysapprove

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

ToolApprovalRequestContent.AlwaysApproveToolResponse and AlwaysApproveToolWithArgumentsResponse set ContentHeader{AdditionalProperties: t.AdditionalProperties}, copying the request's map by reference. The request and the emitted response therefore share one map instance, so mutating the request's AdditionalProperties after creating the response silently leaks into the response.

This changes both helpers to maps.Clone(t.AdditionalProperties) so the response carries an independent snapshot. maps.Clone(nil) returns nil, so no nil guard is needed; maps is already imported.

Why

CreateResponse already clones with maps.Clone, and TestToolApprovalRequestContent_CreateResponseSnapshotsFunctionCall asserts that a post-response mutation of the request must not affect the response. The AlwaysApprove helpers violated that same contract. This aligns them with the response-is-a-snapshot semantics used across the .NET and Python SDKs, where approval responses capture request metadata by value rather than aliasing the live request.

How tested

Added TestToolApprovalRequestContent_AlwaysApproveSnapshotsAdditionalProperties, which builds a request with AdditionalProperties, calls each AlwaysApprove helper, mutates the request's map afterward, and asserts the response value is unchanged. It fails before the fix (both subtests) and passes after. go build ./..., go vet ./message/..., and go test ./message/... are green.

@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 24, 2026 03:59
Copilot AI review requested due to automatic review settings July 24, 2026 03:59

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 fixes map aliasing in tool-approval “AlwaysApprove” response helpers so that emitted responses snapshot AdditionalProperties rather than sharing the same map instance with the request.

Changes:

  • Update AlwaysApproveToolResponse and AlwaysApproveToolWithArgumentsResponse to use maps.Clone(t.AdditionalProperties) when populating response headers.
  • Add a regression test ensuring post-response mutation of the request’s AdditionalProperties does not affect the always-approve responses.

Reviewed changes

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

File Description
message/content.go Clones AdditionalProperties when building always-approve approval response wrappers to avoid shared-map aliasing.
message/content_test.go Adds coverage to assert always-approve helpers snapshot AdditionalProperties (matching existing CreateResponse semantics).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 24, 2026
@github-actions

This comment has been minimized.

AlwaysApproveToolResponse and AlwaysApproveToolWithArgumentsResponse
copied the request's AdditionalProperties map by reference, so the
emitted response shared one map instance with the request. Mutating the
request afterward would leak into the already-created response, matching
neither CreateResponse (which uses maps.Clone) nor the .NET/Python
snapshot semantics. Clone the map so the response is an independent
snapshot.
@PratikDhanave
PratikDhanave force-pushed the clone-additionalproperties-alwaysapprove branch from ffc15d3 to b8a15a9 Compare July 24, 2026 09:30
@github-actions

Copy link
Copy Markdown
Contributor

Parity Review — Approved

This PR fixes a reference-aliasing bug in ToolApprovalRequestContent.AlwaysApproveToolResponse and AlwaysApproveToolWithArgumentsResponse by cloning AdditionalProperties with maps.Clone() instead of sharing the map by reference.

Scope: message/ package — behavioral bug fix only. No exported function/method signatures were added, removed, or changed.

Cross-repo parity: The PR description correctly identifies that this change restores alignment with .NET and Python SDK semantics, where approval responses capture request metadata as an independent snapshot rather than aliasing the live request object. CreateResponse already used this pattern in Go; this PR extends it consistently to the AlwaysApprove helpers.

Labels: public-api-change is not warranted — the exported API surface is unchanged. The existing parity-approved label remains appropriate.

No parity issues found.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent · 18.2 AIC · ⌖ 4.6 AIC · ⊞ 5.9K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants