fix(core): reject stale file reconciliation - #1149
Merged
Merged
Conversation
Signed-off-by: phernandez <paul@basicmachines.co>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c26b3415e1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: phernandez <paul@basicmachines.co>
14 tasks
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.
Why
A note write accepted through MCP or the browser can race with file indexing that
started from an older Tigris object. Before this change, the stale indexing pass
could reconcile its older Markdown back into
note_content, effectively makingan accepted write disappear from the canonical database state and file history.
This is the Core half of the single-editor persistence work tracked in
https://github.com/basicmachines-co/basic-memory-cloud/issues/1589.
What Changed
note_contentreconciliation state before indexing anexisting Markdown file.
captured anchor.
advance canonical state when the prior file write was fully synchronized and
its file/database versions and checksums agreed.
canonical state while indexing was in flight.
note_contentabsence as an anchor rather than disabling theoptimistic check for newly indexed entities.
observation, relation, and search projections cannot finish on old Markdown.
immediate retry stale.
regression tests.
Implementation Details
NoteContentReconciliationAnchorrecords the pre-index canonical version,checksums, and file-write status.
FileIndexercaptures that anchor beforeparsing an existing Markdown file and passes it to the reconciler after the
entity update.
The reconciler treats the anchor as an optimistic concurrency boundary:
and cannot promote its file content.
baseline (
file_write_status == "synced", equal file/database versions, andequal file/database checksums).
Reconciliation returns an explicit
currentorstaleoutcome. A staleoutcome makes the per-file indexer run one fresh pass from current storage,
repairing every derived projection. A second stale outcome raises rather than
reporting a false success, allowing the existing indexing job retry policy to
converge later.
This preserves first-writer CAS behavior without adding locks or a second
version authority.
Testing
uv run pytest -q tests/indexing/test_note_content_reconciliation.py tests/indexing/test_note_content_reconciler.py tests/indexing/test_file_indexer.py tests/indexing/test_index_batch_runtime.py tests/indexing/test_note_content_batch_reconciliation.pyjust fast-checkgit diff --checkRisks / Follow-ups
merged Core SHA and publish the File History conflict-resolution UI already
verified locally.
pinned to this Core change.