Skip to content

bug: server deadlocks on POST /remember + cosine auto-linking never creates edges #442

Closed

Description

@ajianaz

Bug Description

uteke-serve deadlocks when receiving multiple POST /remember requests. After 2-3 successful inserts, the server hangs indefinitely — subsequent POST /remember and GET /health requests timeout (60s+ with no response).

Additionally, cosine auto-linking (memory_edges) never fires — even for exact duplicate content that should score 1.0000 similarity.

Reproduction

Setup

# Fresh DB
rm ~/.uteke/uteke.db*
uteke-serve --port 8767 &

Insert memories (via curl)

# 1st insert — succeeds after ONNX warmup (~5s)
curl -s -m 15 -X POST http://127.0.0.1:8767/remember \
  -H "Content-Type: application/json" \
  -d '{"content": "CorIn is a desktop knowledge workstation built with Tauri 2, Svelte 5, and Rust backend.", "namespace": "corin"}'

# 2nd insert — succeeds
curl -s -m 15 -X POST http://127.0.0.1:8767/remember \
  -H "Content-Type: application/json" \
  -d '{"content": "CorIn uses Tauri 2 framework with Svelte 5 frontend and Rust backend.", "namespace": "corin"}'

# 3rd insert — HANGS (timeout 60s+)
curl -s -m 15 -X POST http://127.0.0.1:8767/remember \
  -H "Content-Type: application/json" \
  -d '{"content": "Exact duplicate of memory 1.", "namespace": "corin"}'

Server logs

INFO uteke_serve: POST /remember    # 1st OK
INFO uteke_serve: POST /remember    # 2nd OK
INFO uteke_serve: POST /remember    # 3rd HANGS (no response, no error)
INFO uteke_serve: GET /health       # Also hangs server fully unresponsive

Root Cause Analysis

1. Server Deadlock

The server uses Mutex<Uteke> (tokio::sync::Mutex). Each POST /remember acquires the lock for the entire duration of:

  1. Tokenize input
  2. ONNX inference (CPU-bound, ~100-200ms per call)
  3. SQLite insert
  4. VectorIndex insert + save
  5. auto_link_cosine() VectorIndex search + SQLite edge insert

After 2-3 calls, the mutex appears to deadlock. Possible causes:

  • ONNX session is Mutex<Session> nested lock acquisition
  • index.save() writes to disk while holding the Uteke lock
  • auto_link_cosine() acquires index.read() lock, but index.insert() in step 4 may not have released the write lock

2. No Auto-Edge Creation

Even when memories are successfully inserted, memory_edges table is always empty:

sqlite> SELECT COUNT(*) FROM memory_edges;
0

The auto_link_cosine() function in edges.rs:766 is called after index.insert(), but:

  • index.search() returns empty results (index size() == 0 check fails?)
  • Or namespace filter (memories_in_namespace) returns empty set
  • Or the function silently returns on results.is_empty()

Evidence

Two memories with cosine similarity 1.0000 (exact content match) but zero edges created:

Memory 1: "CorIn is a desktop knowledge workstation built with Tauri 2..."
Memory 2: "CorIn is a desktop knowledge workstation built with Tauri 2..."
Cosine similarity: 1.0000 (verified via /recall)
memory_edges: 0

3. Duplicate Insert Not Blocked

Exact same content can be inserted multiple times without any possible_duplicate warning or dedup. This confirms auto-linking is completely non-functional.

Impact

  • CorIn semantic search shows irrelevant results without edges, graph is tag-based only
  • Duplicate memories accumulate no dedup protection
  • Server becomes unresponsive after a few operations, requires restart
  • CorIn desktop app appears broken all searches hang

Expected Behavior

  1. POST /remember should complete in under 500ms (ONNX warm) and never hang
  2. Exact duplicate content should create possible_duplicate edge (sim >= 0.92)
  3. Similar content should create similar_to edge (sim >= 0.80)
  4. Server should handle concurrent requests without deadlock

Environment

  • uteke v0.3.2, schema v11
  • macOS (Apple Silicon)
  • uteke-serve from cargo install --path crates/uteke-server
  • ONNX model: embeddinggemma-q4 (768d, 256 max seq len)
  • DB: fresh ~/.uteke/uteke.db, 0 prior memories

Activity

  1. added
    bug
    on Jun 22, 2026
  2. self-assigned this
    on Jun 22, 2026
  3. added a commit that references this issue on Jun 22, 2026
  4. ajianaz commented on Jun 22, 2026

    @ajianaz
    CollaboratorAuthor

    Fixed in #443. Root cause was RwLock deadlock: remember_precomputed() held the write lock on the vector index, then auto_link_cosine() tried to acquire a read lock on the same RwLock → permanent deadlock. Fix: drop(index) before calling auto_link_cosine().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions