Skip to content

fix(session_search): allow compression-ended parents in search results#13841

Open
iamagenius00 wants to merge 2 commits into
NousResearch:mainfrom
iamagenius00:fix/session-search-compression
Open

fix(session_search): allow compression-ended parents in search results#13841
iamagenius00 wants to merge 2 commits into
NousResearch:mainfrom
iamagenius00:fix/session-search-compression

Conversation

@iamagenius00

Copy link
Copy Markdown
Contributor

Summary

Allow compression-ended parent sessions to appear in session_search results. After context compaction, the agent loses access to original messages (replaced by a compact summary), but the previous lineage exclusion logic skipped them — creating a memory black hole.

Closes #13840
Supersedes #13501 (closed — this version addresses review concerns preemptively)
Related: #5447, #6256, #6507, #8803

What changed

tools/session_search_tool.py

  • _resolve_to_parent() now returns (root_id, has_compression_hop) — checks end_reason == "compression" during the same db.get_session() call it already makes for parent traversal (no additional DB queries)
  • Lineage exclusion: delegation parents are still skipped (content is in context); compression parents are allowed through (content is gone)

tests/tools/test_session_search.py (+3 tests)

  • test_current_child_session_excludes_delegation_parent — delegation parents still excluded (renamed from old test, clarified intent)
  • test_compression_parent_searchable — single-level compaction parent appears in results
  • test_multi_level_compression_parent_searchable — A→B→C chain where both A and B are compression parents

Design decisions

Why return a flag from _resolve_to_parent instead of a separate helper?
The parent traversal already calls db.get_session() for every hop. Checking end_reason in the same loop avoids N+1 queries that a separate _is_compression_session() helper would require.

Why whitelist (allow compression) instead of blacklist (exclude delegation)?
Current implementation checks not has_compression — if a future end_reason type is added where content is also lost, it would be excluded by default. This is the safer direction: new end_reasons default to excluded (same as current behavior), compression is the explicit exception. If more end_reasons need the same treatment, they can be added to the compression check.

Testing

$ python -m pytest tests/tools/test_session_search.py -v
37 passed in 2.88s

All 37 tests pass (34 existing + 2 new compression tests + 1 renamed delegation test).

…rch results

Compression-ended parent sessions contain content no longer in the agent's
context window (replaced by a compact summary). The previous lineage
exclusion logic skipped them along with delegation parents, creating a
memory black hole for compacted content.

Changes:
- _resolve_to_parent() now returns (root_id, has_compression_hop), reusing
  the db.get_session() call already made during parent traversal (no extra
  queries)
- Lineage exclusion skips delegation parents but allows compression parents
- Tests: delegation exclusion, single compression, multi-level compaction

37 tests pass.

Closes NousResearch#13840
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround tool/memory Memory tool and memory providers comp/tools Tool registry, model_tools, toolsets labels Apr 22, 2026
@trevorgordon981

Copy link
Copy Markdown

I have verified this solution by inspecting the code changes and running the new test suite. The fix modifies to track whether a lineage chain includes a compression-ended session. It correctly excludes delegation parents (non-compression) from search results but includes compression-ended parents, whose content is no longer in the agent's context window. The new unit tests confirm that compression parents are searchable, while delegation parents remain excluded. This eliminates 'memory black holes' for compressed conversations.

Tested and confirmed. ✅

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 P1 High — major feature broken, no workaround tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[session_search] Compression-ended parent sessions excluded from search results — memory black hole

3 participants