Skip to content

The agent that grows with you

fix(gateway): session.history ships durable row_id stamps

Teknium2e9dcb7c555d
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index a02b01c69cf..fa6ba36e7e3 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -12956,6 +12956,42 @@ def test_session_history_uses_session_profile_db(monkeypatch, tmp_path):
server._sessions.pop("sid", None)
+def test_session_history_ships_durable_row_ids(monkeypatch):
+ """session.history must request row-id stamps — clients resolve truncation
+ targets by content against this projection (#87059 client half)."""
+ seen: dict = {}
+
+ class _Db:
+ def get_messages_as_conversation(self, _key, include_ancestors=False, include_row_ids=False, **_kwargs):
+ seen["include_row_ids"] = include_row_ids
+
+ return [
+ {"role": "user", "content": "hello", "_row_id": 41},
+ {"role": "assistant", "content": "hi"},
+ ]
+
+ server._sessions["rowid-hist-sid"] = {
+ "session_key": "rowid-sess",
+ "history": [],
+ "history_lock": __import__("threading").Lock(),
+ "running": False,
+ "agent": None,
+ "created_at": 1.0,
+ "last_active": 1.0,
+ }
+ monkeypatch.setattr(server, "_get_db", lambda: _Db())
+ try:
+ resp = server.handle_request(
+ {"id": "1", "method": "session.history", "params": {"session_id": "rowid-hist-sid"}}
+ )
+ assert "result" in resp, resp
+ assert seen.get("include_row_ids") is True
+ user_rows = [m for m in resp["result"]["messages"] if m.get("role") == "user"]
+ assert user_rows and user_rows[0].get("row_id") == 41
+ finally:
+ server._sessions.pop("rowid-hist-sid", None)
+
+
def test_session_status_uses_session_profile_db(monkeypatch, tmp_path):
"""session.status must load meta from the session profile state.db."""
profile_home = tmp_path / "profiles" / "mlperf"
diff --git a/tui_gateway/methods_session.py b/tui_gateway/methods_session.py
index bc3579b7940..d7e95edcdc8 100644
--- a/tui_gateway/methods_session.py
+++ b/tui_gateway/methods_session.py
@@ -2493,8 +2493,16 @@ def _(rid, params: dict) -> dict:
with _session_db(session) as db:
if db is not None:
try:
+ # include_row_ids: the durable row id is how clients address
+ # a specific persisted turn (reactions, and the Desktop's
+ # content-based truncation-target resolution — #87059). The
+ # projection in _history_to_messages only forwards row_id
+ # when the row carries a stamp, so an unstamped read here
+ # silently strips the one durable address clients can use.
history = db.get_messages_as_conversation(
- session["session_key"], include_ancestors=True
+ session["session_key"],
+ include_ancestors=True,
+ include_row_ids=True,
)
except Exception:
pass