fix(honcho): pass user_message as search_query for topic-relevant context injection - #17021
Closed
qxxaa wants to merge 2 commits into
Closed
fix(honcho): pass user_message as search_query for topic-relevant context injection#17021qxxaa wants to merge 2 commits into
qxxaa wants to merge 2 commits into
Conversation
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.
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.
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
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.
Problem
get_prefetch_context()accepts auser_messageparameter but intentionally discards it, with a comment explaining that passing it assearch_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'speer.context()returns the full peer representation: all observations, derived conclusions, and peer card, in insertion order. WhencontextTokensis 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_messageassearch_queryto_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 passessearch_queryto the Honcho API — this change simply connects the two. The total diff is 2 lines.Behaviour when user_message is None
user_message or Nonepreserves 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 linesTesting
recallMode: hybridandinjectionFrequency: first-turnin honcho.json