Skip to content

fix: improve session_search lineage recall#6536

Draft
markusleben wants to merge 1 commit into
NousResearch:mainfrom
markusleben:fix/session-search-lineage-recall
Draft

fix: improve session_search lineage recall#6536
markusleben wants to merge 1 commit into
NousResearch:mainfrom
markusleben:fix/session-search-lineage-recall

Conversation

@markusleben

Copy link
Copy Markdown

Summary

  • fix session_search so it can retain matched child/continuation content within a resolved root lineage
  • anchor summaries with matched search snippets instead of relying only on transcript truncation
  • add regression tests for lineage recall, metadata consistency, and fallback preview behavior

Problem

session_search could find a hit in a child/continuation session, resolve it to the lineage root, and then summarize only the root transcript. In practice that meant later continuation content could disappear from recall, especially for broader queries spanning both root and child sessions.

This PR is an attempted fix for #6507 based on a local reproduction and iterative validation.

What changed

  • keep multiple hit_session_ids per resolved root instead of only the first hit
  • merge root→…→hit paths for all matched sessions under the same resolved root
  • use root session metadata consistently in final results
  • pass matched snippets into the summarizer prompt as explicit evidence
  • improve _truncate_around_matches() so quoted phrases are preferred over common-token anchoring
  • re-center fallback previews around the match instead of always taking the first 500 chars

Validation

Local validation performed:

  • python -m pytest tests/tools/test_session_search.py tests/tools/test_llm_content_none_guard.py -q
  • real local state.db repro for yesterday's Telegram session chain
  • independent code-review passes on the patch/diff

Relevant regression coverage added for:

  • child-hit fallback preview includes lineage content
  • root metadata stays consistent
  • multiple results keep per-session metadata
  • same-root root-hit + child-hit broad query case
  • summarizer prompt includes matched snippets from both root and child hits
  • quoted phrase truncation behavior

Notes

  • This is intentionally opened as a draft / attempted fix rather than a “definitive merge now” PR.
  • Local validation looked good, but I’d appreciate maintainer feedback on whether this lineage-merging approach matches the intended session-search semantics.

Closes #6507

- merge matched child/root hits within the same session lineage
- anchor summaries with matched snippets and better fallback previews
- add regression tests for lineage recall, metadata, and truncation
@markusleben

Copy link
Copy Markdown
Author

One small follow-up question / nice-to-have while I was validating this locally:

I noticed agent/prompt_builder.py currently tells the model for Telegram:

  • “Please do not use markdown as it does not render.”

But the Telegram adapter itself appears to support MarkdownV2/fenced code blocks pretty explicitly (gateway/platforms/telegram.py has MarkdownV2 escaping, code-block handling, tests, and plain-text fallback on parse failure).

That made me wonder whether the current Telegram “no markdown” hint is:

  • just an older conservative prompt hint,
  • or intentionally kept for some safety / prompt-injection / rendering reason I’m missing.

I didn’t include that change in this PR on purpose — this PR stays focused on session_search lineage recall.

But if the current Telegram hint is not intentional for security/robustness reasons, I think there may be a nice small follow-up improvement there: let Telegram shell commands / logs render as proper fenced code blocks instead of plain text blobs.

Happy to open a tiny separate follow-up PR for that if useful — or ignore it if the current wording is deliberate.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets labels Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: session_search drops child/continuation-session hits by summarizing only the lineage root

2 participants