Skip to content

The agent that grows with you

fix(gateway): document and colocate summary replay coverage

Yuan Licd5dfc7aa394
diff --git a/gateway/run.py b/gateway/run.py
index befaf6cf205..f64f7d1fd9c 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -1302,6 +1302,7 @@ def _build_gateway_agent_history(
continue
# Keep user timestamps for the stale-dangerous-confirmation stripper in agent/replay_cleanup.py.
entry = _build_replay_entry(role, content, msg, preserve_timestamp=(role == "user"))
+ # Compaction sent summaries unstamped; stamping them on replay breaks the cached prefix.
if inject_timestamps and role == "user" and isinstance(content, str) and not msg.get("_compressed_summary"):
rendered = _render_msg_ts(content, replay_timestamp, tz=_msg_tz)
# Preserve only a sidecar matching the complete rendered message,
diff --git a/tests/gateway/test_gateway_history_persistence_stamp.py b/tests/gateway/test_gateway_history_persistence_stamp.py
index a4c46f0d943..1cc16697973 100644
--- a/tests/gateway/test_gateway_history_persistence_stamp.py
+++ b/tests/gateway/test_gateway_history_persistence_stamp.py
@@ -23,16 +23,3 @@ def test_db_flush_collect_does_not_recollect_gateway_history_rows():
_rows, msgs = _db_flush_collect(agent, list(history) + [new], None)
assert msgs == [new]
-
-
-def test_compaction_summary_replays_without_timestamp():
- summary = {"role": "user", "content": "[CONTEXT COMPACTION] prior turns", "timestamp": 1.0, "_compressed_summary": True}
- history, _ = _build_gateway_agent_history([summary], inject_timestamps=True)
- assert history[0]["content"] == summary["content"]
-
-
-def test_regular_user_message_still_replays_with_timestamp():
- message = {"role": "user", "content": "what is next?", "timestamp": 1.0}
- history, _ = _build_gateway_agent_history([message], inject_timestamps=True)
- assert history[0]["content"].endswith(message["content"])
- assert history[0]["content"] != message["content"]
diff --git a/tests/gateway/test_message_timestamps.py b/tests/gateway/test_message_timestamps.py
index 09e6ea7037e..746a19615b9 100644
--- a/tests/gateway/test_message_timestamps.py
+++ b/tests/gateway/test_message_timestamps.py
@@ -202,3 +202,25 @@ def test_build_history_injects_only_when_enabled():
assert agent_history[0]["content"].endswith("hello")
# Assistant message is never timestamped.
assert agent_history[1]["content"] == "hi"
+
+
+def test_compaction_summary_replays_without_timestamp():
+ from gateway.run import _build_gateway_agent_history
+
+ summary = {
+ "role": "user",
+ "content": "[CONTEXT COMPACTION] prior turns",
+ "timestamp": 1.0,
+ "_compressed_summary": True,
+ }
+ history, _ = _build_gateway_agent_history([summary], inject_timestamps=True)
+ assert history[0]["content"] == summary["content"]
+
+
+def test_regular_user_message_still_replays_with_timestamp():
+ from gateway.run import _build_gateway_agent_history
+
+ message = {"role": "user", "content": "what is next?", "timestamp": 1.0}
+ history, _ = _build_gateway_agent_history([message], inject_timestamps=True)
+ assert history[0]["content"].endswith(message["content"])
+ assert history[0]["content"] != message["content"]