Repository navigation
fix(memory): keep temporal reads correct for superseded and merged entries - #27
Merged
Merged
Conversation
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.
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.
What does this PR do?
Makes temporal reads correct for superseded entries and merged duplicates.
recall_as_ofselects entries by theirvalid_from/valid_untilwindow, including superseded ones. The window is checked before the result limit.knowledge_timelineincludes superseded entries.Recallkeeps hiding superseded entries and now also hides merged duplicates.merge_duplicatesrecords supersession on the duplicate:SupersededBypoints to the primary entry andValidUntilis the merge time, unless the window closed earlier.recall_as_ofreturns both entries before the merge and only the primary entry from the merge onward.targeted_access_countor writerecall_events, so browsing history does not promote stale entries.recount_referencesdoes not count merges as references.Why?
recall_as_ofandknowledge_timelinewere built onRecall, 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
make vetgo test -race ./...internal/memory/temporal_supersession_test.goandinternal/memory/merge_supersession_test.gofor the covered behavior.Known limitations: when several entries are superseded by the same entry,
valid_fromof the replacement is overwritten each time, sorecall_as_ofmay find no valid entry between the first and last supersession. An entry with an emptyvalid_fromis treated as valid before its creation, as it was before this change.Checklist
go test ./...passesgo vet ./...passes