Python: fix: preserve synthetic compaction summaries - #7944
Python: fix: preserve synthetic compaction summaries#7944Patel Namraa (Namraa310806) wants to merge 5 commits into
Conversation
| last_sid = fallback_sid | ||
| for message in projected: | ||
| # For new synthetic messages, use the last known source; for original messages, use their tracked source | ||
| sid = source_by_id.get(id(message), last_sid) |
There was a problem hiding this comment.
Could we carry the summarized messages' _attribution.origin_session_ids onto each synthetic replacement before appending it here? With SummarizationStrategy, cross-session memory can be collapsed into a new assistant message whose _attribution is absent. CrossSessionObserver then skips it, so malicious originated content crosses into the primary model without the governance signal. Aggregating the original messages' source and origin IDs into the replacement would preserve the trust boundary while keeping the summary.
There was a problem hiding this comment.
Thanks for catching this. I hadn't accounted for the provenance carried by _attribution.origin_session_ids on the messages being summarized. I'll update the implementation so synthetic replacement messages inherit the aggregated origin session IDs from the messages they replace, and I'll add regression coverage for the cross-session case.
Resolved merge conflict in _compaction.py by combining both approaches: - Use upstream's _run_compaction_strategy helper for consistency - Preserve local branch's source tracking logic for message attribution after compaction
Motivation & Context
CompactionProvider.before_runcan lose synthetic summary messages created by replacement-based compaction strategies such asToolResultCompactionStrategyandSummarizationStrategy.These strategies create new
Messageobjects to replace messages that are excluded during compaction. However,before_runwas only filtering the existing messages incontext.context_messagesusing object identity. Since the newly created summary messages were not part of those original source lists, they were silently discarded during reconciliation.This could cause the original tool results or conversation history to be removed without retaining the summary that was supposed to replace them.
Fixes #7943.
Description & Review Guide
What are the major changes?
CompactionProvider.before_runto track the source of existing messages before running the compaction strategy.context.context_messagesbuckets from the projected message list after compaction instead of only filtering the original buckets.ToolResultCompactionStrategyandSummarizationStrategy.What is the impact of these changes?
before_strategycompaction are no longer silently dropped.What do you want reviewers to focus on?
CompactionProvider.before_run, especially how existing messages and newly created synthetic messages are assigned back tocontext.context_messages.before_runreconciliation.Related Issue
Fixes #7943
Contribution Checklist