[Bug] Per-file deletion enqueue: rm() enqueues one SemanticMsg per deleted file instead of batching by parent directory
Summary
When deleting multiple files from the same resource directory, each file deletion independently enqueues a separate Semantic queue job targeting the same parent directory. Deleting 278 files from one directory produces 278 SemanticMsg instances — all with the same root_uri and coalesce_key. The coalesce mechanism deduplicates them at dequeue time, but the root cause is the enqueue side: deletions should be batched per parent directory before hitting the queue.
Code path
fs_service.py:198–228 — the rm() method calls _enqueue_delete_refresh() at line 223 once per deleted file. Each call targets refresh_parent_uri (the parent directory — see _semantic_refresh_parent_uri at line 290–294), but passes the individual file as deleted_uri:
# fs_service.py:219-228
if refresh_parent_uri:
await self._enqueue_delete_refresh(
root_uri=refresh_parent_uri, # SAME parent for every file
deleted_uri=uri, # individual deleted file
context_type=context_type,
ctx=ctx,
)
_enqueue_delete_refresh at lines 334–375 constructs a SemanticMsg with:
changes={"deleted": [deleted_uri]},
coalesce_key=build_semantic_coalesce_key(
context_type=context_type,
uri=root_uri, # parent directory — same key for every file
...
),
Effect
N files deleted from one directory = N SemanticMsg instances queued, all with the same coalesce_key. The coalesce mechanism (semantic_queue.py:67–71) handles this at runtime — bumping the version per enqueue and skipping stale messages at dequeue — but the queue still holds N redundant entries. Each surviving entry burns a full VLM regeneration of the parent directory's L0 overview+abstract.
Contrast with existing pattern: _enqueue_parent_refresh (semantic_processor.py:271–309) already correctly enqueues ONE parent refresh after processing a file — the deletion path should follow the same pattern: batch all deletions for the same parent into one message with changes={"deleted": [all_deleted_uris]}.
Real-world impact
During a bulk cleanup of ~3,000 PNG page-raster images from the knowledge base, 2,998 Semantic jobs were enqueued for only 187 distinct parent directories. A single directory (Talhoffer plates) had 278 jobs queued for one parent. Combined with the in-memory-only coalesce map (#3891), a server restart during processing would have turned all 2,998 into live VLM jobs.
Environment
- OpenViking v0.4.12 (AGPL-3.0), self-hosted
- Resource deletions via
DELETE /fsAPI
Desired behavior
rm() (or _enqueue_delete_refresh) should batch deletions by parent directory: accumulate all deleted URIs for the same refresh_parent_uri, then enqueue ONE SemanticMsg with changes={"deleted": [all_deleted_uris]}. The simplest approach is to move the enqueue call outside the per-file loop — collect deleted URIs per parent in the caller, then fire one refresh per unique parent.
Related: #3891 (coalesce persistence bug). These two issues multiply each other: the per-file enqueue creates the flood, and the in-memory-only coalesce map means a restart makes every queued job live again.