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

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)
This commit is contained in:
outpoints
2026-08-23 19:04:42 -07:00
committed by Teknium
parent 3cbdc32565
commit 231e1c1204
2 changed files with 36 additions and 0 deletions
+4
View File
@@ -275,7 +275,11 @@ class HonchoMemoryProvider(DialecticMixin, MemoryProvider):
def _resolve_session_key(self, cfg, session_id: str, **kwargs) -> str: def _resolve_session_key(self, cfg, session_id: str, **kwargs) -> str:
"""Resolve the Honcho session key without touching the network.""" """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( return cfg.resolve_session_name(
cwd=cwd,
session_title=kwargs.get("session_title"), session_id=session_id, session_title=kwargs.get("session_title"), session_id=session_id,
session_title_source=kwargs.get("session_title_source"), session_title_source=kwargs.get("session_title_source"),
gateway_session_key=kwargs.get("gateway_session_key"), gateway_session_key=kwargs.get("gateway_session_key"),
@@ -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