Skip to content

Commit c1d6b8b

Browse files
committed
fix: stabilize compaction summary timestamps
1 parent a6c1e8f commit c1d6b8b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

pion/session/manager.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,15 @@ def build_context(self) -> list[Message]:
227227
selected.append(entry)
228228
selected.extend(path[compaction_idx + 1 :])
229229

230-
messages: list[Message] = [UserMessage(content=compaction.summary or "")]
230+
# The summary is a deterministic projection of the persisted
231+
# compaction entry. Reusing its timestamp prevents repeated context
232+
# builds (and reloads) from producing different message snapshots.
233+
messages: list[Message] = [
234+
UserMessage(
235+
content=compaction.summary or "",
236+
timestamp=compaction.timestamp,
237+
)
238+
]
231239
messages.extend(
232240
entry.message
233241
for entry in selected

tests/test_session.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ def test_append_and_persistence_round_trip(tmp_path: Path) -> None:
8181
assert len(path.read_text(encoding="utf-8").strip().split("\n")) == 5
8282

8383

84+
def test_compaction_summary_timestamp_is_stable() -> None:
85+
manager = SessionManager()
86+
manager.append_message(_user("before"))
87+
compaction_id = manager.append_compaction("stable summary")
88+
89+
first = manager.build_context()[0]
90+
second = manager.build_context()[0]
91+
92+
assert first.timestamp == manager.get_entry(compaction_id).timestamp
93+
assert second.timestamp == first.timestamp
94+
95+
8496
def test_in_memory_session_writes_nothing(tmp_path: Path) -> None:
8597
manager = SessionManager()
8698
manager.append_message(_user("hello"))

0 commit comments

Comments
 (0)