fix(cascade): scope LanceDB row ids by md path to stop cross-project overwrites - #430
Open
alexmat wants to merge 1 commit into
Open
fix(cascade): scope LanceDB row ids by md path to stop cross-project overwrites#430alexmat wants to merge 1 commit into
alexmat wants to merge 1 commit into
Conversation
…overwrites
Every daily-log handler built row ids as f"{owner_id}_{entry_id}" and
user_profile as bare owner_id. Entry numbering is per-file
(<kind>_<date>_NNNNNNNN), so any two projects with a same-date file
produce identical row ids and merge_insert("id") replaces the
previous project's rows wholesale — only the last-processed file per
date survives. Proven in production (1.2.3) by version-walk: one
transition swapping 54 rows between two projects' same-date files at
identical entry_ids; user_profile collapsed 16 project profiles to 2.
Row id is now f"{md_path}#{entry_id}" for the four daily-log kinds
and md_path for user_profile (path unique by construction, robust to
future layout dimensions). Profile recall derives the same path from
app/project/owner.
Adds a parametrized coexistence regression test (fails on <= 1.2.3,
passes with the fix). Migration note: existing deployments need a full
cascade rebuild — sha-skip keeps old-id rows otherwise.
Fixes EverMind-AI#320
alexmat
marked this pull request as ready for review
September 2, 2026 13:40
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.
Fixes #320.
Problem
Every daily-log cascade handler built LanceDB row ids as
f"{owner_id}_{entry_id}", anduser_profileas bareowner_id. Entry numbering is per-file (<kind>_<date>_NNNNNNNN), so any two projects with a same-date file produce identical row ids — andmerge_insert("id")treats the previously indexed project's rows as matches and replaces them wholesale. Only the last-processed file per date survives.Confirmed in production on 1.2.3 (current PyPI latest;
mainwas still building ids the same way before this patch), in a multi-project deployment (~20 projects, one owner):atomic_facttable stayed pinned at exactly 5,194 rows for 13+ hours while hundreds of commits landed — every insert was silently a replacement.list_versions+ per-version counts) shows the mechanism in lockstep. One transition as the smoking gun: v2263 → v2264: −54 rows from projectcomms'atomic_fact-2026-08-27.md, +54 rows from projectdsh-69826's same-date file, with identical entry_ids (af_20260827_00000018,…46,…19, …).user_profile(id = owner_id) collapsed 16 project profiles into 2 rows — the last two projects written.Affected handlers:
atomic_fact,episode,foresight,agent_case(allid=f"{owner_id}_{entry.entry_id}"), plususer_profile(id=owner_id).Fix
Row id derives from the file's relative path plus entry id rather than enumerating scope keys — the path is unique by construction and stays correct if a new layout dimension appears later:
id = f"{md_path}#{entry_id}"user_profile:id = md_path(of theuser.md), with the recall-side profile fetch deriving the same path fromapp_id/project_id/owner_id(ProfileRecaller.fetchgainsapp_id/project_idparams; call site insearch/manager.pypasses them from the request)Regression test
tests/unit/test_memory/test_cascade/test_handler_row_id_project_scoping.py— parametrized over the four daily-log kinds: writes the same-date entry for two different projects through each writer + handler pair against an in-memory repo with merge-by-id semantics, and asserts both projects' rows coexist under distinct ids. Fails on ≤ 1.2.3 (4/4 fail), passes with this patch (4/4 pass).Migration note for existing deployments
A full
cascade rebuildis required after upgrading — sha-skip means old-id rows are never rewritten, and new-id rows would otherwise coexist as duplicates. Markdown is canonical, so the rebuild is lossless; parking the optimize/prune loop during the rebuild is advisable. Post-fix verification on our deployment: 14,735atomic_factrows indexed (2.8× the collision-era steady state), 17user_profilerows, zero cross-project replacements across 168 version transitions and a full optimize+prune cycle.Follow-up (not in scope)
atomic_fact.parent_idstores the episode'sentry_id, so fact→episode parent resolution has the same cross-project ambiguity on same-date episode files. Worth its own issue/PR.