Skip to content

The agent that grows with you

fix(honcho): resolve migration owner gate through _resolve_user_peer_id

Erosika27021f5f840b
diff --git a/plugins/memory/honcho/session.py b/plugins/memory/honcho/session.py
index 0f14e1bccd1..6f2e68afdd0 100644
--- a/plugins/memory/honcho/session.py
+++ b/plugins/memory/honcho/session.py
@@ -1138,13 +1138,17 @@ class HonchoSessionManager:
return False
# Only migrate the owner-describing memory files (MEMORY.md / USER.md)
- # when the session's user peer IS the configured owner peer. Otherwise a
+ # when the session's user peer IS the owner peer. Otherwise a
# non-owner triggering a new session (e.g. any other human in a shared
# Slack/Discord channel) gets the owner's full profile files uploaded
# under the NON-OWNER's peer, and Honcho's deriver attributes the
# owner's facts to that person. SOUL.md describes the agent, not a
# human, but skipping it here too keeps the migration owner-scoped.
- if session.user_peer_id != self._sanitize_id(self._config.peer_name):
+ # The owner is resolved through _resolve_user_peer_id (pin/runtime/
+ # alias aware) — config.peer_name alone is optional and None for
+ # most single-user setups.
+ owner_peer_id = self._resolve_user_peer_id(session_key)
+ if session.user_peer_id != owner_peer_id:
logger.info(
"Skipping memory-file migration for non-owner session (user=%s)",
session.user_peer_id,
diff --git a/tests/honcho_plugin/test_async_memory.py b/tests/honcho_plugin/test_async_memory.py
index 4e4e379ef59..375b50f8b6a 100644
--- a/tests/honcho_plugin/test_async_memory.py
+++ b/tests/honcho_plugin/test_async_memory.py
@@ -423,6 +423,10 @@ class TestAsyncWriterRetry:
class TestMemoryFileMigrationTargets:
def test_soul_upload_targets_ai_peer(self, tmp_path, make_manager):
mgr = make_manager(write_frequency="turn")
+ # Migration is owner-gated: the session's user peer must match what
+ # _resolve_user_peer_id returns. Make the runtime identity match the
+ # crafted session so this reads as the owner's own session.
+ mgr._runtime_user_peer_name = "custom-user"
session = _make_session(
key="cli:test",
user_peer_id="custom-user",
@@ -457,6 +461,27 @@ class TestMemoryFileMigrationTargets:
assert peer_by_upload_name["user_profile.md"] is user_peer
assert peer_by_upload_name["agent_soul.md"] is ai_peer
+ def test_migration_skipped_for_non_owner_session(self, tmp_path, make_manager):
+ """A non-owner user peer in the session must not receive the owner's
+ memory files — see #43752-adjacent shared-channel misattribution."""
+ mgr = make_manager(write_frequency="turn")
+ mgr._runtime_user_peer_name = "owner-user"
+ session = _make_session(
+ key="discord:shared",
+ user_peer_id="some-other-human",
+ assistant_peer_id="custom-ai",
+ honcho_session_id="shared-chan",
+ )
+ mgr._cache[session.key] = session
+ mgr._sessions_cache[session.honcho_session_id] = MagicMock()
+
+ (tmp_path / "MEMORY.md").write_text("owner facts", encoding="utf-8")
+
+ uploaded = mgr.migrate_memory_files(session.key, str(tmp_path))
+
+ assert uploaded is False
+ assert mgr._sessions_cache[session.honcho_session_id].upload_file.call_count == 0
+
# ---------------------------------------------------------------------------
# HonchoClientConfig dataclass defaults for new fields