hermes - 💡(How to fix) Fix session_search: loads entire conversation before truncation, causing slow recall for large sessions [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

In tools/session_search_tool.py, the flow is:

FTS5 search → get_messages_as_conversation(session_id) → _format_conversation(all messages) → _truncate_around_matches(text, query)

The entire conversation is loaded and formatted (line 438: messages = db.get_messages_as_conversation(session_id), then line 442: conversation_text = _format_conversation(messages)), and only then truncated. The expensive work is done before the relevant portion is identified.

Fix Action

Fixed

Code Example

FTS5 search → get_messages_as_conversation(session_id)_format_conversation(all messages)_truncate_around_matches(text, query)
RAW_BUFFERClick to expand / collapse

Problem

session_search loads and formats the entire conversation for every matched session before truncating to ~100K chars around matches. For large sessions, this causes significant latency in the "recall" phase — entirely outside the FTS5 index search and LLM summarization steps.

Real-world data

SessionMessagesContent sizeLoad + format cost
web-ui deployment866821 KBhigh
trojan setup428219 KBhigh
web-ui upgrade378258 KBmedium

A session with 866 messages takes noticeably longer to "recall" than one with 50 messages, even when the FTS5 match is instantaneous and only 2-3 messages actually match the query.

Root cause

In tools/session_search_tool.py, the flow is:

FTS5 search → get_messages_as_conversation(session_id) → _format_conversation(all messages) → _truncate_around_matches(text, query)

The entire conversation is loaded and formatted (line 438: messages = db.get_messages_as_conversation(session_id), then line 442: conversation_text = _format_conversation(messages)), and only then truncated. The expensive work is done before the relevant portion is identified.

Suggested fix

FTS5 has a built-in snippet() function that can return matching context directly from the index, without loading full conversations. Alternatively, the match positions returned by db.search_messages() could be used to load only the N messages before and after each match, then format just that window.

The key change: move truncation before formatting, or use FTS5 snippet() to avoid loading the full conversation entirely.

Affected code

  • tools/session_search_tool.pysession_search() function
  • hermes_state.pySessionDB.get_messages_as_conversation() (called with full session, no windowing support)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING