Python: Prevent replayed history from being re-persisted by CosmosHistoryProvider - #8269
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits intoSep 11, 2026
Conversation
WhaleTech (ryo-whaletech)
temporarily deployed
to
github-app-auth
September 10, 2026 18:21 — with
GitHub Actions
Inactive
WhaleTech (ryo-whaletech)
temporarily deployed
to
github-app-auth
September 10, 2026 18:21 — with
GitHub Actions
Inactive
Copilot started reviewing on behalf of
WhaleTech (ryo-whaletech)
September 10, 2026 18:22
View session
WhaleTech (ryo-whaletech)
temporarily deployed
to
github-app-auth
September 10, 2026 18:22 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation follows the established history-provider pattern and is covered by focused regression tests.
Pull request overview
Prevents duplicate Cosmos history growth when callers replay accumulated transcripts.
Changes:
- Filters incoming messages against session/source-scoped history.
- Skips writes for exact replays.
- Adds regression coverage for replay scenarios.
File summaries
| File | Description |
|---|---|
python/packages/azure-cosmos/agent_framework_azure_cosmos/_history_provider.py |
Persists only genuinely new messages. |
python/packages/azure-cosmos/tests/test_cosmos_history_provider.py |
Tests prefix and exact replay behavior. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
@microsoft-github-policy-service agree |
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Sep 11, 2026
Eduard van Valkenburg (eavanvalkenburg)
enabled auto-merge
September 11, 2026 09:06
Eduard van Valkenburg (eavanvalkenburg)
deployed
to
github-app-auth
September 11, 2026 09:07 — with
GitHub Actions
Active
This branch was successfully deployed
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 & Context
CosmosHistoryProvider.save_messages()currently upserts every supplied message under a fresh document ID. When a caller supplies a full accumulated transcript, the provider writes the already-persisted prefix again, causing silent duplicate and potentially superlinear persistent-history growth.The core history contract already handles both append-only input and full-transcript replay through
filter_new_messages(). Applying the same behavior to Cosmos closes a remaining provider-specific instance of the history replay problem addressed in #7242.Description & Review Guide
CosmosHistoryProvider.save_messages()now reads the existing history for the same session and source, appliesfilter_new_messages(), returns when the incoming sequence is an exact replay, and builds Cosmos batch operations only for genuinely new messages. Deterministic regression tests exercise the actualquery_itemsseam and verify both that prefix replay writes onlyCfor existing[A, B]plus incoming[A, B, C], and that an exact replay writes nothing.Related Issue
Fixes #8268
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.