Skip to content

CRITICAL: Race condition in concurrent writes corrupts usearch vector index #543

Closed

Description

@ajianaz

Description

Concurrent writes to the usearch vector index cause data corruption. When 5 memories are written in parallel (xargs -P5), the vector index becomes out-of-sync with the SQLite database — 4 vectors are lost from the index while all 5 records exist in SQLite.

Environment

  • Uteke version: 0.6.1 (binary from GitHub Releases)
  • OS: Linux 6.8.0-1054-oracle (Oracle Cloud ARM)
  • Store path: ~/.uteke (local CLI)
  • Reproducibility: Consistent — reproducible on demand

Steps to Reproduce

# Create test namespace
uteke namespace create ctest

# Write 5 memories in parallel
echo -e "mem1\nmem2\nmem3\nmem4\nmem5" | xargs -P5 -I{} bash -c 'uteke remember --namespace ctest "concurrent test {}"'

# Verify consistency
uteke doctor
uteke verify

Expected Behavior

All 5 vectors should appear in both SQLite and usearch index. Index should be thread-safe or queue writes sequentially.

Actual Behavior

  • SQLite contains all 5 records
  • usearch index only contains 1-4 vectors (4 lost in our test)
  • uteke doctor reports: DB=19339, Index=19335 (mismatch)
  • Error logged: rename temp to final key mapping: No such file or directory
  • Running uteke repair recovers consistency by rebuilding index from SQLite

Impact

  • Data loss risk: Memories exist in DB but are invisible to semantic recall
  • Silent failure: No error returned to caller — write appears successful
  • Production blocker: Multi-agent coordination (multiple agents writing simultaneously) will trigger this

Suggested Fix

  1. Add a write lock (RwLock or Mutex) around vector index operations
  2. Or implement a write queue that serializes index modifications
  3. Consider using usearch native thread-safety options if available
  4. Interim: add auto-repair after batch writes

Workaround

Run uteke repair after any batch or concurrent write operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:criticalscope:core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions