Skip to content

fix(honcho): pass user_message as search_query for topic-relevant context injection - #17021

Closed
qxxaa wants to merge 2 commits into
NousResearch:mainfrom
qxxaa:fix/honcho-prefetch-search-query
Closed

fix(honcho): pass user_message as search_query for topic-relevant context injection#17021
qxxaa wants to merge 2 commits into
NousResearch:mainfrom
qxxaa:fix/honcho-prefetch-search-query

Conversation

@qxxaa

@qxxaa qxxaa commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Problem

get_prefetch_context() accepts a user_message parameter but intentionally discards it, with a comment explaining that passing it as search_query "would expose conversation content in server access logs."

This rationale is inconsistent: Honcho already receives and persists every message in full via saveMessages. The content is already in the database. A search query string appearing in an access log adds negligible additional exposure over what is already persisted — and is entirely moot for self-hosted deployments where the operator owns the logs.

Current behaviour

Without search_query, Honcho's peer.context() returns the full peer representation: all observations, derived conclusions, and peer card, in insertion order. When contextTokens is set to limit injection size, the budget is consumed by raw observations first. The higher-signal parts — peer card and synthesised conclusions — appear last and are truncated.

The result is topic-agnostic context injection on every cold start, regardless of what the session is actually about.

Fix

Pass user_message as search_query to _fetch_peer_context() when available. This enables Honcho's semantic retrieval to return conclusions relevant to the current session topic rather than the full observation set.

_fetch_peer_context() already accepts and passes search_query to the Honcho API — this change simply connects the two. The total diff is 2 lines.

Behaviour when user_message is None

user_message or None preserves the existing broad-fetch behaviour when no message is available (e.g. session prewarm before the first turn). No regression for existing deployments.

Files changed

  • plugins/memory/honcho/session.py — 2 lines

Testing

  1. Configure recallMode: hybrid and injectionFrequency: first-turn in honcho.json
  2. Start a fresh session with a topic-specific first message
  3. Inspect the injected context — should contain topic-relevant conclusions rather than the full observation dump
  4. Verify sessions without a first message (prewarm) still function correctly

The user_message parameter was accepted by get_prefetch_context but intentionally discarded, with the rationale that passing it would
expose conversation content in server access logs.

This rationale is inconsistent: Honcho already persists every message in full via saveMessages. The content is already in the database. A search query in an access log adds negligible additional exposure, and is moot for self-hosted Honcho deployments where the operator owns the logs.

Without search_query, Honcho returns the full peer representation -
all observations, deductive/inductive layers, and peer card - in
insertion order. When contextTokens is set, the most useful parts
(peer card, dialectic conclusions) are truncated because raw
observations fill the budget first.

Passing user_message as search_query enables Honcho's semantic
retrieval to return only conclusions relevant to the current session
topic, reducing injection noise and improving context quality on cold starts.

The _fetch_peer_context method already accepts and passes search_query to the Honcho API. This change simply connects the two.
@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 28, 2026
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 12, 2026
…ousResearch#17021)

The Phase 6B-2 pipeline refactor (commit d24d61f) removed the old
3398-line run_conversation() method, which contained 23 calls to
_persist_session() across every exit path (normal, error, interrupt,
compression, etc.). The new AIAgentCompatShim.run_conversation() never
calls _persist_session or _flush_messages_to_session_db, causing ALL
sessions since ~Apr 28 to have 0 messages in the SQLite database.

Symptoms:
- session_search returns no results for recent sessions
- JSON session files no longer written to ~/.hermes/sessions/
- Sessions exist in DB with message_count=0 and title=NULL
- Data loss on exit/crash (no recovery possible)

Fix (4 changes):
1. cli.py: Add _persist_session() call after every agent turn (~line 8650)
2. cli.py: Add final flush in the finally block at session exit (~line 10848)
3. cli.py: Add persist in single-query (-q) mode (~line 11150)
4. gateway/run.py: agent_persisted was always True (skipping DB writes)
   but the agent no longer persists — changed to False so messages are
   written via append_to_transcript()

Note: 3 pre-existing tests were already broken (they expected
_persist_session calls from the deleted run_conversation). Not caused
by this change.
@qxxaa
qxxaa deleted the fix/honcho-prefetch-search-query branch July 6, 2026 12:10
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request Aug 23, 2026
…efactor

The old run_conversation() called _flush_messages_to_session_db() on
every exit path (23 call sites). The Phase 6B-2 pipeline refactor
removed those calls, causing session metadata to exist in the DB
but messages to never be written — data loss on exit/crash. (NousResearch#17021)

- cli.py: add _persist_session() after run_conversation(), on shutdown,
  and in single-query mode
- gateway/run.py: force gateway-side persistence (agent_persisted=False)
  since the agent no longer handles it
- .lazy-refresh-incomplete: remove stale temp file
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 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.

2 participants