Skip to content

The agent that grows with you

fix(honcho): resolve sessions against agent cwd, not process cwd

outpoints231e1c1204b6
diff --git a/plugins/memory/honcho/__init__.py b/plugins/memory/honcho/__init__.py
index 62fe8ce52f4..14255ce5a11 100644
--- a/plugins/memory/honcho/__init__.py
+++ b/plugins/memory/honcho/__init__.py
@@ -275,7 +275,11 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
def _resolve_session_key(self, cfg, session_id: str, **kwargs) -> str:
"""Resolve the Honcho session key without touching the network."""
+ from agent.runtime_cwd import resolve_agent_cwd
+
+ cwd = kwargs.get("cwd") or str(resolve_agent_cwd())
return cfg.resolve_session_name(
+ cwd=cwd,
session_title=kwargs.get("session_title"), session_id=session_id,
session_title_source=kwargs.get("session_title_source"),
gateway_session_key=kwargs.get("gateway_session_key"),
diff --git a/tests/honcho_plugin/test_session_routing_integration.py b/tests/honcho_plugin/test_session_routing_integration.py
new file mode 100644
index 00000000000..89151a7ecbf
--- /dev/null
+++ b/tests/honcho_plugin/test_session_routing_integration.py
@@ -0,0 +1,32 @@
+"""Route against real repository/SessionDB state, without contacting Honcho."""
+
+import subprocess
+
+import pytest
+
+from agent import runtime_cwd
+from hermes_state import SessionDB
+from plugins.memory.honcho import HonchoMemoryProvider
+from plugins.memory.honcho.client import HonchoClientConfig
+
+
[email protected]("cwd_source", ["explicit", "context", "terminal"])
+def test_provider_routes_by_logical_workspace(monkeypatch, tmp_path, cwd_source):
+ launch = tmp_path / "launch"
+ repo = tmp_path / "project"
+ launch.mkdir()
+ repo.mkdir()
+ subprocess.run(["git", "init", "-q", str(repo)], check=True)
+ child = repo / "src"
+ child.mkdir()
+ monkeypatch.chdir(launch)
+ monkeypatch.setenv("TERMINAL_CWD", str(child if cwd_source == "terminal" else launch))
+ token = runtime_cwd.set_session_cwd(str(child) if cwd_source == "context" else None)
+ cfg = HonchoClientConfig(session_strategy="per-repo", sessions={str(launch): "wrong-bucket"})
+ try:
+ key = HonchoMemoryProvider()._resolve_session_key(
+ cfg, "conversation", **({"cwd": str(child)} if cwd_source == "explicit" else {})
+ )
+ finally:
+ runtime_cwd._SESSION_CWD.reset(token)
+ assert key == repo.name