Skip to content

Let a filtered-out seed still anchor its segment context - #1498

Closed
edwinyyyu wants to merge 1 commit into
MemMachine:mainfrom
edwinyyyu:seed-anchors-window
Closed

Let a filtered-out seed still anchor its segment context#1498
edwinyyyu wants to merge 1 commit into
MemMachine:mainfrom
edwinyyyu:seed-anchors-window

Conversation

@edwinyyyu

@edwinyyyu edwinyyyu commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Problem

get_segment_contexts applies property_filter to 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:

  • returned when it passes, omitted when it does not;
  • a seed whose entire window is filtered away stays absent from the returned mapping rather than mapping to an empty list, which the 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_context located the seed inside its own context with a bare next(...), which would now raise StopIteration. 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_memory suite, with and without the change, fails exactly the same 8 tests on this machine (all missing NLTK punkt_tab data, unrelated), and passes 4 more with it.

🤖 Generated with Claude Code

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
edwinyyyu force-pushed the seed-anchors-window branch from 78bd1e6 to 3f73fae Compare August 10, 2026 20:33
@edwinyyyu edwinyyyu closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant