Skip to content

fix(honcho): normalize cwd when matching manual session overrides#13322

Open
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/honcho-cwd-normalization
Open

fix(honcho): normalize cwd when matching manual session overrides#13322
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/honcho-cwd-normalization

Conversation

@Sanjays2402

@Sanjays2402 Sanjays2402 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

HonchoClientConfig.resolve_session_name() does a raw dict lookup self.sessions.get(cwd) on whatever string the caller passed in. When Hermes is launched from different shells the same project directory can be spelled multiple equivalent ways — with/without a trailing slash, as ~/proj vs /home/user/proj, with a . or .. segment — and all but one miss the override, so Hermes silently falls through to the basename-derived session name and effectively starts a fresh Honcho session every time.

Adds a small _match_session_override() helper that tries the existing fast-path dict lookup first (so configs with already-normalized keys keep their exact behaviour) and then falls back to comparing the absolute, ~-expanded, normalized form of both the lookup cwd and each override key.

Normalization uses pathlib.Path.resolve(strict=False), so it doesn't require the directory to actually exist on disk — which matters for test fixtures and remote-cwd callers. A defensive fallback to os.path.normpath(os.path.expanduser(...)) covers pathological inputs.

Related Issue

Fixes #13284

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • plugins/memory/honcho/client.py (+43 / −2): new _match_session_override() + _normalize_cwd() helpers; resolve_session_name() delegates to them.
  • tests/honcho_plugin/test_client.py (+33): regression tests for normalized spellings and ~ expansion.
def _match_session_override(self, cwd: str) -> str | None:
    if not self.sessions:
        return None
    direct = self.sessions.get(cwd)           # fast path
    if direct:
        return direct
    target = self._normalize_cwd(cwd)
    for key, value in self.sessions.items():
        if self._normalize_cwd(key) == target:
            return value
    return None

How to Test

  1. Add a sessions override in ~/.hermes/config.yaml keyed by ~/proj (or with a trailing slash).
  2. Launch Hermes from /Users/you/proj (no trailing slash, no tilde).
  3. Before: basename-derived session name. After: the configured override is used.

Run the regression suite:

pytest tests/honcho_plugin/test_client.py -q

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(honcho):)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: macOS 26.5 (arm64)

Documentation & Housekeeping

  • I've updated relevant documentation — N/A (internal helper)
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A
  • I've considered cross-platform impact (Windows, macOS) — uses pathlib.Path.resolve
  • I've updated tool descriptions/schemas — N/A

Screenshots / Logs

Verification

  • python3 -m py_compile plugins/memory/honcho/client.py tests/honcho_plugin/test_client.py → clean.
  • The fast-path dict lookup is tried before normalization, so there's zero cost for callers whose override keys already match exactly.
  • Normalization never calls the filesystem's stat() — it's string/path-manipulation only — so it's safe for cwd values that don't exist locally (remote task cwds, etc.).

Regression tests added

Test Scenario
test_manual_override_matches_normalized_spellings (parametrized ×4) Trailing slash on override / lookup, ./ segment, .. segment
test_manual_override_expands_tilde_in_override_key ~/proj override key resolves for /home/user/proj lookup

Kept the existing test_manual_override unchanged so the fast-path behaviour is still locked in.

Closes NousResearch#13284.

HonchoClientConfig.resolve_session_name() does:

    manual = self.sessions.get(cwd)

which is a raw dict lookup on whatever string the caller passed in.
When Hermes is launched from different shells the same project directory
can be spelled multiple equivalent ways \u2014 with/without a trailing slash,
as '~/proj' vs '/home/user/proj', via a '.' or '..' segment, etc. \u2014 and
all but one miss the override, so Hermes silently falls through to the
basename-derived session name and effectively starts a fresh Honcho
session.

Add a small _match_session_override() helper that tries the existing
fast-path dict lookup first (so configs with already-normalized keys
keep their exact behaviour) and then falls back to comparing the
absolute, user-expanded, normalized form of both the lookup cwd and
each override key.

The normalization uses pathlib.Path.resolve(strict=False), so it
doesn't require the directory to actually exist on disk \u2014 which
matters for test fixtures and for remote-cwd callers.

Tests added in tests/honcho_plugin/test_client.py:
  - trailing-slash equivalence (both directions)
  - './' and '..' path segments normalized away
  - '~/proj' override key resolves for '/home/user/proj' lookup
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #13333 — both normalize Honcho session override paths. Fixes #13284.

@Sanjays2402

Copy link
Copy Markdown
Contributor Author

Hey @alt-glitch — just a note for context: this PR was opened ~10 minutes before #13333 (04:54:34Z vs 05:04:48Z), so #13333 is actually the duplicate here, not the other way around. Happy to defer to @sgaofen's implementation if maintainers prefer it, but wanted to make sure the timeline was clear. Either way, whichever lands first is fine by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Honcho session override lookup misses configured cwd when path spelling changes

2 participants