Skip to content

fix(memory): keep temporal reads correct for superseded and merged entries - #27

Merged
ipiton merged 2 commits into
mainfrom
bugfix/t191-temporal-supersession
Nov 18, 2026
Merged

ipiton merged 2 commits into
mainfrom
bugfix/t191-temporal-supersession

Conversation

@ipiton

@ipiton ipiton commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Makes temporal reads correct for superseded entries and merged duplicates.

  • recall_as_of selects entries by their valid_from / valid_until window, including superseded ones. The window is checked before the result limit.
  • knowledge_timeline includes superseded entries.
  • Plain Recall keeps hiding superseded entries and now also hides merged duplicates.
  • merge_duplicates records supersession on the duplicate: SupersededBy points to the primary entry and ValidUntil is the merge time, unless the window closed earlier.
  • recall_as_of returns both entries before the merge and only the primary entry from the merge onward.
  • Temporal reads no longer increase targeted_access_count or write recall_events, so browsing history does not promote stale entries.
  • Merging into an already retired primary entry is rejected with a validation error.
  • recount_references does not count merges as references.

Why?

recall_as_of and knowledge_timeline were built on Recall, which hides superseded entries. For a date before the replacement, the old entry was already filtered out and the new one was not valid yet, so the answer was empty or incomplete, and it looked plausible. Merged duplicates had the opposite problem: only metadata marked them, so they stayed visible at every date.

Migration

The first time a new version opens a bank, a one-time migration (user_version = 2) backfills the temporal columns of existing merged duplicates. It runs automatically. It keeps values already present, skips entries later promoted to canonical, and leaves entries merged into each other in a cycle visible.

It has been tested on test banks only. Back up the bank before the first start on real data.

How to test

  1. make vet
  2. go test -race ./...
  3. See internal/memory/temporal_supersession_test.go and internal/memory/merge_supersession_test.go for the covered behavior.

Known limitations: when several entries are superseded by the same entry, valid_from of the replacement is overwritten each time, so recall_as_of may find no valid entry between the first and last supersession. An entry with an empty valid_from is treated as valid before its creation, as it was before this change.

Checklist

  • go test ./... passes
  • go vet ./... passes
  • Documentation updated (if behavior changed)
  • No hardcoded paths or API keys

recall_as_of and knowledge_timeline went through Recall, which hides superseded entries, so a date before the replacement returned nothing.

Both now rank through a shared recall path with their own admission rule. The validity window is applied before the result limit, and history reads no longer count as targeted access.
MergeDuplicates recorded the merge only in metadata, so a merged duplicate stayed in Recall and in recall_as_of for every date.

The duplicate now gets superseded_by and a closed validity window. The primary keeps its temporal fields because it existed before the merge. Merging into a retired primary is refused, and recount_references ignores merge links.

A one-time migration fills the columns for duplicates merged by earlier versions.
@ipiton
ipiton merged commit bc10870 into main Nov 18, 2026
5 checks passed
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