From 231e1c1204b612f2ea844dc1a1b4c5c319f5f71a Mon Sep 17 00:00:00 2001 From: outpoints <12377381+outpoints@users.noreply.github.com> Date: Sun, 23 Aug 2026 19:04:42 -0700 Subject: [PATCH] fix(honcho): resolve sessions against agent cwd, not process cwd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Honcho provider resolved per-repo/per-directory session names from os.getcwd(), which is the backend process launch directory on Desktop/gateway hosts (typically $HOME), not the user's workspace. With a manual sessions map entry for the home directory, every Desktop conversation landed in that fallback bucket instead of the project's per-repo session. Use agent.runtime_cwd.resolve_agent_cwd() — the same single source of truth already used for system-prompt and context-file discovery — so Honcho session routing agrees with everything else about where the agent logically lives. It honors the pinned session cwd, then TERMINAL_CWD, then the launch directory; CLI sessions launched inside a project resolve identically either way. Adds a regression covering the Desktop-style case: backend launched in $HOME, workspace elsewhere, home-directory manual map present. Refs #24740 (cherry picked from commit cfb32757de2509dd404acf98311e357d73fa741e) --- plugins/memory/honcho/__init__.py | 4 +++ .../test_session_routing_integration.py | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/honcho_plugin/test_session_routing_integration.py diff --git a/plugins/memory/honcho/__init__.py b/plugins/memory/honcho/__init__.py index 62fe8ce52f..14255ce5a1 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 0000000000..89151a7ecb --- /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 + + +@pytest.mark.parametrize("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