feat(honcho): HONCHO_SESSION env var for per-launch session pinning#18152
Open
sasha-id wants to merge 2 commits into
Open
feat(honcho): HONCHO_SESSION env var for per-launch session pinning#18152sasha-id wants to merge 2 commits into
sasha-id wants to merge 2 commits into
Conversation
a8a1d74 to
0126240
Compare
resolve_session_name reads HONCHO_SESSION and returns it (peer-prefixed when session_peer_prefix=True). Placed BELOW gateway_session_key so a process-wide env on the gateway daemon does not collapse multi-chat isolation; placed ABOVE strategy fallback so non-gateway launches (CLI/ REPL) get a launch-time pin. Sanitization: [^a-zA-Z0-9_-]+ → -, then strip leading/trailing dashes (matches existing session_title and gateway_session_key sanitization). Empty/whitespace falls through to existing strategy logic. Tests: TestResolveSessionNameEnvVar covers env-set, peer-prefix on/off, gateway wins (daemon-safety invariant), title wins, sanitization, edge cases, and existing-behavior preservation when unset.
Reconstruct the env-derived value and compare to the resolved session key before logging the env-var-derived line — sessions[cwd] manual override preempts env silently, so a naive 'env set & no gateway/title' check would produce misleading log output.
0126240 to
701786f
Compare
sasha-id
added a commit
to sasha-id/hermes-agent
that referenced
this pull request
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
HONCHO_SESSIONenv var that pins the Honcho session name for the launch.resolve_session_namereadsHONCHO_SESSIONafter the gateway-session-key check and before the strategy fallback, returning the sanitized value (peer-prefixed whensession_peer_prefix=True).Why
Today the only operator-facing session-pin signal is
/title(set post-launch, persisted in the SQLite session DB). Operators who launch hermes from per-project wrappers want to pin the session at launch without/title-ing every session. Mirrors how operator-written values are sanitized elsewhere in the same function (session_titleatclient.py:555,gateway_session_keyatclient.py:567) — same regex ([^a-zA-Z0-9_-]+ → -, then strip leading/trailing dashes), case-preserving.Daemon-safety invariant
The env var sits below
gateway_session_keyin priority. Tested byTestResolveSessionNameEnvVar.test_gateway_wins_over_env_var. Without that ordering, a process-wideHONCHO_SESSIONon a gateway systemd unit would collapse all gateway chats into one Honcho session — the test guards against the regression.For non-gateway launches (CLI / REPL), the env var becomes the primary launch-time session pin.
How to test
HONCHO_SESSION=test-foo hermes -q "hello"Then check
~/.hermes/logs/(or stderr if debug logging is enabled) for:With
session_peer_prefix=False(the default inclient.py:283):Honcho session resolved via HONCHO_SESSION env var: test-foo.The plugin's
__init__.pynow reconstructs the env-derived value and compares it to the resolved session key before logging the env-var-derived line — so manualsessions[cwd]overrides (which preempt env silently) don't false-positive in the logs.Cross-platform
os.environ.getis OS-agnostic. Notermios/fcntl/signal/ process-management changes. macOS verified locally.Tests
tests/honcho_plugin/test_client.py::TestResolveSessionNameEnvVar— 8 cases:session_peer_prefix)/titlewinsFoo.Bar!→Foo-Bar)---→ per-directory basename)monkeypatch.delenv, notpatch.dict(clear=True), so PATH/HOME stay intact)sessions[cwd]still wins (unchanged)Run:
pytest tests/honcho_plugin/test_client.py -v. All pre-existing tests still pass (77 passed, 3 skipped, 0 fails).Scope
Plugin-only change. Wrapper / launcher changes that export the env var live downstream in operator tooling, not in this PR. Docstring on
resolve_session_nameupdated from 7 numbered steps to 8.