From 7dacc2ed3567c8e7a2db7ad828b6810c6f9a8a7d Mon Sep 17 00:00:00 2001 From: Erosika Date: Tue, 8 Sep 2026 16:12:37 -0400 Subject: [PATCH] fix(honcho): describe what _seen_gateway_accounts can list The docstring said grouping session rows by (source, user_id) enumerates every account the gateway handled. record_gateway_session_peer overwrites a row's user_id, so a shared thread keeps only its last author. The docstring now says that, and a test pins it. --- plugins/memory/honcho/cli.py | 4 ++-- tests/honcho_plugin/test_peers_map.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/memory/honcho/cli.py b/plugins/memory/honcho/cli.py index 22281c24ef..672c7f23e3 100644 --- a/plugins/memory/honcho/cli.py +++ b/plugins/memory/honcho/cli.py @@ -1060,8 +1060,8 @@ def _state_db_path() -> Path: def _seen_gateway_accounts(db_path: Path) -> list[dict]: """Gateway accounts recorded in state.db, most recent first; bot authors are skipped. - The gateway stamps each session row with its routing peer, so grouping rows by - (source, user_id) enumerates every account it has handled. + A session row keeps only its last routing peer, so a shared thread contributes + its most recent author and not every participant. """ if not db_path.exists(): return [] diff --git a/tests/honcho_plugin/test_peers_map.py b/tests/honcho_plugin/test_peers_map.py index f89f2726be..8943e036c2 100644 --- a/tests/honcho_plugin/test_peers_map.py +++ b/tests/honcho_plugin/test_peers_map.py @@ -51,6 +51,15 @@ class TestSeenGatewayAccounts: {"platform": "telegram", "user_id": "111", "user_id_alt": "", "label": "eri", "sessions": 2, "profiles": []}, ] + def test_shared_session_lists_only_its_last_author(self, tmp_path): + """record_gateway_session_peer overwrites the row's user_id, so earlier authors are gone.""" + from hermes_state import SessionDB + + db = SessionDB(tmp_path / "state.db") + for uid in ("alice", "bob"): + db.record_gateway_session_peer("shared", source="telegram", user_id=uid, session_key="telegram:group:1") + assert [a["user_id"] for a in _seen_gateway_accounts(tmp_path / "state.db")] == ["bob"] + def test_missing_db_or_table_returns_empty(self, tmp_path): assert _seen_gateway_accounts(tmp_path / "absent.db") == [] sqlite3.connect(tmp_path / "empty.db").close()