Python: deduplicate MessagePack FileHistoryProvider writes - #8224
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoSep 10, 2026
Conversation
CoralGarden52
temporarily deployed
to
github-app-auth
September 10, 2026 09:29 — with
GitHub Actions
Inactive
CoralGarden52
temporarily deployed
to
github-app-auth
September 10, 2026 09:29 — with
GitHub Actions
Inactive
CoralGarden52
temporarily deployed
to
github-app-auth
September 10, 2026 09:29 — with
GitHub Actions
Inactive
CoralGarden52
temporarily deployed
to
github-app-auth
September 10, 2026 09:30 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation preserves locking and file-format behavior with adequate regression coverage.
Pull request overview
Aligns MessagePack history persistence with JSONL transcript deduplication.
Changes:
- Deduplicates MessagePack records before appending.
- Extends regression tests across both formats.
File summaries
| File | Description |
|---|---|
python/packages/core/agent_framework/_sessions.py |
Filters replayed MessagePack messages under the session lock. |
python/packages/core/tests/core/test_sessions.py |
Adds format-parameterized deduplication coverage. |
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.
CoralGarden52
force-pushed
the
fix/file-history-msgpack-dedup
branch
from
September 10, 2026 09:34
a932561 to
f39fde2
Compare
CoralGarden52
temporarily deployed
to
github-app-auth
September 10, 2026 09:34 — with
GitHub Actions
Inactive
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Sep 10, 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 & Context
FileHistoryProvidersupports JSONL by default and length-prefixed MessagePack as an opt-in format. The existing deduplication fix in #7242 appliesfilter_new_messages()to the JSONL write path, but the MessagePack write path appends every supplied message. As a result, a client that replays a complete transcript on every turn gets different persistence and replay behavior depending only on the serialization format.This is a follow-up to #7242 and fixes a real, deterministic persistence bug. On upstream
mainat018056a52, I reproduced it with a realAgent/AgentSession/FileHistoryProviderlifecycle using a fixed session, ten turns, unique assistant responses, and a complete transcript supplied on every turn. Before this change, the stored history was:The baseline Agent client-message counts were
[1, 5, 9, 13, 17, 21, 25, 29, 33, 37]for JSONL and[1, 5, 11, 19, 29, 41, 55, 71, 89, 109]for MessagePack. No exception was raised; loading the session returned repeated turns, increasing storage and later history/model-context size. A delta-only control stored 20 records in both formats, isolating the defect to full-transcript replay.Description & Review Guide
What are the major changes?
filter_new_messages(existing_messages, messages)logic already used by the JSONL path before appending.jsonandmsgpack, including replayed transcripts, repeated writes, suffix-only appends, role-sensitive identity, and legitimate identical messages within one batch.What is the impact of these changes?
20 records / 3,061 bytesand MessagePack20 records / 2,521 bytes; client-message counts matched in both runs:[1, 5, 9, 13, 17, 21, 25, 29, 33, 37].20 records / 2,770 bytesand MessagePack20 records / 2,270 bytesafter the fix.What do you want reviewers to focus on?
filter_new_messages()preserves legitimate duplicate turns within one incoming batch while removing replayed prefixes.The following checks were run on Python 3.12.14:
uv run pytest packages/core/tests/core/test_sessions.py -qpassed on the focused session suite.uv run poe test --package corepassed:5023 passed, 131 skipped, 2 xfailed(the run reported existing warnings).uv run poe syntax --package corepassed both core formatting and lint tasks.uv build --package agent-framework-corecompleted successfully.git diff --checkandgit show --checkpassed.mypy :: coreandzuban :: corepassed through the test-typing task. The aggregatety/pyreflysweeps were blocked by the environment missing the optionalagent_hookspackage, and Pyright could not start because the environment provides Node 12 while the installed Pyright bundle requires newer JavaScript syntax; neither failure reported a diagnostic in the changed implementation.Related Issue
Fixes #8223
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.