Skip to content

fix(session_search): use original session ID for content retrieval #22150

@stevenliou

Description

@stevenliou

Bug

FTS5 search was returning wrong session content. When searching 'headless-chatgpt', the search correctly matched a child session (20260509_013938_e105c7, 156 msgs) via FTS5, but then the code fetched content from the resolved parent session (20260508_133608_740f82d1, 42 msgs) — which doesn't contain the matched text.

Root Cause

In tools/session_search_tool.py, the _resolve_to_parent helper overwrites result['session_id'] with the parent sid. Then get_messages_as_conversation(resolved_sid) fetches from the parent, not the child where the actual content lives.

# Before (buggy)
result['session_id'] = resolved_sid  # ← overwrites original child sid
messages = get_messages_as_conversation(resolved_sid)

Fix

Preserve the original session ID for content retrieval, add a separate resolved_session_id field for dedup logic:

# After (fixed)
seen_sessions.add(resolved_sid)
if resolved_sid != sid:
    result['resolved_session_id'] = resolved_sid
# session_id stays as original for content retrieval
messages = get_messages_as_conversation(sid)

Verification

  • Child session 20260509_013938_e105c7: 156 msgs, contains 'headless-chatgpt' (13 occurrences)
  • Parent session 20260508_133608_740f82d1: 42 msgs, no 'headless-chatgpt'
  • After fix: content_sid correctly points to 20260509_013938_e105c7

Commit

69c55d61d — fix(session_search): use original session ID for content retrieval

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