Skip to content

fix(mcp): return the checksum on reads of files that are not notes - #2179

Open
arturbordignon wants to merge 2 commits into
basicmachines-co:mainfrom
arturbordignon:fix/2150-binary-read-checksum
Open

arturbordignon wants to merge 2 commits into
basicmachines-co:mainfrom
arturbordignon:fix/2150-binary-read-checksum

Conversation

@arturbordignon

Copy link
Copy Markdown

Fixes #2150.

Problem

bm_read returned no checksum for files that are not Markdown notes. A full read of a PDF or image carried no metadata at all, and locally even a metadata-only read (include_content=false) returned checksum: null, because plain files go through entity_metadata_response_payload, which excludes db_checksum, and EntityResponseV2 had no field for Entity.checksum.

Change

As agreed in the issue:

  • API: EntityResponseV2 gets a checksum field. Plain files fill it from Entity.checksum through model_validate(entity); the accepted-note payload doesn't set it, so notes keep db_checksum and db_checksum keeps its single meaning (Cloud: keep content checksum and storage ETag in separate entity columns #1644).
  • MCP (bm_read):
    • a metadata-only read returns db_checksum for a note and checksum for any other file;
    • a full JSON read of a text file returns a top-level checksum;
    • an image or document carries {file_path, checksum} in the content block's _meta, so clients can still display it.
      A text-mode read of a text file stays plain text and makes no extra call.
  • Docs: docs/ai-assistant-guide-extended.md says a file's checksum is its SHA-256 locally and the storage ETag in Cloud.

Tests

In tests/mcp/test_tool_bm_read.py, through the real ASGI stack:

  • test_a_file_metadata_read_returns_its_checksum (PNG, PDF, JSON): metadata-only read, non-empty checksum;
  • test_a_binary_read_carries_its_path_and_checksum (PNG/PDF, JSON and text output): full read, non-empty checksum in _meta, equal to the metadata read's;
  • test_a_text_file_json_read_carries_its_checksum: full JSON read of a text file.

All fail on main and pass with this change.

uv run pytest tests -n 4                 # 8853 passed; the 6 failures in test_ci_test_selection.py need the `just` binary, which this machine doesn't have
uv run pytest tests/mcp tests/api/v2 tests/cli -n 4   # 3104 passed after the last change
uv run ruff check / ruff format --check  # clean
uv run pyright <changed files>           # 0 errors
uv run ty check src tests test-int       # same 4 pymilvus import diagnostics as on main

Signed-off-by: Artur Bordignon <arturbordignon6@gmail.com>
@CLAassistant

CLAassistant commented Nov 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T18:59:15.623435Z 272bdd3 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 272bdd3793

ℹ️ 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".


# A file that is not a note has no note_content row, so its own checksum is the
# one a caller can verify. Notes carry `db_checksum` instead.
checksum: Optional[str] = Field(None, description="Checksum of a file that is not a note")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the file checksum out of Markdown-note responses

EntityResponseV2 uses from_attributes=True, so validating an ORM Entity fills this field from Entity.checksum without checking its path. The knowledge_router.index_file response does exactly that even though the endpoint only indexes Markdown, and get_entity_by_id does it for legacy fallbacks. Those note responses now expose a physical-file hash as this non-note checksum while db_checksum is null, so clients can mistake it for the accepted note revision. Populate this field only on non-note responses or clear it on note response paths.

AGENTS.md reference: AGENTS.md:L157-L167

Useful? React with 👍 / 👎.

Signed-off-by: Artur Bordignon <arturbordignon6@gmail.com>
@arturbordignon

arturbordignon commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

Good catch, fixed in the latest commit. Rather than clearing the field at each construction site, EntityResponseV2 now has an after-validator that sets checksum to null whenever file_path is a Markdown note (runtime_file_path_is_markdown_note, the same check bm_read uses), so index_file, the legacy get_entity_by_id fallback and any future model_validate(entity) call can't leak the file hash onto a note. test_index_file_keeps_the_file_checksum_off_a_note checks the raw JSON of index-file for a Markdown file, it failed before the fix with the file's SHA-256 in checksum.

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.

bm_read omits checksum on full reads of binary files

2 participants