Skip to content

fix(sync): treat a markdown path with a non-markdown type as dirty - #1542

Closed
wangzhengzhuo05 wants to merge 1 commit into
basicmachines-co:mainfrom
wangzhengzhuo05:fix/repair-wrong-type-entity
Closed

wangzhengzhuo05 wants to merge 1 commit into
basicmachines-co:mainfrom
wangzhengzhuo05:fix/repair-wrong-type-entity

Conversation

@wangzhengzhuo05

Copy link
Copy Markdown
Contributor

What

Fixes #1538. A row whose file_path is a markdown note but whose indexed content_type is not text/markdown can never be repaired, because change detection compares checksums only: the row's checksum already matches the file on disk, so every scan reports it unchanged and it is never re-parsed.

Reported shape of the corrupt row (an Emacs autosave took over the real note's file_path):

file_path     notes/note.md
note_type     file
content_type  text/plain
permalink     NULL
note_content  no row
checksum      matches the bytes on disk exactly

Appending a single byte to the file repairs the row completely, which shows the repair machinery is healthy — it just cannot be triggered.

How

EntityRepository.get_by_file_paths() already masks an indexed checksum to SQL NULL when the indexed projection is known to be incomplete even though the checksum matches (publication_pending, legacy_relation_pending, legacy_markdown_identity). A NULL checksum makes change detection re-read the canonical bytes.

This adds one more predicate to that same mask: the path is a markdown note path (.md / .markdown, case-insensitive) and the row's content_type is not RUNTIME_MARKDOWN_CONTENT_TYPE. Such a row is now treated as dirty regardless of checksum, so the next scan re-reads the file and _apply_markdown_entity_fields() repairs title, note_type, permalink, content_type and the note-content row in place — the same repair the manual one-byte append provokes.

Scope is deliberately the first acceptance clause of the issue ("a row whose file_path is a markdown path but whose content_type is not text/markdown"). No API, protocol, or row-shape change: get_by_file_paths() still returns (file_path, checksum).

Tests

tests/repository/test_entity_repository.py::test_get_by_file_paths_masks_markdown_path_without_markdown_type

  • a corrupt row (notes/note.md, content_type="text/plain", current checksum) is masked to None;
  • a healthy row (notes/note.md, content_type="text/markdown") keeps its real checksum, guarding against over-masking.

Verification (local)

uv run pytest tests/repository/test_entity_repository.py -q    # 37 passed
uv run pytest tests/indexing/ -q                               # 636 passed, 1 skipped
uv run ruff check / ruff format --check <changed files>        # clean

Mutation check: with markdown_path_without_markdown_type removed from the mask's or_(...), the new test fails (1 failed); restored, it passes. The test therefore guards this exact predicate and not incidental behaviour.


Implemented with AI assistance (OpenCode + muse-spark); reviewed, re-run and mutation-checked by the author before submission.

An indexed row whose file_path is a markdown note but whose content_type is
not text/markdown keeps a matching checksum, so change detection reports it
unchanged forever and the row is never re-parsed. Mask such a row's checksum
to unknown, alongside the existing incomplete-projection masks, so the next
scan re-reads the file and repairs the type fields in place.

Fixes basicmachines-co#1538

Signed-off-by: wangzhengzhuo05 <[email protected]>

@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: 35c3a5b237

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +416 to +417
func.lower(Entity.file_path).like("%.md"),
func.lower(Entity.file_path).like("%.markdown"),

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 Exclude extension-only resource basenames from the mask

For indexed resources named .md or .markdown (for example _phase7_import/.md, which runtime_file_path_is_markdown_note() and the existing regular-file tests intentionally classify as non-Markdown), these SQL LIKE predicates nevertheless match the path. Every subsequent event therefore receives a NULL indexed checksum and re-reads/reindexes the unchanged resource, after which it remains non-Markdown and is masked again, so this derived state never converges. Match the canonical PurePosixPath(...).suffix semantics, including its requirement for a nonempty basename, rather than raw string endings.

AGENTS.md reference: AGENTS.md:L161-L166

Useful? React with 👍 / 👎.

@wangzhengzhuo05

Copy link
Copy Markdown
Contributor Author

Superseded by #1543, which preserves the contributor commit (35c3a5b) and addresses the P2 review finding. Closing to keep the queue clean — thanks @phernandez.

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.

[BUG] Checksum-keyed reconciliation can never repair an entity row whose type is wrong — sync reports it “unchanged” forever

1 participant