fix(session_search): exclude entire session lineage from recent sessions list#3531
Open
dieutx wants to merge 1 commit intoNousResearch:mainfrom
Open
fix(session_search): exclude entire session lineage from recent sessions list#3531dieutx wants to merge 1 commit intoNousResearch:mainfrom
dieutx wants to merge 1 commit intoNousResearch:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After context compression,
session_searchwith no query (browsing recent sessions) shows the current conversation's parent session in the results. The agent sees its own conversation as a separate "recent session" and may waste tokens recalling from itself.Root Cause
_list_recent_sessionsatsession_search_tool.py:211usesmax(visited, key=len)to find the root session of the current lineage. This picks the session ID with the longest string, not the actual root parent. If the child ID is longer than the parent ID, the wrong session is identified as root and the real parent leaks into results.The correct pattern already exists in the same file —
_resolve_to_parentat line 298 walks the chain and returns the lastsidreached. But_list_recent_sessionsuses a different, broken approach.Additionally, line 218 only excludes
current_rootandcurrent_session_id— but intermediate sessions in a deep chain (grandparent→parent→child) are not excluded.Fix
Replaced the
max(visited, key=len)approach with a proper parent-chain walk that captures the actual root. Changed the exclusion check from comparing two IDs to checking membership in the fullcurrent_lineageset — so all sessions in the chain (root, intermediate, current) are excluded.Tests
4 new tests: parent excluded after compression, deep A→B→C chain all excluded, no-compression session excluded, None current_session returns all.