Skip to content

bug: embed command hangs indefinitely on certain memories — no per-memory timeout #362

Closed

Description

@hurttlocker

Problem

cortex embed ollama/all-minilm (and ollama/nomic-embed-text) hangs indefinitely when processing certain memories. The embed worker starts, reports worker_running=true, but never writes vectors. embed --status shows embeddings=0 remaining=N forever.

Ollama responds fine to direct API calls — the issue is in the Cortex embed loop, not Ollama.

Reproduction

# Fresh DB with 500+ memories
cortex embed ollama/all-minilm --batch-size 50
# Hangs at 0 embeddings written
# Meanwhile, direct Ollama call works:
curl -s -X POST http://localhost:11434/api/embeddings \
  -d "{\"model\":\"all-minilm\",\"prompt\":\"test\"}" | jq .embedding | head -1
# Returns 384 dims instantly

Root Cause

The embed goroutine sends memory content to Ollama without a per-request timeout. When Ollama takes >30s on a long/malformed memory, the goroutine blocks. Since workers share a connection pool or semaphore, one stuck request blocks the entire batch and all subsequent batches.

Memories that trigger this:

  • Long metadata-heavy content (JSON blocks, conversation headers)
  • Content >2000 chars with special characters
  • Unicode-heavy content

Impact

  • Production blocker: fresh installs cannot complete embedding
  • Autoresearch runner blocked: cannot benchmark the shipping embedder path
  • Workaround exists: Python bypass script with per-memory 8s timeout (scripts/embed-fast.py)

Fix

  1. Add per-memory HTTP timeout to the Ollama embed client (8-10s)
  2. On timeout: log warning, skip the memory (or insert zero-vector), continue to next
  3. Add --timeout flag to cortex embed (default 10s)
  4. Add retry logic: retry once with truncated content (first 1000 chars) before skipping
  5. Report skip count in embed --status

Acceptance

  • cortex embed ollama/all-minilm completes on a 500-memory DB in <5 minutes
  • No hangs on any memory content
  • embed --status shows skip count
  • Skipped memories are logged with IDs for manual review

Refs

Activity

  1. added
    bug
    on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions