[Bug] Semantic coalesce version map is in-memory only — queue floods after server restart
Summary
The semantic queue coalesce version map (_SEMANTIC_COALESCE_VERSION in semantic_queue.py:19) is a module-level dict with no persistence. After a server restart, ALL previously coalesced semantic jobs become live again, turning routine bulk deletions into multi-day VLM processing storms.
Code
# semantic_queue.py:19
_SEMANTIC_COALESCE_VERSION: dict[str, int] = {}
The dict is populated at enqueue() time (lines 67–71) — each new message for a given coalesce_key bumps the version. At on_dequeue() time (semantic_processor.py:331), is_semantic_msg_stale() checks whether the message's coalesce_version is lower than the in-memory version; if so, the message is skipped.
There is no persistence: no file, no database, no startup rebuild from the queued messages. The queue itself IS persistent (AGFS-backed), but the deduplication map is not.
Effect
After a server restart, _SEMANTIC_COALESCE_VERSION is empty → get(coalesce_key, 0) returns 0 for every key → every queued message whose coalesce_version > 0 now passes the staleness check and gets processed. A directory that had 278 deletions enqueued gets all 278 semantic jobs burned, each triggering a full VLM regeneration (~2.7 min each on our hardware).
Real-world impact
2,998 pending Semantic jobs for 187 distinct parent directories after a bulk PNG cleanup from the knowledge base. Projected 12 days of VLM drain at full speed (26 jobs processed in 2.5 hours). Required manual queue.db surgery — reading the SQLite file, keeping only the highest coalesce_version per key, and merging deleted change sets — to bring it down to 187 jobs.
Related fragility
The 45-second memory dedupe window at semantic_queue.py:17 (_MEMORY_PARENT_SEMANTIC_DEDUPE_SEC = 45.0) shares the same in-memory-only design. It lives on self._memory_parent_semantic_last (instance dict, not persisted) and only applies to context_type == "memory" (line 47), not to resources. Same failure mode, same restart wipe.
Environment
- OpenViking v0.4.12 (AGPL-3.0), self-hosted, native mode
- VLM: llama.cpp qwen2.5vl Q4_K_M (RTX 2060 6GB, single slot, 32K ctx)
- Config: max_concurrent=2, timeout=900
Desired behavior
The coalesce version map should survive restarts. Two plausible approaches:
- Persist it — write the map alongside the queue (e.g., a JSON sidecar or a dedicated key-value file in the queuefs mount) and reload on startup.
- Rebuild from the queue — on startup, scan all pending Semantic messages, group by coalesce_key, and seed the map with the highest coalesce_version per key.
Either approach eliminates the restart wipe without changing the enqueue/dequeue protocol.
Split from the original consolidated report into three separate issues:
- #3891 (this one) — coalesce version map persistence
- #3892 — per-file deletion enqueue waste
- #3893 — silent context-size drops
All three discovered during self-hosted operation on modest VLM hardware but it may still be an issue for bigger installations with more data.
I traced the flow: rm() deletes the file and its vectors before enqueueing the semantic refresh. Multiple deletions under the same parent share a coalesce_key, and the latest job reads the directory’s current state. After restart, the messages remain but the latest-version map is lost, so obsolete jobs run and version numbering restarts at 1.
Would you accept rebuilding the maximum version per key from all unacknowledged Semantic messages before workers start? I would preserve legacy messages and add restart/parallel-deletion tests.
One question: is changes only an incremental hint, or must changes from superseded messages be merged?
@chuanbao666 @zhoujh01