OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: /api/v1/system/wait can return before queues drain during a Semantic-to-Embedding handoff

Open Leeminjing opened this issue 1 week ago • 1 comments

Issue Origin

Observed or reproduced in a real environment. Reproduced in a local test harness using the production QueueFS backends, workers, and HTTP route.

Bug Description

POST /api/v1/system/wait can return success while work is still queued. The completion check reads Embedding before Semantic. A Semantic worker can enqueue an Embedding message and then acknowledge its own message between those reads. Each per-queue status is accurate at the time it was read, but the two queues were never empty at the same time.

Steps to Reproduce

  1. Run the real QueueFS memory or SQLite backend with one Semantic message processing and no Embedding messages. Use a Semantic message that can enqueue Embedding without a lock handoff.
  2. Call POST /api/v1/system/wait. After its first Embedding status read returns pending=0, processing=0, pause that caller before it reads Semantic.
  3. Let the Semantic worker enqueue one Embedding message and ACK the Semantic message. Keep the Embedding worker from consuming the child.
  4. Resume the waiting caller and inspect the HTTP response and the actual Embedding queue. The harness uses thread events to force this ordering and substitutes file and model calls. Queue writes, ACKs, counts, and the HTTP route use the production implementations.

Expected Behavior

The request remains pending while Embedding has an unacknowledged message. After both queues drain, the request returns its existing success response and counters.

Actual Behavior

The request returns HTTP 200 with status: "ok" while Embedding still has one pending message, with no new external request during the handoff. The direct QueueManager.wait_complete() call also returns a result with Embedding.pending == 1. It checks the first set of readings, then directly returns a second set without checking it for completion.

OpenViking Version

Source checkout ab1bb593d3c1b2c074133ec8a95d8f2379edc343. The relevant code matches upstream main at 6a0fd46.

Python Version

3.12.10

Operating System

Windows

Additional Context

Confirmed with both memory and SQLite QueueFS backends, at the queue manager and HTTP boundaries. The system API reference describes this operation as waiting for the processing queues to drain. #5000 made each queue's occupancy read atomic.

Proposed scope for discussion is a consistent cross-queue occupancy snapshot in QueueFS and completing the wait from the same snapshot it returns. The existing set of queues covered by the wait, HTTP response format, SDK, and task-ID queries are outside the change.

Leeminjing avatar Nov 22 '26 07:11 Leeminjing

Thanks for the clear reproduction. The runtime-wide wait can return while the last indexing job is still queued. A script that searches immediately afterward can therefore miss the new document until indexing finishes.

For a specific resource import, ov add-resource --wait follows the import's own task. Clients can also poll the returned task ID. Given the narrow timing window and the cost of maintaining a queue-wide snapshot across backends, we're closing this as not planned.

qin-ctx avatar Nov 24 '26 04:11 qin-ctx