Worker claims retain ops into 'processing' but never completes or times them out, leaving the queue stalled
Description
The background worker claims pending retain operations (moving them to processing) and then stalls: they stay in processing indefinitely without completing and without being released by any configured timeout. New pending operations pile up behind them, so the queue stops draining. This reproduces with healthy NN providers and with both the global and per-operation LLM timeouts set to short values.
Expected Behavior
A retain claimed by the worker either completes (writes its facts + embeddings and flips to completed) or, if the upstream LLM call exceeds the configured timeout, is released (moves back to pending or is marked failed with an error) so the slot frees up and the rest of the queue drains.
Observed Behavior
- Worker stats show
my_active: retain:<bank>(8)but those 8 rows sit inprocessingfor minutes witherror_message=NULLand nocompleted/failedtransition. - SQL
SELECT status, count(*) FROM async_operations:processingstays at a constant non-zero value whilecompletedis0over a multi-minute window. - Setting both
HINDSIGHT_API_LLM_TIMEOUTandHINDSIGHT_API_RETAIN_LLM_TIMEOUTto"20"does NOT free the stuckprocessingrows. Restarting the container flushes the in-memory slot state (slots drop to 0) but the next polling cycle claims a fresh batch and they stall again. - No error is logged for these rows (no failure, no timeout traceback) — they appear to hang silently in flight.
Requested Fix / Proposed Solution
- Investigate why a
retainLLM call that exceeds the configured timeout is not surfaced as an exception that releases the claimed operation. - Add a stale-claim watchdog: if a
processingrow'sclaimed_atis older than the LLM wall-clock budget, re-queue it (and increment a counter) rather than leaving the slot permanently occupied. - Consider a per-
retainhard deadline (including the structured-output + embedding tail) so a single hung call cannot occupy a slot indefinitely.
Reproduction package
Build
- Version: latest
ghcr.io/vectorize-io/hindsightimage (:latest) - Platform: Docker Desktop on Windows; single GPU (Turing, NVIDIA) with local TEI embedding/rerank containers on the same host
Config used
HINDSIGHT_API_LLM_STRATEGY: '{"mode": "failover"}'
HINDSIGHT_API_LLM_MAX_RETRIES: "1"
HINDSIGHT_API_LLM_TIMEOUT: "20"
HINDSIGHT_API_RETAIN_LLM_TIMEOUT: "20"
HINDSIGHT_API_RETAIN_MAX_COMPLETION_TOKENS: "8000"
HINDSIGHT_API_RETAIN_LLM_REASONING_EFFORT: "medium"
HINDSIGHT_API_LLM_MAX_CONCURRENT: "6"
Request/log excerpt
[WORKER_STATS] worker=hindsight-main-worker slots=8/10 ... my_active: retain:hermes(8)
[WORKER_TASK] op=<uuid> type=retain op_type=retain bank=hermes stage=llm.openai.retain_extract_facts.attempt=1/2 stage_age=<large>
(The stage_age grows without the operation ever reaching completed or failed.)
How to replicate
- Enqueue some number of
retainoperations (e.g. a handful of memory items with non-trivial text). - Ensure an upstream OpenAI-compatible NN provider is reachable (healthy, quick responses).
- Run the worker with the short timeouts above.
- Observe: the worker claims a batch into
processing, thencompletedstays0andprocessingstays constant whilestage_ageclimbs, for many minutes. docker restartthe server: slots flush to 0, but a fresh batch is claimed and the same stall repeats.
Notes
- This was observed with a multi-member failover chain, but the stall occurs regardless of which member is ultimately consulted, because the claimed operation is never released.
- The embedding tail (generating vector embeddings for extracted facts) is part of the same
retainpipeline and is included in the recommendation to bound it with a hard deadline.
A persisted lease watchdog should reclaim rows after the full retain deadline, not just the LLM timeout. Completion should also be idempotent, so a late call cannot overwrite a requeued attempt and retries remain safe.