Let a filtered-out seed still anchor its segment context - #1498
Closed
edwinyyyu wants to merge 1 commit into
Closed
Conversation
get_segment_contexts applied property_filter to the seed lookup itself, so a seed that did not match was dropped before its window was built and the caller got nothing back for it — not even the neighbours that do match. A filter excluding only the seed's own kind therefore answered "no context" rather than "here is the surrounding context of the kind you asked for". The seed is an address, not a candidate. Look it up unfiltered so it can anchor the window wherever it is, and apply the filter to it like any other row on the way out: it is returned when it passes and omitted when it does not, and a seed whose entire window is filtered away stays absent from the returned mapping rather than mapping to an empty list. build_query_result_context assumed the seed was present in its own context and used a bare next(), which would now raise StopIteration. It falls back to the start of the context, degrading seed-proximity ordering to chronological order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
edwinyyyu
force-pushed
the
seed-anchors-window
branch
from
August 10, 2026 20:33
78bd1e6 to
3f73fae
Compare
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.
Problem
get_segment_contextsappliesproperty_filterto the seed lookup itself. A seed that does not match the filter is dropped before its window is built, so the caller gets nothing back for it — not even the neighbouring segments that do match.The practical effect: a filter that excludes only the seed's own kind answers "no context" rather than "here is the surrounding context, of the kind you asked for". Asking to see the tool results around a message returns nothing, because the message is not a tool result.
Change
The seed is an address, not a candidate. It is looked up unfiltered so it can anchor its window wherever it is, and the filter is applied to it like any other row on the way out:
dict[UUID, list[Segment]]return already expresses unambiguously for multiple seeds.Deciding whether each seed passes costs one indexed lookup over the seeds alone, and only when a filter is present.
Caller that assumed otherwise
EventMemory.build_query_result_contextlocated the seed inside its own context with a barenext(...), which would now raiseStopIteration. It falls back to the start of the context, degrading seed-proximity ordering to chronological order for that context.I checked the rest of the tree for the same assumption; this was the only place.
Tests
Two new cases — the filtered-out seed keeps its window, and an entirely filtered window leaves the seed absent — running against SQLite and PostgreSQL, since both must have the same semantics.
Full
event_memorysuite, with and without the change, fails exactly the same 8 tests on this machine (all missing NLTKpunkt_tabdata, unrelated), and passes 4 more with it.🤖 Generated with Claude Code