Python: (ag-ui): fix approval payloads being re-processed on subsequent conversation turns#4232
Merged
moonbox3 merged 3 commits intomicrosoft:mainfrom Feb 26, 2026
Merged
Conversation
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes AG-UI human-in-the-loop approval payloads being re-processed on subsequent turns by cleaning approval JSON payloads out of the outgoing snapshot and replacing them with the executed tool result, preventing duplicate tool invocations when CopilotKit replays history.
Changes:
- Add
_clean_resolved_approvals_from_snapshotto rewrite tool-role snapshot messages containing approval payloads into the corresponding tool result. - Invoke snapshot cleaning after
_resolve_approval_responsesinrun_agent_streamas a defense-in-depth measure. - Add regression tests covering snapshot cleaning, “no-op” behavior when no approvals exist, prevention of stale approval reprocessing, and ensuring fresh approvals still get processed.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py | Adds snapshot-cleaning logic and calls it after approval resolution to prevent stale approvals from being replayed. |
| python/packages/ag-ui/tests/ag_ui/test_message_hygiene.py | Adds tests validating snapshot cleaning and that cleaned snapshots don’t re-trigger approvals on later turns. |
| python/packages/ag-ui/tests/ag_ui/test_message_adapters.py | Adds a test ensuring a fresh approval still produces a function_approval_response. |
eavanvalkenburg
approved these changes
Feb 25, 2026
TaoChenOSU
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Fixes a bug where approval payloads in ag-ui were being re-executed on subsequent conversation turns, causing duplicate tool invocations and stale approvals to be re-processed.
When a user approves a tool call in ag-ui:
{"accepted": true}) is processed and the tool executesThis caused tools to run multiple times and approval history to become corrupted.
Description
Contribution Checklist