Skip to content

[dotnet-port-fixes] Preserve tool approval message ordering - #1012

Open
Quim Muntal (qmuntal) wants to merge 1 commit into
mainfrom
dotnet-port-fixes/approval-message-ordering
Open

[dotnet-port-fixes] Preserve tool approval message ordering#1012
Quim Muntal (qmuntal) wants to merge 1 commit into
mainfrom
dotnet-port-fixes/approval-message-ordering

Conversation

@qmuntal

Copy link
Copy Markdown
Member

Summary

  • keep reconstructed function calls and results at the original approval anchor, ahead of trailing caller content
  • distinguish service-managed history from client-managed history so only the latter resends the assistant function call
  • cover trailing messages and residual content that shares an approval-response message

Upstream

Ports Fix FICC tool_calls/tool ordering with approvals and service-managed chat history (#7617) by westey-m.

Testing

  • go test ./agent/harness/toolautocall

Port the approval anchor handling from dotnet/extensions#7617 so reconstructed function calls and results remain adjacent ahead of trailing caller content in both service-managed and client-managed histories.`n`nUpstream: dotnet/extensions#7617
Copilot AI lite review requested due to automatic review settings September 7, 2026 10:27
@qmuntal
Quim Muntal (qmuntal) requested a review from a team as a code owner September 7, 2026 10:27
@github-actions github-actions Bot added area:agent Changes files in the agent area size:large At most 300 changed lines across at most 10 files labels Sep 7, 2026

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 ordering fix is well-scoped, preserves existing processing semantics, and is covered by new/updated unit tests for both service-managed and client-managed history cases.

Review tier: Lite
Findings: None

What changed in this PR

This PR ports and applies fixes to the tool-autocall approval workflow so that reconstructed function calls/results are anchored at the original approval location (ahead of trailing caller content), and so that provider/service-managed conversation history is treated differently from client-managed history when deciding what to resend downstream.

Changes:

  • Compute an “approval anchor” insertion index and use slices.Insert to place generated tool result messages before trailing user/caller content.
  • Distinguish service-managed vs client-managed history (via WithServiceID / Session.ServiceID) so only client-managed history re-inserts reconstructed assistant function-call messages into downstream history.
  • Add/adjust tests to cover trailing-message ordering and residual-content cases for both history modes.
File Description
agent/​harness/​toolautocall/​autocall.go Computes an approval-anchor insertion point; inserts reconstructed approval artifacts at that anchor; skips resending reconstructed call history when the service manages conversation state.
agent/​harness/​toolautocall/​autocall_approval_test.go Updates helper to run under provider-managed conversation mode by default and adds targeted ordering/regression tests for trailing/residual content scenarios.

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

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Scope: internal-only (unexported helpers in agent/harness/toolautocall); no exported Go API added, removed, or changed.

Changed Go contract: None. processToolApprovalResponses, hasAnyApprovalContent/messageHasFunctionApproval/messageContainsOnlyFunctionApprovals are unexported. The only exported symbols already existed (agent.WithServiceID, agent.Session.ServiceID) and are merely consumed to compute serviceManagedHistory; no signature, default, or option shape visible to callers changed.

Upstream evidence reviewed: dotnet/extensions PR #7617 (src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs), specifically HasAnyFunctionApproval, MessageContainsOnlyFunctionApprovals, and the rewritten ProcessFunctionApprovalResponses/ProcessFunctionCallsAsync/InvokeApprovedFunctionApprovalResponsesAsync insert-index logic, plus FunctionInvokingChatClientApprovalsTests.cs.

Result: aligned. The Go port faithfully mirrors the .NET fix: it computes the same "approval anchor" (lastApprovalIdx/trailingMessageCount) before extraction, inserts reconstructed tool-call messages only when history is client-managed (serviceManagedHistory mirrors .NET's hasConversationId/!string.IsNullOrWhiteSpace(options?.ConversationId)), and inserts rejected/approved function results at the same anchor so they precede trailing caller content — matching .NET's insertIndex/InsertRange behavior. New Go tests (TestFunctionInvoking_ApprovedResultPrecedesTrailingMessageWithServiceManagedHistory, ...ClientManagedHistory, ...ResidualContentWithClientManagedHistory) correspond to the added .NET approval-ordering test scenarios. No behavioral divergence or missing feature gate was found; no public-api-change label needed.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • github.com
  • proxy.golang.org

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

network:
  allowed:
    - defaults
    - "github.com"
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent for #1012 · copilot · auto · 40.2 AIC · ⌖ 7.56 AIC · ⊞ 9.5K ·

@github-actions github-actions Bot added kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure pending-auto-risk Automatic risk classification is in progress risk:medium Contained production impact requiring normal review depth and removed pending-auto-risk Automatic risk classification is in progress labels Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Changes files in the agent area kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure risk:medium Contained production impact requiring normal review depth size:large At most 300 changed lines across at most 10 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants