Skip to content

fix: documents_fts migration repair + doc delete by slug (#549, #550) - #554

Merged
ajianaz merged 1 commit into
developfrom
fix/549-550-docs-fts-and-delete-slug
Jul 4, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/549-550-docs-fts-and-delete-slug

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #549 and #550 — two bugs in the document engine.

#549: documents_fts table missing — FTS5 search fails for document chunks

Root cause: Schema v12 migration creates the documents_fts FTS5 virtual table with best-effort execution (let _ = self.conn.execute(sql, []);). If the creation failed silently, the table is absent and existing documents are never backfilled. Every uteke recall / uteke doc search logs a noisy warning.

Fix: Add ensure_documents_fts() consistency check (same pattern as ensure_documents_has_children() from #500):

  • Runs after every ensure_schema_version() call (including on store open)
  • Checks if documents_fts exists via sqlite_master
  • If missing: creates FTS5 table, sync triggers, and backfills existing documents
  • Also exposed via ensure_schema_consistency() for uteke repair

#550: uteke doc delete <SLUG> fails — only works with document ID

Root cause: doc_delete() resolved the slug to an ID (main_id) for chunk cleanup, but passed the original slug to delete_document(id) which queries WHERE id = ?1. Slug never matches a UUID.

Fix: Resolve slug to resolved_id FIRST, then use it consistently for descendants, chunk cleanup, and the actual delete.

Test Results

  • cargo check: clean
  • cargo fmt --check: clean
  • cargo test: 284 passed, 4 pre-existing failures (dream tests — ONNX backend)
  • All schema and document tests: passed

Files Changed

  • crates/uteke-core/src/memory/schema.rs: +56 (ensure_documents_fts)
  • crates/uteke-core/src/lib.rs: +17/-14 (doc_delete slug fix)

Closes #549, Closes #550

#549: Add ensure_documents_fts() consistency check that creates the
FTS5 virtual table and backfills existing documents if the v12
migration failed silently (best-effort execute).

#550: Resolve slug to document ID before calling delete_document(),
matching doc_get behavior. Previously delete_document(id) received
the raw slug which never matched WHERE id = ?1.
@ajianaz ajianaz added the bug Something isn't working label Jul 3, 2026
@ajianaz ajianaz self-assigned this Jul 3, 2026
/// backfilled. This check runs after every `ensure_schema_version()` call so the
/// table is created and populated on next access.
fn ensure_documents_fts(&self) -> Result<(), Error> {
// Only relevant for schema v12+ databases.
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (2)

  • crates/uteke-core/src/lib.rs:1040 — In doc_delete, the call to self.store.delete_chunks_for_documents(&all_ids) now still uses .unwrap_or_default(), which suppresses any database error while proceeding with self.store.delete_document(&resolved_id)?. This can leave the document subtree deleted while its chunks and search index entries remain orphaned or inconsistent. The risk is concrete because the code immediately uses the returned chunk_ids to clean up the usearch index, so a failed chunk deletion becomes indistinguishable from 'no chunks existed'.
  • crates/uteke-core/src/memory/schema.rs:171 — In ensure_documents_fts, let version = self.schema_version().unwrap_or(0); converts any failure reading the schema version into 0 and then returns early for < 12. A real database error is therefore silently ignored, preventing the repair path from running and masking corruption or access problems. This is especially risky because this function is meant to repair partially migrated databases.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit a9629b8 into develop Jul 4, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the fix/549-550-docs-fts-and-delete-slug branch July 9, 2026 14:27
ajianaz added a commit that referenced this pull request Aug 13, 2026
…ete-slug

fix: documents_fts migration repair + doc delete by slug (#549, #550)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: doc delete by slug fails - only works with document ID BUG: documents_fts table missing - FTS5 search fails for document chunks in v0.6.4

2 participants