hindsight icon indicating copy to clipboard operation
hindsight copied to clipboard

Auto-consolidation runs up to 32 concurrent recalls in the API process and ignores enable_auto_consolidation when re-queuing

Open choi138 opened this issue 1 month ago • 0 comments

Summary

Auto-consolidation runs up to consolidation_llm_batch_size × consolidation_llm_parallelism (8 × 4 = 32) recall_async calls concurrently inside the API process, each holding up to recall_connection_budget (4) DB connections. On a deployment with a modest pool this starves user recalls (Failed to search memories (TimeoutError) after the 30 s acquire timeout) and the consolidation batches themselves. In addition, a round that hits consolidation_max_memories_per_round re-submits itself immediately with no pacing, and enable_auto_consolidation=false does not stop an in-flight chain.

Version

hindsight-api-slim 1.0.0; bank with ~450k facts, >200k unconsolidated.

Where

  • hindsight_api/engine/consolidation/consolidator.py ~L2371-2385: per-batch asyncio.gather of recall_async for every fact; ~L2018-2036 group parallelism; no dedicated bound (engine _search_semaphore is 32).
  • ~L2051-2078: on round limit → submit_async_consolidation immediately; no check of enable_auto_consolidation. memory_engine.py task handler (~L4280-4330) does not check it either. Only enable_observations=false breaks the chain.
  • ~L1396 _COUNT_LIMIT = 100_000 makes progress total a hard cap, so processed: 100 / total: 100000 is shown forever.
  • Stats: observations_merged is unreachable (dedup folds are counted as created, ~L2719-2727 / 2759-2768).

Observed

281 consolidation operations/day (one every ~5 min, 100 memories each), 39 failed with Failed to search memories (TimeoutError), user recall latency 4–14 s, with HINDSIGHT_API_DB_POOL_MAX_SIZE=5.

Expected

A dedicated, configurable concurrency bound for consolidation recalls; honor enable_auto_consolidation when re-queuing; optional requeue delay.

Reference fix

https://github.com/choi138/hindsight/tree/fix/consolidation-recall-concurrency (commit 17624f46b): adds HINDSIGHT_API_CONSOLIDATION_RECALL_MAX_CONCURRENT (default 4) and HINDSIGHT_API_CONSOLIDATION_REQUEUE_DELAY_SECONDS (default 0), gates automatic requeue/handler on enable_auto_consolidation while letting explicit /consolidate runs drain fully, and fixes the merged accounting. 8 new tests; existing consolidation suites pass (158).

choi138 avatar Oct 15 '26 05:10 choi138