Skip to content

Python: fix AG-UI service-session snapshot replay - #7770

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 11 commits into
microsoft:mainfrom
PratikWayase:fix/7710-agui-snapshot-block
Aug 26, 2026
Merged

Python: fix AG-UI service-session snapshot replay#7770
Eduard van Valkenburg (eavanvalkenburg) merged 11 commits into
microsoft:mainfrom
PratikWayase:fix/7710-agui-snapshot-block

Conversation

@PratikWayase

@PratikWayase pratik wayase (PratikWayase) commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

When AgentFrameworkAgent combines use_service_session=True with a snapshot_store, the provider service session must remain the sole authority for prior provider history. Replaying the AG-UI snapshot alongside an existing Foundry conversation or response ID can send historical assistant messages or tool results twice, causing Responses API validation failures.

AG-UI threadId and runId values are client-owned protocol correlation IDs; they are not inherently provider conversation identifiers. This change keeps complete backend-owned snapshots for AG-UI hydration, sends only validated incremental input to the provider, and persists the provider continuation privately.

Description & Review Guide

  • What are the major changes?

    • Split service-session requests into a validated provider suffix and a complete persisted snapshot using the existing canonical snapshot reconstruction and trust filtering.
    • Support full, incremental, ID-less, stale, truncated, tool-result, approval, and generic input_required continuation shapes.
    • Persist provider conversation/response IDs as private snapshot continuation state instead of conflating them with the AG-UI Thread ID.
    • In provider-owned mode, create a provider conversation through create_conversation() when supported; otherwise persist the provider-issued response ID for subsequent previous_response_id continuation.
    • Add explicit service_session_id_from_thread_id=True compatibility behavior for applications that intentionally use a provider continuation ID as their AG-UI Thread ID.
    • Add deterministic AG-UI → OpenAIChatClient → local Responses host coverage, explicit Agent Framework Message/Content history coverage, and live Foundry Hosted Agent tests for pre-created and backend-created conversations.
  • What is the impact of these changes?

    • Foundry Hosted Agents and other service-session providers receive only the current continuation input.
    • Native AG-UI clients can retain their own UUID or application-defined Thread IDs while the backend privately manages provider conversations or response chains.
    • Applications intentionally sharing a provider ID as threadId can preserve that behavior through the explicit compatibility option.
    • AG-UI clients retain complete snapshot hydration and persistence, while non-service-session behavior remains snapshot-authoritative.
  • What do you want reviewers to focus on?

    • Provider suffix validation for ID-less, stale, truncated, tool-result, and resume continuations.
    • Separation between client-owned AG-UI IDs, provider continuation IDs, provider-bound messages, and persisted UI snapshots.
    • Conversation-mode and response-mode behavior, including private restoration of provider continuation state.
    • The deterministic local Responses boundary tests and live two-turn Foundry Hosted Agent coverage.

Related Issue

Fixes #7710

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue.
  • This is not a breaking change.

Copilot AI balanced review requested due to automatic review settings August 19, 2026 18:24
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 19, 2026
@github-actions github-actions Bot changed the title fix(python): separate provider input from UI snapshot in AG-UI service-session mode Python: fix(python): separate provider input from UI snapshot in AG-UI service-session mode Aug 19, 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.

Pull request overview

Separates service-managed provider history from AG-UI snapshot history.

Changes:

  • Prevents stored snapshot replay into service-session provider calls.
  • Reconstructs full snapshots for UI hydration.
  • Adds split-authority regression coverage.

Reviewed changes

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

File Description
_agent_run.py Separates provider input and persisted snapshots.
test_snapshots.py Tests incremental provider input and full snapshot history.

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

Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Outdated
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Outdated
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py
@chetantoshniwal

Copy link
Copy Markdown
Contributor

/review

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (3 commit(s)): 3f0ac0ba31ed, 7d51557ce79c, 35527333f272
Model: gpt-5.6-sol

Overview

The review found 3 verified inline finding(s).

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (1 high, 2 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py

Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Outdated
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Outdated
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _agent.py48295%82, 145
   _agent_run.py147414790%161, 221, 240, 287, 305, 321–322, 444, 497–498, 505, 614, 618, 620, 637, 664–665, 719, 748, 762, 766, 770, 773, 778, 783, 795, 802–808, 819, 833, 840, 850, 865, 868, 900, 935, 959, 972, 1021, 1039, 1041, 1067, 1069, 1071, 1074–1078, 1102, 1133, 1169, 1224–1225, 1267, 1281, 1326–1332, 1341, 1349, 1377, 1399, 1403, 1406, 1408, 1468–1469, 1475–1481, 1584, 1588–1589, 1592, 1597–1598, 1601, 1607–1608, 1612–1614, 1632–1634, 1659–1660, 1683–1684, 1697, 1739–1741, 1752–1754, 1756, 1770–1772, 1900, 1908, 1938, 1942, 1987, 2147–2148, 2230, 2339, 2344, 2416, 2418, 2425, 2441, 2446, 2503, 2508, 2512, 2556, 2602, 2677, 2822, 2860, 2868, 2870, 2873, 2879, 2934, 2937, 2947–2948, 2955, 3002
   _run_common.py6623095%100, 175–176, 178, 180, 183, 189, 191, 205, 212, 236–237, 250, 269, 292–294, 305, 349, 361, 369, 372, 560, 581, 875–876, 1200–1201, 1267, 1270
   _snapshots.py83495%139, 222, 233–234
TOTAL48227448490% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9760 36 💤 0 ❌ 0 🔥 2m 38s ⏱️

Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Outdated
Comment thread python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py Outdated
Comment thread python/packages/ag-ui/tests/ag_ui/test_snapshots.py Outdated
@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) changed the title Python: fix(python): separate provider input from UI snapshot in AG-UI service-session mode Python: fix AG-UI service-session snapshot replay Aug 26, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Aug 26, 2026
Merged via the queue into microsoft:main with commit b5e8ae9 Aug 26, 2026
36 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ag-ui Usage: [Issues, PRs], Target: AG-UI protocol integration documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: AG-UI snapshot replay with service sessions blocks Foundry Hosted Agents

6 participants