Skip to content

feat(honcho): add sessionAiPeerPrefix to isolate sessions per AI peer - #39130

Open
itnkr wants to merge 2 commits into
NousResearch:mainfrom
itnkr:feat/honcho-session-ai-peer-prefix
Open

feat(honcho): add sessionAiPeerPrefix to isolate sessions per AI peer#39130
itnkr wants to merge 2 commits into
NousResearch:mainfrom
itnkr:feat/honcho-session-ai-peer-prefix

Conversation

@itnkr

@itnkr itnkr commented Jun 4, 2026

Copy link
Copy Markdown

What does this PR do?

Adds an opt-in sessionAiPeerPrefix config flag for the Honcho memory plugin. When set, the resolved Honcho session name is prefixed with {aiPeer}- so that multiple AI peers sharing one workspace + peerName + gateway chat key stay on disjoint sessions instead of colliding on a single one.

It is the symmetric counterpart to the existing sessionPeerPrefix (which prefixes the user peer). The motivating case is the gateway_session_key branch of resolve_session_name(), which is AI-peer-agnostic — so without this flag there is no way to isolate two agents that share a workspace and peer name.

Related Issue

Fixes #39129

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Default is false; when unset, session-name resolution is byte-for-byte unchanged.

Changes Made

  • plugins/memory/honcho/client.py
    • new session_ai_peer_prefix config field
    • host-first / root-fallback parsing of sessionAiPeerPrefix (mirrors sessionPeerPrefix)
    • resolve_session_name() is now a thin wrapper that delegates to a new _resolve_session_name_base() (the existing resolution ladder, unchanged) and then applies the {aiPeer}- prefix on every path. The prefixed name is re-run through _enforce_session_id_limit() so the prefix can never push a name past Honcho's session-id cap.
  • tests/honcho_plugin/test_session_ai_peer_prefix.py (new)
  • plugins/memory/honcho/README.md — config table + resolution notes

How to Test

pytest tests/honcho_plugin/test_session_ai_peer_prefix.py

Tests cover: config parsing (default/root/host/host-overrides-root), the gateway-key collision case, cross-peer disjointness (same chat key + different aiPeer → different sessions), the session-id length cap, and a disabled-by-default regression guard. Existing honcho suites (test_honcho_client_config.py, test_pin_peer_name.py) still pass — 61 green locally.

Checklist

  • Tests added/updated
  • Docs updated
  • Backward compatible (opt-in, default false)

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers comp/plugins Plugin system and bundled plugins labels Jun 4, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Clean, backward-compatible config addition: sessionAiPeerPrefix mirrors the existing sessionPeerPrefix behavior but for AI peers. Resolver refactor is sound (delegates to _resolve_session_name_base then post-processes) and tests cover the gateway-key collision case thoroughly.

Already docs-updated in a separate PR (39128), so the user-facing narrative is consistent.

Reviewed by Hermes Agent

@dso2ng

dso2ng commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for splitting this as a narrow opt-in fix. I re-checked the current Honcho/profile landscape while dogfooding multiple Hermes profiles, and this is the cleanest patch for the session collision layer.

Observed shape on current main:

  • profile-aware Honcho host blocks select config correctly (hermes, hermes_<profile>, with legacy dotted lookup still relevant)
  • many real deployments intentionally keep the same workspace + peerName across profiles and only vary aiPeer
  • in that setup, gateway_session_key remains AI-peer-agnostic, so two AI peers can still land in the same Honcho session

sessionAiPeerPrefix fixes exactly that without changing the default/shared-memory policy. That boundary is useful: it does not try to solve full profile namespace isolation (tracked separately by issues like #4726/#31789/#31388), but it gives shared-workspace operators a safe knob to keep sessions disjoint.

I also like that the PR applies the prefix after the base resolver and re-runs the length cap; that avoids making the gateway path a one-off special case.

For reviewer context: this is complementary to #30077 (runtime user-peer mapping) and not a replacement for profile/workspace isolation. It is the small hardening I would enable before turning on any automatic/context/hybrid Honcho recall in a multi-profile setup.

@itnkr

itnkr commented Jun 23, 2026

Copy link
Copy Markdown
Author

Rebased onto current main — the client.py/README conflicts are resolved and the branch is conflict-free again. The new sessionAiPeerPrefix resolver tests pass locally (gateway-key prefixing, two-AI-peer disjointness, the disabled-by-default regression guard, and the session-id length cap).

Some real-world signal worth adding: this patch has been running in production across my full Hermes deployment for ~3 weeks — five Dockerized spheres plus a native macOS install, all now on 0.17.0. One sphere runs six AI peers sharing a single personal Honcho workspace with the same peerName and gateway chat key, and sessionAiPeerPrefix is the only thing keeping their sessions disjoint — without it they all collide on one shared session. It is opt-in and default-off, so it stays inert for anyone who does not set it.

Would appreciate a maintainer look whenever there is a window 🙏

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the narrowly scoped, default-off session-isolation fix. The current gateway path does have the stated collision: plugins/memory/honcho/client.py:698-701 returns a sanitized gateway_session_key without incorporating ai_peer.

Problems

  • The new setting needs gateway cache invalidation. gateway/run.py:15756-15762 enumerates the Honcho settings included in the cached-agent signature, and the PR does not add sessionAiPeerPrefix. That signature controls reuse at gateway/run.py:18158-18163; meanwhile the provider resolves and retains its session key at plugins/memory/honcho/__init__.py:433-445. A live config flip would therefore leave an existing gateway session on its old Honcho session until unrelated eviction or restart. The analogous contract is explicitly covered for other Honcho identity changes in tests/honcho_plugin/test_pin_peer_name.py:672-817.

Suggested changes

  • Add honcho.session_ai_peer_prefix to the Honcho cache-busting extraction in gateway/run.py, and add a config-flip regression test alongside the existing Honcho cache-signature tests.

Automated hermes-sweeper review.

# sessions disjoint when several AI peers share one workspace + peerName +
# gateway chat key; without it the gateway_session_key branch in
# resolve_session_name() yields the same name for every AI peer.
session_ai_peer_prefix: bool = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also include this setting in the gateway's Honcho cache-busting signature (gateway/run.py:15756-15794) and test a honcho.json false→true flip. A cached gateway AIAgent retains the Honcho manager/session key resolved at initialization, so without a signature change this opt-in setting will not affect an already-active gateway session until unrelated eviction or restart.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
@itnkr

itnkr commented Jul 17, 2026

Copy link
Copy Markdown
Author

Addressed the cache-invalidation feedback: added session_ai_peer_prefix to the gateway's Honcho cache-busting signature (_HONCHO_CACHE_BUSTING_KEYS + _extract_honcho_cache_busting_config) so a live config flip rebuilds the cached agent instead of stranding the existing gateway session on its old Honcho session. Added a config-flip regression test alongside the existing cache-signature cases.

While in there I also closed the same latent gap for the pre-existing user-side sessionPeerPrefix — it feeds the same resolve_session_name output into the same frozen _session_key, so it had the identical live-flip staleness bug and was likewise missing from the signature. Both are covered by regression tests now.

@teknium1 teknium1 added area/sessions Session lifecycle, resume, persistence, history area/memory Memory subsystem: store, providers, sync, background reviews labels Jul 19, 2026
@itnkr
itnkr force-pushed the feat/honcho-session-ai-peer-prefix branch from 70d44d2 to ae949b5 Compare July 21, 2026 13:30
@itnkr

itnkr commented Jul 21, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (v0.19.0) — the branch is conflict-free and MERGEABLE again. v0.19 reworked client.py, so the sessionAiPeerPrefix change was re-derived onto the new base; the two-commit shape is unchanged (feature + the gateway cache-busting fix).

The earlier review feedback is addressed: session_ai_peer_prefix (and the symmetric session_peer_prefix) are in the gateway's Honcho cache-busting signature, with config-flip regression tests alongside the existing cache-signature tests. Full honcho suite passes locally on v0.19 (55 passed).

Ready for another look whenever you have a moment. 🙏

@itnkr
itnkr requested a review from teknium1 July 24, 2026 11:45
@itnkr
itnkr force-pushed the feat/honcho-session-ai-peer-prefix branch from ae949b5 to bfae3ad Compare July 30, 2026 13:14
@itnkr

itnkr commented Jul 30, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (b4f8c491d) — the branch is mergeable again.

Conflict resolution. Only tests/honcho_plugin/test_pin_peer_name.py conflicted. It was caused by 6b81590 ("prune low-value tests suite-wide (wave 1)"), which removed the three sibling cache-signature tests my additions were appended after. I've honored that pruning rather than resurrecting them, and collapsed my own two per-key tests into a single test_cache_busting_signature_reflects_session_prefixes that asserts both new keys flip — same coverage, less test surface, consistent with the direction of the prune.

Verified the clean auto-merges, since two of them were load-bearing:

  • _extract_cache_busting_config was renamed to _extract_honcho_cache_busting_config and split, but the old name survives as a wrapper — so both new keys land in the right place and the tests' call signature is still valid.
  • resolve_session_name's signature is unchanged and all production callers (__init__.py, cli.py) go through the public method, so the _resolve_session_name_base wrapper still intercepts every resolution path.

Two small additions while rebasing:

  • Added the missing sessionAiPeerPrefix ProviderField to plugins/memory/honcho/config_schema.py, so the flag is discoverable in the desktop settings panel alongside sessionPeerPrefix. This was an oversight in the original PR — the flag worked from honcho.json, it just wasn't exposed in the UI.
  • Reorganized the two commits so each is independently green. The cache-signature test now sits with the gateway/run.py change that implements it, rather than one commit ahead of it.

tests/honcho_plugin/, tests/gateway/test_agent_cache.py, and tests/plugins/memory/ pass at both commits (261 passed, 12 skipped). Happy to squash or drop the added test entirely if you'd prefer to keep the pruned surface minimal.

erosika pushed a commit to plastic-labs/hermes-agent that referenced this pull request Aug 11, 2026
Address review feedback on NousResearch#39130: the new sessionAiPeerPrefix setting
affects the resolved Honcho session key, which HonchoMemoryProvider freezes
at construction (self._session_key). Because it wasn't part of the gateway's
cached-agent signature, a live config flip left an existing gateway session
bound to its old, AI-peer-agnostic Honcho session until an unrelated eviction
or restart.

Add honcho.session_ai_peer_prefix to _HONCHO_CACHE_BUSTING_KEYS and the
_extract_honcho_cache_busting_config values so a flip rebuilds the cached
agent on the next turn, mirroring the existing aiPeer / pin_peer_name /
runtime_peer_prefix contracts.

Also close the symmetric gap for the pre-existing user-side sessionPeerPrefix:
it feeds the same resolve_session_name output (per-session/title/per-repo/
per-directory strategies) into the same frozen _session_key, so it had the
identical live-flip staleness bug and was likewise absent from the cache
signature. Fixing both keeps the two prefixes consistent.

Add one config-flip regression test covering both keys, alongside the
existing Honcho cache-signature test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
itnkr and others added 2 commits August 18, 2026 11:50
The gateway_session_key branch of resolve_session_name() returns an
AI-peer-agnostic name, so multiple AI peers sharing one workspace +
peerName + gateway chat key collide on a single Honcho session.

Add sessionAiPeerPrefix (symmetric counterpart to sessionPeerPrefix):
when set, the resolved session name is prefixed with {ai_peer}- on every
resolution path. The prefixed name is re-run through the session-id
length cap so the prefix can never exceed Honcho's limit.

- config field + host/root parsing in client.py
- public resolve_session_name() wraps a new _resolve_session_name_base()
- tests covering parsing, the gateway-key case, cross-peer disjointness,
  the length cap, and a disabled-by-default regression guard
- README: config table + resolution notes
Address review feedback on NousResearch#39130: the new sessionAiPeerPrefix setting
affects the resolved Honcho session key, which HonchoMemoryProvider freezes
at construction (self._session_key). Because it wasn't part of the gateway's
cached-agent signature, a live config flip left an existing gateway session
bound to its old, AI-peer-agnostic Honcho session until an unrelated eviction
or restart.

Add honcho.session_ai_peer_prefix to _HONCHO_CACHE_BUSTING_KEYS and the
_extract_honcho_cache_busting_config values so a flip rebuilds the cached
agent on the next turn, mirroring the existing aiPeer / pin_peer_name /
runtime_peer_prefix contracts.

Also close the symmetric gap for the pre-existing user-side sessionPeerPrefix:
it feeds the same resolve_session_name output (per-session/title/per-repo/
per-directory strategies) into the same frozen _session_key, so it had the
identical live-flip staleness bug and was likewise absent from the cache
signature. Fixing both keeps the two prefixes consistent.

Add one config-flip regression test covering both keys, alongside the
existing Honcho cache-signature test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@itnkr
itnkr force-pushed the feat/honcho-session-ai-peer-prefix branch from bfae3ad to 5951fd3 Compare August 18, 2026 15:53
@itnkr

itnkr commented Aug 18, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (9664e386f) — zero conflicts this time, and the branch is MERGEABLE again.

Rebase notes. ~4,035 commits of drift since the 07-30 rebase, and nothing in the overlay's context moved: all three touched files (plugins/memory/honcho/client.py, plugins/memory/honcho/config_schema.py, gateway/run.py) applied clean, and the public surface is unchanged — resolve_session_name is still the wrapper every external caller uses, with _resolve_session_name_base and _enforce_session_id_limit underneath.

Tests. 36/36 across tests/honcho_plugin/test_session_ai_peer_prefix.py and test_pin_peer_name.py — the resolver cases, gateway-key prefixing, two-AI-peer disjointness, the disabled-by-default guard, the session-id length cap, and the config-flip cache-signature regression. Full tests/honcho_plugin/ is 316 passed / 16 skipped on this branch.

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

Labels

area/memory Memory subsystem: store, providers, sync, background reviews area/sessions Session lifecycle, resume, persistence, history comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/memory Memory tool and memory providers type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Honcho: AI peers sharing a workspace collide on one session via gateway_session_key

5 participants