Skip to content

The agent that grows with you

fix(honcho): derive a bot author's peer from its full id with the runtime digest rule

Erosikab4d7a33b51c1
diff --git a/plugins/memory/honcho/README.md b/plugins/memory/honcho/README.md
index 2a6a9b8c975..f0cb7911c83 100644
--- a/plugins/memory/honcho/README.md
+++ b/plugins/memory/honcho/README.md
@@ -276,7 +276,7 @@ If `sessionPeerPrefix` is `true`, the peer name is prepended: `alice-hermes-agen
#### Bot DMs (`a2aSessions`)
-In bot mode another Hermes profile can DM this agent. The relay marks that turn with author `bot:<profile>`. A gateway platform marks a bot sender with its platform user id and a bot flag. Either way the turn never reaches the human's session. With `a2aSessions: true` (default) the turn is written into `<session>:a2a:<sanitized id>-<8-char digest>`: the sender's message under the sender's peer, the reply under this agent's `aiPeer`. A `bot:<profile>` sender's peer is the `userPeerAliases` entry for `bot:<profile>` if one exists, else the profile name with no `runtimePeerPrefix`, which is the sender's own default `aiPeer` in a shared workspace. A platform bot resolves like any other runtime user: alias, then prefix. `pinUserPeer` never collapses a bot onto `peerName`. A bot whose peer would equal this agent's `aiPeer` is skipped, and so is every bot turn when `a2aSessions: false`. During a bot-authored turn `honcho_conclude` and `honcho_profile` refuse writes, because conclusions and cards describe the human. Recall still reads the human's session only.
+In bot mode another Hermes profile can DM this agent. The relay marks that turn with author `bot:<profile>`. A gateway platform marks a bot sender with its platform user id and a bot flag. Either way the turn never reaches the human's session. With `a2aSessions: true` (default) the turn is written into `<session>:a2a:<sanitized id>-<8-char digest>`: the sender's message under the sender's peer, the reply under this agent's `aiPeer`. A `bot:` sender is identified by its full id, `bot:<profile>` for a profile on this machine or `bot:<connection>/<profile>` for one relayed through a Desktop connection. Its peer is the `userPeerAliases` entry for that full id if one exists, else the id after `bot:` sanitized, with no `runtimePeerPrefix`. When sanitizing changed the id, or the result equals `peerName` or an alias target, a digest suffix is added the same way `runtimePeerPrefix` users get one, so a bot never lands on the operator's peer and two connections' `coder` stay apart. A platform bot resolves like any other runtime user: alias, then prefix. `pinUserPeer` never collapses a bot onto `peerName`. A bot whose peer would equal this agent's `aiPeer` is skipped, and so is every bot turn when `a2aSessions: false`. During a bot-authored turn `honcho_conclude` and `honcho_profile` refuse writes, because conclusions and cards describe the human. Recall still reads the human's session only.
#### What each strategy produces
diff --git a/plugins/memory/honcho/session_peers.py b/plugins/memory/honcho/session_peers.py
index af2f1c3cd77..983ebaa4f3f 100644
--- a/plugins/memory/honcho/session_peers.py
+++ b/plugins/memory/honcho/session_peers.py
@@ -106,17 +106,16 @@ class SessionPeersMixin:
def _peer_id_for_runtime_id(self, runtime_id: str) -> str:
"""Honcho peer ID for one runtime identity: alias first, then prefix, as at session init.
- A ``bot:<profile>`` author maps onto the bare profile name because a cloned profile's aiPeer
- defaults to that name."""
- aliases = getattr(self._config, "user_peer_aliases", {}) if self._config else {}
- if isinstance(aliases, dict):
- alias = aliases.get(runtime_id)
- if isinstance(alias, str) and alias.strip():
- return self._sanitize_id(alias.strip())
+ A ``bot:`` author is keyed by its full id (``bot:<profile>`` or ``bot:<connection>/<profile>``) and,
+ without an alias, its peer is derived from everything after ``bot:`` with the same digest suffix
+ rule as prefixed runtime users, so it never lands on ``peerName`` or an alias target."""
+ alias = self._peer_aliases().get(runtime_id)
+ if isinstance(alias, str) and alias.strip():
+ return self._sanitize_id(alias.strip())
if runtime_id.startswith(BOT_AUTHOR_PREFIX):
- profile = runtime_id[len(BOT_AUTHOR_PREFIX):].strip()
- return self._sanitize_id(profile or runtime_id)
- prefix = getattr(self._config, "runtime_peer_prefix", "") if self._config else ""
+ ident = runtime_id[len(BOT_AUTHOR_PREFIX):].strip()
+ return self._generated_runtime_peer_id("", ident or runtime_id)
+ prefix = self._cfg("runtime_peer_prefix", "")
prefix = prefix.strip() if isinstance(prefix, str) else ""
return self._generated_runtime_peer_id(prefix, runtime_id) if prefix else self._sanitize_id(runtime_id)
diff --git a/tests/honcho_plugin/test_turn_author_peers.py b/tests/honcho_plugin/test_turn_author_peers.py
index 7a0e072c235..c9c2d271ab9 100644
--- a/tests/honcho_plugin/test_turn_author_peers.py
+++ b/tests/honcho_plugin/test_turn_author_peers.py
@@ -79,7 +79,7 @@ class TestResolveAuthorPeerId:
assert mgr.resolve_author_peer_id("telegram:group1", "111222") is None
def test_bot_author_lands_on_its_profile_peer(self):
- """A cloned profile's aiPeer defaults to the profile name, so the sender reuses its AI peer."""
+ """A clean profile name that no configured peer claims is the peer as is."""
mgr = _manager(_config(), runtime_id="7654321")
assert mgr.resolve_author_peer_id("telegram:dm1", "bot:coder") == "coder"
@@ -91,13 +91,36 @@ class TestResolveAuthorPeerId:
mgr = _manager(_config(runtime_peer_prefix="telegram_"), runtime_id="7654321")
assert mgr.resolve_author_peer_id("telegram:dm1", "bot:coder") == "coder"
- def test_bot_author_profile_name_is_sanitized(self):
+ def test_bot_author_profile_name_is_sanitized_with_a_digest(self):
+ """Sanitizing is lossy, so a changed name carries a digest like a prefixed runtime user."""
mgr = _manager(_config(), runtime_id="7654321")
- assert mgr.resolve_author_peer_id("telegram:dm1", "bot:my profile.v2") == "my-profile-v2"
+ peer = mgr.resolve_author_peer_id("telegram:dm1", "bot:my profile.v2")
+ assert peer.startswith("my-profile-v2-") and peer != "my-profile-v2"
+
+ def test_bot_authors_that_sanitize_alike_get_different_peers(self):
+ mgr = _manager(_config(), runtime_id="7654321")
+ dotted = mgr.resolve_author_peer_id("telegram:dm1", "bot:a.b")
+ dashed = mgr.resolve_author_peer_id("telegram:dm1", "bot:a-b")
+ assert dotted != dashed
+ assert dashed == "a-b"
+
+ def test_bot_author_named_like_the_owner_never_lands_on_the_owner_peer(self):
+ """``bot:eri`` with ``peerName: eri`` is another agent, not the operator."""
+ for pinned in (False, True):
+ mgr = _manager(_config(peer_name="eri", pin_peer_name=pinned), runtime_id="7654321")
+ peer = mgr.resolve_author_peer_id("telegram:dm1", "bot:eri", is_bot=True)
+ assert peer != mgr._declared_owner_peer_id()
+ assert peer.startswith("eri-")
+
+ def test_bot_author_named_like_an_alias_target_gets_a_digest(self):
+ mgr = _manager(_config(user_peer_aliases={"111222": "coder"}), runtime_id="7654321")
+ peer = mgr.resolve_author_peer_id("telegram:dm1", "bot:coder")
+ assert peer != "coder" and peer.startswith("coder-")
def test_bot_author_without_a_profile_keeps_the_raw_id(self):
mgr = _manager(_config(), runtime_id="7654321")
- assert mgr.resolve_author_peer_id("telegram:dm1", "bot:") == "bot-"
+ peer = mgr.resolve_author_peer_id("telegram:dm1", "bot:")
+ assert peer.startswith("bot-") and peer != mgr._declared_owner_peer_id()
def test_pin_peer_name_does_not_collapse_bot_authors(self):
"""The pin unifies the operator's accounts. A bot's words never land under the human's peer."""