Skip to content

bm_read omits checksum on full reads of binary files #2150

Todo

Description

@phernandez

Problem

A full bm_read of a non-Markdown binary file (a PDF or an image) returns the file content without a checksum field. Markdown notes and text files include it. A customer's backup job checks each file against Basic Memory's stored checksum. Because of this, it reads the PDF's checksum as empty (length 0), and the check fails on every run, even though the file is intact.

The checksum does exist. bm_read(..., include_content=false) returns it for any file type, and the entity row has it.

Where

src/basic_memory/mcp/tools/read.py, in the # --- Files that are not Markdown notes --- branch:

  • _present_file(...) returns image content or document.to_resource_content(...) for binaries, with no metadata attached.
  • The text-file path returns a dict through target.paths.note(...), and the metadata-only path includes "checksum": entity.db_checksum.

The JSON output of bm tool read --json for a binary therefore has no checksum to report.

Second issue: what the checksum means

In Cloud, db_checksum is the storage ETag: 32 hex characters, which for single-part uploads is the MD5 of the bytes. Locally it is SHA-256 (64 hex characters). Projects can even mix both (one production workspace has 32- and 64-character values side by side). Callers have no way to tell which algorithm a value uses, so comparing it with a local SHA-256 fails even when the file is intact.

Proposed

  1. Include checksum (and content_type, file_path) in the JSON result of a full binary read, matching text files and notes.
  2. Document what the checksum is, or return it with its algorithm (for example checksum_algorithm: "md5-etag" | "sha256"), so backup and verification tools can compare correctly.

Done when

  • bm tool read --cloud --json on a PDF returns a non-empty checksum.
  • The docs (or the response itself) say which hash the checksum is.
  • There is a test for a full binary read in JSON output that asserts the checksum is present.

Activity

  1. added
    bug
    on Nov 25, 2026
  2. claude commented on Nov 25, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 13s —— View job


    Triage

    • Type: Bug (labeled bug, cloud)
    • Component: MCP tools (read.py, non-Markdown branch) and CLI JSON output. The checksum semantics concern Cloud, since the storage ETag is MD5 there and SHA-256 locally.
    • Priority: Medium-High. A customer's backup verification fails on every run, but the data is intact and there is a workaround: include_content=false returns the checksum.
    • Complexity: Simple to Medium.
      • Part 1: add checksum, content_type and file_path to the binary read result. This is a small change plus a test.
      • Part 2: either document the algorithm or return a checksum_algorithm field. This needs a design decision, because Cloud can mix 32-character MD5 ETags and 64-character SHA-256 values in the same project. Inferring the algorithm from the checksum length is fragile, so it would be better to record the algorithm at write time.

    Duplicates: I searched for existing issues on checksums in binary reads and found none.

    Notes: The issue is clear and includes a location, a proposal and acceptance criteria. I did not investigate further or implement anything, because this was triage only.

  3. added
    cloud
    on Nov 25, 2026
  4. arturbordignon commented on Nov 29, 2026

    @arturbordignon

    Hi! I'd like to take this one.

    Plan: in the non-Markdown branch of bm_read, add checksum (from entity.db_checksum), content_type and file_path to the JSON result for images and documents, matching what a metadata-only read returns. I'll add a test for a full binary read in JSON that asserts a non-empty checksum.

    For the second part, would you prefer a docs note (SHA-256 locally, the storage ETag in Cloud) or a checksum_algorithm field in the response? A docs note keeps this PR small. The field would need the API to report which hash it stored, unless inferring it from the length (32 vs 64 hex characters) is acceptable.

  5. arturbordignon commented on Nov 29, 2026

    @arturbordignon

    Quick finding while reproducing: locally, include_content=false also returns checksum: null for a PDF, PNG or JSON file. Plain files go through entity_metadata_response_payload, which drops db_checksum on purpose (ENTITY_METADATA_PAYLOAD_EXCLUDE), and EntityResponseV2 has no field for Entity.checksum (the file's SHA-256). My guess is that Cloud fills db_checksum with the storage ETag, which is why it shows up there.

    The MCP side is ready on my branch: a top-level checksum in JSON for text files, and {file_path, checksum} in the content block's _meta for images and documents, so clients can still display them.

    For the API side, which would you prefer?

    1. Expose Entity.checksum for non-note files through a new field (e.g. checksum), leaving the note-content fields excluded.
    2. Fill db_checksum from Entity.checksum for non-note files, matching what Cloud returns.
  6. phernandez commented on Nov 29, 2026

    @phernandez
    MemberAuthor

    Thanks for taking this, @arturbordignon, and for the extra finding about include_content=false.

    1. Checksum algorithm: a docs note is enough for this PR (SHA-256 locally, the storage ETag in Cloud). Cloud: keep content checksum and storage ETag in separate entity columns #1644 tracks splitting the content checksum and the storage ETag into separate columns in Cloud. That's where the mixing gets fixed properly, so please don't infer the algorithm from the checksum length.
    2. API: option 1. Add a checksum field filled from Entity.checksum for non-note files, and leave db_checksum alone. Option 2 would give db_checksum two meanings, which is what Cloud: keep content checksum and storage ETag in separate entity columns #1644 is meant to undo.

    Your MCP side sounds right: top-level checksum in JSON for text files, and file_path/checksum in the content block's _meta for images and documents. Please include a test for a full binary read and one for a metadata-only read, both asserting a non-empty checksum.

  7. added this to the v1.1 milestone on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcloud

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions