Skip to content

fix(transfer): remap mental-model evidence on documents import - #5657

Merged
nicoloboschi merged 2 commits into
mainfrom
fix/merge-import-mm-evidence-remap
Oct 16, 2026
Merged

nicoloboschi merged 2 commits into
mainfrom
fix/merge-import-mm-evidence-remap

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5298.

Bug: importing a documents archive into a bank gives every fact and observation a new id, but the mental models in the archive kept citing the old (source-bank) ids in reflect_response.based_on. Their evidence pointed at nothing in the new bank.

Fix: call _remap_mental_model_evidence before restoring the models, the same step the whole-bank restore already runs.

Test: new system story in test_52_transfer.py: a mental model cites real facts and an observation, gets exported with the documents, imported into a new bank, and every id it cites must exist there. Fails without the fix (cites memory ids that do not exist in this bank), passes with it.

Note: an api-slim DB test for the same thing was flaky locally (the import sometimes reported a fact id that wasn't in the target bank). I dropped it in favour of the system story; that mismatch may be worth its own look.

A documents import replays facts and observations under fresh ids and records
the mapping, but restored the carried mental models' reflect_response.based_on
verbatim, so their evidence kept naming source-bank ids. Apply the same
_remap_mental_model_evidence the whole-bank restore already uses.

System story 52 now checks that an imported mental model's cited ids exist in
the destination bank; it fails without the fix.
Review fix: assert the model cites exactly the two facts and the observation,
by text, instead of only checking its ids are a subset of the destination's.
@nicoloboschi
nicoloboschi merged commit 4b5f045 into main Oct 16, 2026
117 checks passed
@nicoloboschi
nicoloboschi deleted the fix/merge-import-mm-evidence-remap branch October 16, 2026 10:34
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 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.

Document merge import leaves mental-model based_on citations pointing at source-bank memory IDs

1 participant