Skip to content

Session search truncation treats FTS5 boolean operators as search terms #4238

@Rizk-Taker

Description

@Rizk-Taker

Bug Description

_truncate_around_matches() in tools/session_search_tool.py (line 89) splits the search query on whitespace to find text positions for centering the truncation window. This means FTS5 boolean operators like OR, AND, NOT become search terms themselves.

For a query like "Luka OR resume OR Injoy", the function searches for ["luka", "or", "resume", "or", "injoy"]. The word "or" matches extremely early in any conversation, so the 100K char window centers on irrelevant content near the top of the transcript.

Steps to Reproduce

  1. Have a long session (280K+ chars, full day of conversation)
  2. Search with a query containing OR operators: "topic1 OR topic2 OR topic3"
  3. The relevant content is in the latter half of the session
  4. _truncate_around_matches finds "or" on line ~50, centers window there
  5. Gemini/Claude summarizer receives a window that doesn't contain the actual matching content
  6. Summary correctly reports "no discussion about topic1/topic2/topic3 found"

Root Cause

# line 100 in session_search_tool.py
query_terms = query.lower().split()

This naive split doesn't strip FTS5 operators. The FTS5 engine correctly interprets OR as a boolean operator, but the truncation function treats it as a literal search term.

Suggested Fix

Strip known FTS5 operators before splitting:

_FTS5_OPERATORS = {"and", "or", "not", "near"}
query_terms = [t for t in query.lower().split() if t not in _FTS5_OPERATORS]

Impact

Any session search using boolean operators (which the tool's own schema recommends: "Use OR between keywords for best results") will mis-center the truncation window on common English words, causing the summarizer to miss the actual relevant content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/toolsTool registry, model_tools, toolsetssweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions