OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: Reindexing a single-file URI fails with HTTP 500 - lock I/O error: failed to scan lock directory ... not a directory (pathlock_acquire_tree on a file path)

Open neurosovereign opened this issue 3 months ago • 2 comments

Bug Description

POST /api/v1/content/reindex with a single-file URI returns HTTP 500 with a pathlock error: the executor calls pathlock_acquire_tree() on what is a file path, and the lock manager fails to scan it as a lock directory.

Full traceback tail (live production instance):

2026-08-15 17:51:51,284 - openviking.server.app - ERROR - [request_id=...] Unhandled exception
  File ".../openviking/server/routers/content.py", line 339, in reindex
  File ".../openviking/service/reindex_executor.py", line 438, in _run
      lease = await service.viking_fs._async_agfs.pathlock_acquire_tree(path)
  File ".../openviking/pyagfs/async_client.py", line 302, in pathlock_acquire_tree
  ...
  RuntimeError: lock I/O error: failed to scan lock directory '/local/<account>/user/<uid>/peers/<agent>/memories/events/mem_XXXXXXXXXXXX.md': plugin error: not a directory: /<account>/user/<uid>/peers/<agent>/memories/events/mem_XXXXXXXXXXXX.md

Reproduction steps

curl -s -X POST http://127.0.0.1:1933/api/v1/content/reindex \
  -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"uri":"viking://user/<account>/user/<uid>/memories/events/<some_file>.md","mode":"full","wait":true}'
# → HTTP 500 RuntimeError: lock I/O error: failed to scan lock directory ... not a directory

Any existing single memory file as target reproduces. Directory and namespace targets work fine.

Root cause (0.4.13 code)

openviking/service/reindex_executor.py:438 (_run) unconditionally calls pathlock_acquire_tree(path) after _uri_to_path(uri). For a file URI this is a file path; the tree-lock scan (crates/ragfs/src/lock/, lock-directory scan path) does a directory scan on it and gets not a directory.

_infer_target_type() (reindex_executor.py:206) already classifies file vs directory targets, but _run() never branches on it before taking the tree lock.

Expected behavior

One of:

  1. File target → pathlock_acquire_exact(path) + reindex just that file (most useful — single-file reindex is a legitimate maintenance op), or
  2. Reject file URIs with 400 INVALID_ARGUMENT instead of an unhandled 500.

OpenViking Version

v0.4.13 (pip wheel)

Python Version

3.12

Operating System

Linux x86_64 (Ubuntu 24.04), systemd user unit, single local server

Model Backend

OpenAI-compatible (extraction VLM); not relevant to this code path

Additional context

Workaround: target the parent directory instead of the file. Frequency on our instance: 2 hits in 7 days of journal (low only because we abandoned single-file reindex after the first failure). The 500 (vs 4xx) also pollutes error monitoring as a server fault rather than a request-shape error.

neurosovereign avatar Aug 15 '26 16:08 neurosovereign

I can work on this if the proposed locking contract matches the intended behavior. My plan is to keep directory/namespace targets on pathlock_acquire_tree(path), route a target classified as a file by the existing _infer_target_type() path to pathlock_acquire_exact(path), and release either lease through the same cleanup path.

I would add deterministic service-level regression coverage for both branches: a file target must acquire only the exact lock and reindex that file, while a directory target must retain the tree lock. I will keep the change scoped to reindex_executor and its tests, without changing the public request schema or unrelated RAGFS locking semantics. Please let me know if maintainers prefer rejecting file targets with INVALID_ARGUMENT instead.

linhongyu510 avatar Sep 04 '26 10:09 linhongyu510

This issue was fixed by PR #3964, commit 482434ef6.

The fix checks the target type before locking:

  • File targets use pathlock_acquire_exact().
  • Directory targets continue using pathlock_acquire_tree().
  • The acquired lease is released through the existing cleanup path.
  • Regression tests cover single-file reindexing.

baojun-zhang avatar Sep 17 '26 07:09 baojun-zhang