[Bug]: v0.5.1 — Embedding work rejected against already-completed session_commit tasks
Issue Origin
Observed or reproduced in a real environment (single-node self-hosted deployment).
Bug Description
On OpenViking v0.5.1, memory vectorization work is still enqueued under the TaskExecutionContext of a session_commit task that already reached completed, sometimes many hours earlier. The queue middleware registers the new Embedding work against that terminal task, the task store rejects it, enqueue_embedding_msg() returns False, and memory_updater only logs an error and continues:
Failed to enqueue memory for vectorization: viking://...
Error enqueuing embedding message: Task <id> is unavailable; rejected work for Embedding
The memory file is written successfully, but no vector is produced, so retrieval silently misses the new memory. In an ~11 hour window we observed 185 rejections across 8 distinct session_commit tasks, all in completed state, with the first rejection as soon as 26 seconds after task completion and the last one ~11 hours after completion. The server process did not restart in that window.
Affected clients in this deployment include QoderCN (OpenViking memory plugin 0.7.12), OpenCode and Cherry Studio sessions.
Steps to Reproduce
A deterministic CLI repro is not available because plain HTTP writes do not carry a task context; the failure requires deferred memory-pipeline work to run after its owning task has finished. The observed conditions were:
- Single-node self-hosted v0.5.1, file task store + file queue,
memory.session_auto_commit.enabled=true. - Multiple agent sessions continuously write memories. After an upgrade/restart the queue had a backlog: one
session_commitqueued for ~5.5 hours before it ran. - After some
session_committasks completed, deferred memory refresh/vectorization continued to run (timer/background flush or long-lived semantic work) and kept carrying the old task id into Embedding enqueues. - Logs then show
Failed to enqueue memory for vectorizationplusTask <id> is unavailable; rejected work for Embedding.
Task timing observed (all times CST/UTC+8; task ids truncated; all are session_commit and completed):
| task | created | completed | first rejection | last rejection | rejections |
|---|---|---|---|---|---|
| f75074c0 | 10-20 00:38:14 | 00:51:50 | 00:52:16 | 11:52:33 | 80 |
| 01f5c5de | 10-19 16:07:19 | 10-20 00:51:56 | 01:06:07 | 05:36:24 | 10 |
| 02161028 | 10-20 00:53:21 | 00:55:52 | 00:58:08 | 11:55:18 | 42 |
| 7669af95 | 10-20 00:55:06 | 00:58:30 | 01:09:50 | 01:14:11 | 3 |
| cb59694d | 10-20 01:07:36 | 01:08:27 | 01:24:53 | 11:52:53 | 23 |
| 810f6c72 | 10-19 19:19:08 | 10-20 00:58:11 | 01:06:07 | 11:52:52 | 22 |
| f1e9093f | 10-20 01:05:25 | 01:06:05 | 11:40:54 | 11:41:43 | 3 |
| c756d95b | 10-20 01:13:51 | 01:14:25 | 11:40:47 | 11:41:42 | 2 |
Expected Behavior
Derived Embedding work should either:
- keep the parent task in a non-terminal state until all descendant work completes; or
- be detached from the finished task context and enqueued as independent work (not as work of a terminal task).
At minimum, vectorization failure should not be silently swallowed; it should retry or surface as a task failure.
Actual Behavior
task_queue_middlewareraisesTaskWorkRejectedfor the completed parent task.VikingDBManager.enqueue_embedding_msg()catches the exception and returnsFalse.MemoryUpdater._vectorize_memories()defaults toraise_on_enqueue_failure=False, logs the failure and continues.- The memory file remains written, its vector is missing, and nothing retries automatically (manual reindex is required).
Minimal Reproducible Example
No runnable script yet. A regression test sketch for this lifetime problem:
# inside a session_commit queue handler (task context bound)
with bind_task_context(task.task_id, account_id, user_id):
batcher = StreamingBatcher(...) # lazily creates a long-lived timer/flush task
# parent task is marked completed here
# ... later, the timer flush runs with the inherited context:
await memory_updater.apply_operations(...) # -> Embedding enqueue -> TaskWorkRejected
A deterministic integration test would create a task, bind its context, start a deferred memory flush, complete the task, then trigger the flush and assert that the Embedding enqueue does not use the terminal task id.
Error Logs
Sanitized excerpt (host, PID, account path and full UUIDs removed):
2026-10-20 11:40:49 ERROR openviking.session.memory.memory_updater:_vectorize_memories:1883 - Failed to enqueue memory for vectorization: viking://user/<account>/memories/<redacted>.md
2026-10-20 11:40:49 ERROR openviking.storage.vikingdb_manager - Error enqueuing embedding message: Task 02161028-<redacted> is unavailable; rejected work for Embedding
OpenViking Version
0.5.1 (server and CLI, installed via uv tool; /health reports version: 0.5.1)
Python Version
3.14
Operating System
Linux
Model Backend
Volcengine (Doubao) for embedding and VLM; rerank via an OpenAI-compatible endpoint.
Additional Context
Why this is a context-lifetime bug, not the #6271 ordering bug
EmbeddingMsgConverter.from_context()→EmbeddingMsg.for_embed()does not settask_id(storage/queuefs/embedding_msg.py:234); the queue envelope'stask_idstays empty.prepare_task_payload()therefore takes the task id from the ambient_current_task_context(service/task_work_index.py:148-186).- The observed error is
unavailable, notmissing owner metadata. Inprepare_task_payload(), owner fields are only populated whenhas_authoritative_contextis true (task id matches the current context and account/user are non-empty); otherwisetask_queue_middleware.py:54would raise themissing ownererror first. So the enqueue definitely ran while a matching but staleTaskExecutionContextwas still bound, andregister_workthen hit the terminal-task guard (service/task_store.py:696, raised atservice/task_queue_middleware.py:80). - The v0.5.1 ordering fix (#6258) is present:
session.py:1733creates the task,:1751binds the context,:1775enqueues. The commit itself succeeds. This is about the context outliving the task, not about creation order.
Likely escape paths (please verify)
StreamingBatcher._ensure_timer_task()and_trigger_background_flush()create asyncio tasks without detaching the current task context (session/memory/utils/streaming_batcher.py:159,183,223). A timer/flush task created while asession_commitis being processed inherits that task's context and can keep flushing memory batches after the commit task completes. The roughly 30–70 s cadence of the rejections, with multiple old task ids active concurrently, matches this pattern.SemanticTreeExecutor.__init__()capturesget_task_context()(storage/queuefs/semantic_executor.py:247) and re-binds it for every DAG work item (:521). Long-running or backlogged semantic work can also outlive the parent task and enqueue derived work under a terminal task id.detach_task_context()already exists and is used elsewhere (e.g. semantic parent-refresh enqueue), but not in the batcher timer/background flush path.
Suggested direction
- Detach the task context in the streaming batcher timer/background flush and in any long-lived semantic worker, or explicitly bind the correct still-active owner when flushing.
- Alternatively, allow derived Embedding work from a terminal parent to register as independent work instead of rejecting it.
- Consider keeping the parent task open until registered descendant work finishes.
Workaround
Periodic ov reindex <uri> --mode semantic_and_vectors for affected URIs (we currently run a small sweeper). This heals vectors but does not fix the lifecycle.
Relation to #6271
#6271 is a different TaskWorkRejected path on 0.5.0.post130 (tracker.create after queue.enqueue; the commit itself fails). Here on 0.5.1 the commit succeeds and only later Embedding work is rejected against an already-completed task.
Reporter / collaborator
Reported from the deployment of @lqstc; log correlation and analysis were done with QoderCN (AI coding agent) as collaborator.
cc @runyunzhou
Send by ZCode:
Confirmed the same signature on Windows 11 with 0.5.1 (uv tool install, single node, file task store + file queue, memory.session_auto_commit.enabled=true), so this is not Linux-specific. The server process was not restarted in the observation window.
- 93 rejections over 3 days (2026-10-26 08:32 -> 2026-10-28 08:58, local time)
- 58 distinct memory files written to disk with no vector produced
- all rejections carried a
completedsession_committask id
Example: task 1691658d-<redacted> reached completed at 08:22:31 and kept rejecting Embedding work until 08:58:49, i.e. 36 minutes after completion:
08:39:14 ERROR memory_updater._vectorize_memories:1883 - Failed to enqueue memory for vectorization: viking://user/<account>/memories/entities/...
08:39:14 ERROR vikingdb_manager - Error enqueuing embedding message: Task 1691658d-<redacted> is unavailable; rejected work for Embedding
ov find silently missed those memories until a manual ov reindex viking://user/<account>/memories --mode vectors_only (332 scanned / 395 rebuilt / 0 failed). Retrieval verified afterwards.
Fix verified: 0.5.2.1 contains PR #6331 (detach_task_context() in session/memory/utils/streaming_batcher.py and storage/viking_fs/_snapshot.py). After upgrading 0.5.1 -> 0.5.2.1 and restarting, no rejections so far.
Two side observations while recovering:
- Memory vector records carried no persisted
md5, so the default reindex fingerprint diff treated every memory record as STALE and re-embedded all of them (332 scanned -> 395 rebuilt). The peers subtree skipped unchanged records as expected (309 -> 79), so this looks memory-specific. - Unrelated: one
session_commitfailed with a Windows sharing violation on the lock token (lock I/O error: failed to read lock token at '.../.path.ovlock' ... os error 33). Can file separately if useful.
Sanitized evidence (no credentials, hostnames or full UUIDs): https://gist.github.com/mamaruo/b4358996c5a142a4362b88eea28c31d1
We hit the exact same signature on Linux, v0.5.1 (single-node self-hosted, file task store + file queue, memory.session_auto_commit.enabled=true):
- A
session_committask completed at 17:06:46; from 18:32:17 onward every Embedding enqueue for that session was rejected —Task ... is unavailable; rejected work for Embedding— until service restart. Manualov reindex --mode vectors_onlywas required to backfill the backlog. - This has now happened twice in one day on our instance (queue lifetime after restart: ~100 minutes), and previously went unnoticed for 7 days, silently leaving 543 memories stored-but-unsearchable.
- Forensics match the analysis above: the task record on disk shows
task_type: session_commit,status: completed, and rejections keep stamping the same terminal task id.
This issue was closed as completed on Oct 20, but no fix commit or release is referenced, and commit 2954595 (#6764, Oct 29, fix(tasks): ack orphan terminal queue deliveries) still touches task_queue_middleware.py. Could you confirm:
- Which release actually contains the fix — v0.5.2, or #6764 which is still unreleased?
- Are v0.5.2 / v0.5.2.1 users still affected?
Workaround we're running for now: log-based alerting + watchdog restart + ov reindex catch-up.