Skip to content

fix(api): re-check mental-model edits under the row lock so the vector matches the stored text - #5619

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/mental-model-edit-race
Oct 15, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
fix/mental-model-edit-race

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5297. Re-lands the mental-model part of #5513 (reverted in 65ef1bd for unrelated reasons).

update_mental_model embeds name + content from a read taken before the row lock. If a concurrent edit changes the half the caller didn't send, the write stored a vector for the old text.

  • Document edits now take the same FOR UPDATE row lock trigger patches already use.
  • Under the lock: re-embed only if the half the caller didn't send has moved (rare). The common path still embeds off the lock.
  • History snapshot now comes from the locked row, so it is the content this write actually replaces.

Regression test test_concurrent_edit_does_not_persist_a_stale_embedding pauses a rename mid-embedding, commits a content edit, and checks the final vector matches a clean sequential edit. Fails on main, passes here.

…r matches the stored text

A document edit embedded from a pre-image read off the lock; a concurrent
edit could move the half the caller did not send, and the write then stored a
vector for text the model no longer holds (#5297). The edit now takes the row
lock, re-embeds only if that half moved, and takes the history snapshot from
the locked row. Re-lands the #5513 part reverted in 65ef1bd.

Fixes #5297
@nicoloboschi
nicoloboschi merged commit 82ad30e into main Oct 15, 2026
117 checks passed
@nicoloboschi
nicoloboschi deleted the fix/mental-model-edit-race branch October 15, 2026 13:23
@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.

Concurrent mental-model edits persist an embedding for an obsolete name/content pre-image

1 participant