Files
hermes-agent/tests/honcho_plugin/test_session_routing_integration.py
outpoints 231e1c1204 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)
2026-09-15 22:30:11 -07:00

33 lines
1.2 KiB
Python

"""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