OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

content/write anchors semantic refresh at the resource root with recursive=False — nested files are never vectorized and nested directory overviews never refresh

Open pengfus opened this issue 4 months ago • 1 comments

Environment

  • OpenViking v0.4.5; behavior re-verified live on 2026-07-10 (semantic message logged as Processing semantic generation for: viking://resources/<root> (recursive=False) after writing a deeply nested file)

Bug

Writing a nested file via POST /api/v1/content/write (e.g. viking://resources/a/b/c/d/file.md) enqueues a semantic message anchored at the resource root (viking://resources/a) with recursive=False. The non-recursive directory dispatch only processes the root directory's direct children and never descends, so:

  • the written nested file never gets file-level semantic/vector indexing (0 points in the vector DB for it);
  • the nested parent directories' overviews/abstracts are not refreshed;
  • only the root directory's own L0/L1 are recomputed.

Meanwhile the status refresh path reports sem/vec complete once the queue is idle, so callers (even with wait=true) get a false success signal.

By contrast, the upload/register path (POST /api/v1/resources/temp_upload + POST /api/v1/resources {temp_file_id, to, wait}) emits a per-file message for the actual target URI; the file is vectorized correctly and on completion a parent semantic refresh is enqueued for the immediate parent directory. The two write paths have inconsistent semantics for the same logical operation.

We first hit this with an agent that mirrors a memory tree into OpenViking using content/write — 46 nested files, all reported complete, none vectorized. Re-registering the same files through the upload path fixed all of them (146 vector points, search hits at 0.8+ scores).

Reproduction

  1. POST /api/v1/content/write to viking://resources/<root>/x/y/z/file.md with wait=true.
  2. Server logs Processing semantic generation for: viking://resources/<root> (recursive=False).
  3. Search / vector DB shows no entry for the nested file; x/y/z overviews unchanged. Status reports complete.

Expected behavior

content/write should either emit a per-file (recursive) semantic message for the actual written URI — matching the register path — or the directory DAG should descend along the changed paths recorded in the message's changes.

pengfus avatar Jul 11 '26 05:07 pengfus

Update after re-checking current main (e123bbc0) — the main path is fixed, but one branch still has the bug.

Correction to my report: this is fixed for viking://resources/... since v0.4.6 by #2863 (b2c9768e) and #2864 (3afe85fb). _resolve_root_uri(anchor_to_parent=True) now anchors the semantic refresh at the written file's direct parent directory (openviking/storage/content_write.py:833-843), so the nested file is a direct child of the DAG run root and gets vectorized; ancestor overviews refresh via the per-level _enqueue_parent_refresh bubble (semantic_processor.py:451). My "unchanged in current main" claim was wrong — my live verification ran against the v0.4.5 container, which predates the fix.

Residual bug that still matches this issue in current main: the user-scope branch ignores anchor_to_parent and anchors at the resource root (content_write.py:845-852):

elif parts[0] == "user":
    if "resources" in parts:
        root_uri = VikingURI.build(*parts[: resources_idx + 2])  # resource ROOT

So writing viking://user/<uid>/resources/<res>/a/b/c/file.md still enqueues a recursive=False message at viking://user/<uid>/resources/<res>, and the DAG never descends into subdirectories when recursive=False (semantic_dag.py:432-435, :457-460) — the nested file gets no vector and nested parents' overviews never refresh, exactly the originally reported behavior.

Suggested fix: apply the same anchor_to_parent logic to the user-scope resources branch (anchor at the written file's direct parent under viking://user/<uid>/resources/<res>/...).

pengfus avatar Jul 11 '26 12:07 pengfus