Skip to content

fix: honcho peer retrieval routing - #9668

Closed
bkutasi wants to merge 1 commit into
NousResearch:mainfrom
bkutasi:fix/honcho-peer-retrieval-routing
Closed

fix: honcho peer retrieval routing#9668
bkutasi wants to merge 1 commit into
NousResearch:mainfrom
bkutasi:fix/honcho-peer-retrieval-routing

Conversation

@bkutasi

@bkutasi bkutasi commented Apr 14, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes peer retrieval routing in the Honcho memory plugin when _ai_observe_others mode is enabled. The _fetch_peer_card, _fetch_peer_context, get_peer_card, search_context, and get_prefetch_context methods always looked up peers directly, ignoring the observation-aware pattern where the AI peer should act as an observer to retrieve context about other peers. This caused missing or incorrect peer cards and representations in multi-peer/cross-observation setups.

The fix threads observer_peer_id through the internal retrieval methods, routing calls through the AI peer's get_card(target=...) and context(target=...) APIs when _ai_observe_others=True, while falling back to direct peer lookup when disabled.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Historical Context

This fix completes a chain of observation-mode evolution in the Honcho plugin:

  1. feat(memory): pluggable memory provider interface with profile isolation, review fixes, and honcho CLI restoration #4623feat(memory): pluggable memory provider interface — Introduced the Honcho memory provider plugin architecture
  2. fix: route memory provider tools in sequential execution path #4803fix: route memory provider tools in sequential execution path — Fixed tool routing for memory providers
  3. fix: thread gateway user_id to memory plugins for per-user scoping #5895fix: thread gateway user_id to memory plugins for per-user scoping — Added per-user peer scoping
  4. 29c98e8feat(honcho): add configurable observation mode (unified/directional) — Introduced binary observation mode switching; dialectic_query, create_conclusion got cross-observation routing, but peer retrieval methods (_fetch_peer_card, _fetch_peer_context) were not yet updated
  5. c02c3dcfix(honcho): plugin drift overhaul — Replaced binary observationMode with granular per-peer booleans (_ai_observe_others, _user_observe_me, etc.), switched peer card/profile/search from session.context() to direct peer APIs, added _fetch_peer_card and _fetch_peer_context helper methods — but these new helpers didn't respect _ai_observe_others
  6. feat(honcho): add opt-in initOnSessionStart for tools mode and respect explicit peerName #6995feat(honcho): add opt-in initOnSessionStart for tools mode and respect explicit peerName — Added tools-mode init timing and peer name configuration
  7. fix: resolve CI test failures — add missing functions, fix stale tests #9483fix: resolve CI test failures — Fixed stale tests after the above changes

The gap: Commit c02c3dc introduced _fetch_peer_card and _fetch_peer_context as the new direct-peer-API retrieval path, but these methods always called self._get_or_create_peer(peer_id) directly, bypassing the cross-observation routing that dialectic_query and create_conclusion already had. When _ai_observe_others=True, the AI peer should be the observer (calling get_card(target=user_peer_id) / context(target=user_peer_id)), but the retrieval helpers were fetching the user peer directly instead.

Changes Made

  • plugins/memory/honcho/session.py (+32/-7 lines)

    • _fetch_peer_card(peer_id, observer_peer_id=None) — When _ai_observe_others and observer_peer_id are set, creates the AI peer as observer and calls get_card(target=peer_id) or card(target=peer_id) instead of direct peer lookup
    • _fetch_peer_context(peer_id, search_query=None, observer_peer_id=None) — Same pattern: routes through AI peer's context(target=..., search_query=...) when observation mode is active
    • get_peer_card() — Passes observer_peer_id=session.assistant_peer_id to _fetch_peer_card
    • search_context() — Passes observer_peer_id=session.assistant_peer_id to _fetch_peer_context
    • get_prefetch_context() — Passes observer_peer_id for user context fetch; AI self-context remains direct (no observer needed)
  • tests/honcho_plugin/test_session.py (+182/-29 lines)

    • test_get_peer_card_cross_observation — Verifies AI peer routes get_card(target=user_peer_id) when _ai_observe_others=True
    • test_get_peer_card_unified_mode — Verifies direct peer lookup when _ai_observe_others=False
    • test_search_context_cross_observation — Verifies AI peer routes context(target=..., search_query=...) in observation mode
    • test_search_context_unified_mode — Verifies direct peer context(search_query=...) in unified mode
    • test_get_prefetch_context_cross_observation — Verifies user context fetched via AI observer, AI self-context fetched directly
    • Also improved formatting: multi-line kwargs, parenthesized with statements, added mgr._ai_observe_others = False to existing tests for correctness

How to Test

  1. Configure Honcho memory plugin with aiObserveOthers: true
  2. Start a multi-peer session where the AI should observe other peers
  3. Verify peer cards and representations are correctly retrieved via the AI peer's observer API (check logs for target= kwarg usage)
  4. Run pytest tests/honcho_plugin/test_session.py -q — all tests pass, including the 5 new cross-observation tests

Checklist

Code

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

Documentation & Housekeeping

  • N/A — Internal plugin fix, no user-facing documentation changes needed

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers labels Apr 26, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the thorough write-up and the well-structured fix, @bkutasi — the gap you identified in c02c3dc7 was real.

This is an automated hermes-sweeper review.

Unfortunately, the fix landed on main the day after this PR opened via a parallel overhaul:

  • Commit cc6e8941d (feat(honcho): context injection overhaul, 5-tool surface, cost safety, session isolation #10619, merged 2026-04-15) introduced _resolve_observer_target() and rewired get_peer_card, search_context, and get_prefetch_context to route through the AI peer as observer when _ai_observe_others=True.
  • plugins/memory/honcho/session.py line 989: _resolve_observer_target() returns (assistant_peer_id, target_peer_id) when _ai_observe_others=True — the same semantic your PR proposed.
  • get_peer_card (line 1018) and search_context (line 1052) both call _resolve_observer_target before dispatching to _fetch_peer_card / _fetch_peer_context.
  • Corresponding tests covering cross-observation and unified-mode paths already exist in tests/honcho_plugin/test_session.py (lines 206, 215, 233).

The main implementation is a superset of this fix: it also adds a peer parameter for bidirectional targeting across all five tools. Closing as implemented on main.

@teknium1 teknium1 closed this Jun 10, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 10, 2026
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 sweeper:implemented-on-main Sweeper: behavior already present on current main tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants