Skip to content

feat(honcho): HONCHO_SESSION env var for per-launch session pinning#18152

Open
sasha-id wants to merge 2 commits into
NousResearch:mainfrom
sasha-id:feat/honcho-session-env-var
Open

feat(honcho): HONCHO_SESSION env var for per-launch session pinning#18152
sasha-id wants to merge 2 commits into
NousResearch:mainfrom
sasha-id:feat/honcho-session-env-var

Conversation

@sasha-id

@sasha-id sasha-id commented May 1, 2026

Copy link
Copy Markdown
Contributor

What

Adds a HONCHO_SESSION env var that pins the Honcho session name for the launch. resolve_session_name reads HONCHO_SESSION after the gateway-session-key check and before the strategy fallback, returning the sanitized value (peer-prefixed when session_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_title at client.py:555, gateway_session_key at client.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_key in priority. Tested by TestResolveSessionNameEnvVar.test_gateway_wins_over_env_var. Without that ordering, a process-wide HONCHO_SESSION on 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:

Honcho session resolved via HONCHO_SESSION env var: <peer>-test-foo

With session_peer_prefix=False (the default in client.py:283): Honcho session resolved via HONCHO_SESSION env var: test-foo.

The plugin's __init__.py now reconstructs the env-derived value and compares it to the resolved session key before logging the env-var-derived line — so manual sessions[cwd] overrides (which preempt env silently) don't false-positive in the logs.

Cross-platform

os.environ.get is OS-agnostic. No termios / fcntl / signal / process-management changes. macOS verified locally.

Tests

tests/honcho_plugin/test_client.py::TestResolveSessionNameEnvVar — 8 cases:

  • env-set returns value (with and without session_peer_prefix)
  • gateway wins (daemon-safety invariant)
  • /title wins
  • sanitization preserves casing (Foo.Bar!Foo-Bar)
  • sanitize-to-empty falls through (--- → per-directory basename)
  • env-unset preserves existing behavior (uses monkeypatch.delenv, not patch.dict(clear=True), so PATH/HOME stay intact)
  • manual 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_name updated from 7 numbered steps to 8.

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins tool/terminal Terminal execution and process management backend/docker Docker container execution labels May 1, 2026
@sasha-id sasha-id force-pushed the feat/honcho-session-env-var branch from a8a1d74 to 0126240 Compare May 4, 2026 16:19
sasha-id added 2 commits May 21, 2026 09:58
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.
@sasha-id sasha-id force-pushed the feat/honcho-session-env-var branch from 0126240 to 701786f Compare May 21, 2026 01:59
sasha-id added a commit to sasha-id/hermes-agent that referenced this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/docker Docker container execution comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/terminal Terminal execution and process management type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants