docir — design documents Graph

Documents / Issues / issue-1ccfda8b9c1e

A miss on an unparseable file reports the document as nonexistent

get, update, archive and delete answered 'no document with id' for an id whose file a hand edit left unparseable, so the reader re-added a document that was on disk.

issue-1ccfda8b9c1eissueresolved#cli#integrity#material
View as Markdown◉ View in graph

Class: misleading · Severity: material Flow: arch-0368cc754c15 (the write path) · Step: every by-id lookup's miss Frequency: every get, update, archive, unarchive or delete naming a document whose file a hand edit left unparseable

Finding

A file whose frontmatter does not parse is skipped by docir reindex, so the index holds no row for it and every read path treats it as absent — by design. The miss, though, was worded exactly like an id that never existed: no document with id '<id>', exit 4. Nothing in it said a file on disk claims the id.

What happens today

REPORTED by acceptance testing of 0.30.4, reproduced three times:

text
# hand edit leaves  title: "Invoice template cache   (unclosed quote)
docir reindex            -> warning: 1 file(s) could not be parsed ...
docir get <its id>       -> error: no document with id '<its id>'   (exit 4)
docir update <its id> …  -> the same

docir check names the file (malformed) and docir doctor reports index-behind-files; neither runs on the path that meets the symptom. When the broken file is the store's only one the miss was worse: the empty-index branch of issue-e5a0cb196607 fired and sent the reader to docir reindex, which skips the same file again.

Impact

A reader holding the id from a commit or a link reads "no document" as "deleted, or the wrong id". The natural next step is docir add, which mints a second document beside the broken file — two documents on one subject, and the original returns on the next repair.

Resolution

FIXED. DocumentService._not_found, the one place every by-id miss is worded, first asks the file store for a claimant: DocumentFileStore.find_malformed_claim matches files named <id>-*.md by filename prefix (no glob, so a typed * cannot widen it), parses only those with the same markdown_format.parse that reindex and check use, and returns the path and the parse problem as one line. The message keeps the no document with id '<id>' prefix and DocumentNotFoundError's exit 4, then names docs/<path>, the problem, and the fix — repair the frontmatter, run docir reindex, docir check lists every such file. The claimant is asked before the empty-index branch, because it is the more specific answer and, for a store's only file, the reason the index is empty. Batch get carries the same text in missing, and MCP passes it through unchanged.

Pinned by TestMissingIdNamesAnUnparseableClaimant and the file-store tests beside find_malformed; verified by injecting the bug — with the lookup answering None, the claimant guards fail and the clean-miss guard still passes.

Evidence

  • src/docir/modules/documents/application/services/document_service.py (_not_found)
  • src/docir/platform/filesystem/markdown_store.py (find_malformed_claim)

To amend: Re-verify: