Skip to content

[BUG] Cloud edit_note accepts stale expected_checksum on ordinary notes #1536

Closed

Description

@cfaust990

Bug Description

On an ordinary Basic Memory Cloud note with no review items, edit_note(operation="find_replace") accepted an outdated expected_checksum and modified the note.

Paul suggested in Discord that this looks like a core-library bug.

Steps To Reproduce

The observed test used a disposable synthetic note:

  1. Read the note using structured read_note and save its revision_checksum as cA.
  2. Append a marker, producing revision B.
  3. Read again and confirm its checksum differs from cA.
  4. Confirm the original replacement target still occurs exactly once in B.
  5. Call edit_note on the same note with:
    • operation="find_replace"
    • The original target as find_text
    • Replacement content
    • expected_replacements=1
    • expected_checksum=cA
  6. Read the note again to check whether the stale edit was rejected.

Expected Behavior

The stale precondition rejects the mutation with a recognizable conflict error. Revision B and its contents remain unchanged.

If checksum preconditions are unsupported on ordinary notes, supplying one should return an explicit error rather than silently proceed.

Actual Behavior

The replacement succeeded, and read-back confirmed the content changed.

Observed checksum prefixes:

  • Baseline A: eaec17de…
  • After marker append B: b3aa17dc…
  • After accepted stale edit: bb60d282…

The replacement target occurred exactly once, so replacement-count validation did not explain or prevent the stale edit. The appended marker and the note's identity remained intact.

Environment

  • Basic Memory Cloud through its ChatGPT connector
  • Observed September 11, 2026
  • Cloud server/core-library version: unknown
  • No local Basic Memory installation was used for this test
  • Disposable synthetic note with no review items; no production data involved

Additional Context

An automated reader can submit an edit based on outdated content while believing its supplied checksum protects against concurrent changes.

Our current workaround is an exclusive overnight maintenance window. No production data was lost in this test.

The MCP documentation describes expected_checksum in the context of reviewed notes. Please confirm whether accepting a stale checksum on an ordinary note is intended.

This sequential test demonstrates stale acceptance; it does not establish behavior under simultaneous racing writes.

Reference: https://docs.basicmemory.com/reference/mcp-tools-reference

Possible Solution

When an expected_checksum is supplied, enforce it on ordinary notes as well as reviewed notes, or explicitly reject it if unsupported. Validation and commit should be atomic so another writer cannot change the note between checking the checksum and saving.

A regression test should confirm stale rejection without mutation. A separate concurrency test could verify that two conditional writes based on the same revision produce exactly one success and one conflict.

Activity

  1. added
    bug
    on Sep 11, 2026
  2. added this to the v0.24.0 milestone on Sep 14, 2026
  3. phernandez commented on Sep 14, 2026

    @phernandez
    Member

    Milestone status (2026-09-14): confirmed current Cloud bug; no fix or PR exists yet.

    Current Basic Memory Cloud main at 16e5dba1eb164db1a42bae1e94eb1a2af1b56bd2 still gates expected_checksum only when a note contains comments or suggestions:

    if (storage.comments or storage.suggestions) and expected_checksum != entity.db_checksum:

    Therefore a supplied stale checksum on an ordinary note is still ignored, matching the report. This path lives in Cloud's hosted MCP review/edit wrapper, not the Core edit implementation, so delivery should be made in basic-memory-cloud (with this issue linked or moved as appropriate).

    Next step: enforce any supplied checksum before applying an ordinary-note edit, preserve the existing required-checksum rule for reviewed notes, and add regression coverage proving stale rejection leaves content unchanged. The actual write must retain the existing canonical CAS boundary; a read-only precheck by itself is not sufficient concurrency protection.

  4. phernandez commented on Sep 14, 2026

    @phernandez
    Member

    The fix is in Cloud PR https://github.com/basicmachines-co/basic-memory-cloud/pull/2071 (head b7a1956309877120a867b2961b1ccb9d68a7bc27).

    RCA: Cloud's hosted edit_note wrapper checked caller expected_checksum only for notes with comments or suggestions. For an ordinary note it ignored the supplied precondition and passed its newly read entity.db_checksum to PATCH/PUT. Core correctly enforced that header, but it represented the wrapper's newer read rather than the caller's revision.

    The fix rejects any supplied checksum that differs from the existing note's accepted checksum. Ordinary notes can still omit it; reviewed notes still require it. PATCH and PUT retain the server-read checksum header to protect against another write after wrapper validation. No new locks or retries.

    Verification: 84 targeted tests and just fast-check pass. Real FastMCP → mounted API → Cloud/Core mutation-service tests use disposable PostgreSQL and prove both read A/write B/stale edit A rejection and an injected write after the wrapper read, for PATCH and PUT. API plus independent database readback confirm B remains unchanged. Temporarily removing the wrapper guard makes both sequential regression tests fail because stale writes succeed.

    Ready for coordinator/user direction: all seven applicable CI checks passed on b7a1956309877120a867b2961b1ccb9d68a7bc27 (the two web-only checks were skipped). Codex completed that exact-head review and left a fresh +1 on the PR body at 2026-09-14 15:30:10 UTC. Final review/thread checks found no findings or unresolved threads. Not merged or deployed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions