POST /api/v1/system/consistency returns 503 (AGFSPluginError: not a directory) when URI is a file
Bug Description
Step 1 — Pass a file URI → 503
curl -s -w "\nHTTP %{http_code}\n" -X POST http://<host>:<port>/api/v1/system/consistency \
-H "Authorization: Bearer ***" \
-H "X-OpenViking-Agent: hermes" \
-H "Content-Type: application/json" \
-d '{"uri": "viking://user/hermes/memories/cases/mem_3a9aca10093d.md"}'
Response:
{
"status": "error",
"result": null,
"error": {
"code": "UNAVAILABLE",
"message": "Storage backend unavailable: plugin error: not a directory: /changhe/user/hermes/memories/cases/mem_3a9aca10093d.md"
}
}
HTTP 503
Step 2 — Pass the parent directory URI → 200 OK
curl -s -X POST http://<host>:<port>/api/v1/system/consistency \
-d '{"uri": "viking://user/hermes/memories/cases/"}'
Returns {"status":"ok","result":{"ok":true,...}} with HTTP 200.
Step 3 — Pass a .abstract.md path → 503
Same AGFSPluginError: not a directory error for auto-generated .abstract.md files inside directories.
Steps to Reproduce
Expected Behavior
- File URI → Return
ok: true, expected_count: 0(a file is self-contained, no subtree to check) OR return a clear400 Bad Requestsaying "consistency check only supports directory URIs". - Directory URI → Current behavior (200 OK with consistency report) ✅.
Expected Behavior
Actual Behavior
- File URI →
503 UNAVAILABLEwith misleading error:Storage backend unavailable: plugin error: not a directory: .../mem_xxx.md .abstract.mdinside directory tree → Same 503 when consistency endpoint tries totree_directory()on it.- The error message is misleading: "Storage backend unavailable" suggests the backend is down, but actually it's a type mismatch (file passed where directory expected).
Actual Behavior
File ".../openviking/server/routers/system.py", line 260, in check_consistency
result = await service.check_consistency(...)
File ".../openviking/service/core.py", line 516, in check_consistency
entries = await self._viking_fs.tree(uri) # ← passes file URI directly
File ".../openviking/storage/viking_fs.py", line 2380
raw_entries = await self._async_agfs.tree_directory(entry_uri) # ← AGFSPluginError
openviking.pyagfs.exceptions.AGFSPluginError: plugin error: not a directory: /changhe/user/hermes/memories/cases/mem_3a9aca10093d.md
Minimal Reproducible Example
## Suggested Fix
### Option A (service layer — minimal)
Catch the `AGFSPluginError` in `check_consistency`:
# service/core.py, check_consistency()
from openviking.pyagfs.exceptions import AGFSPluginError
async def check_consistency(self, uri: str, ...) -> ConsistencyResult:
try:
entries = await self._viking_fs.tree(uri)
except AGFSPluginError as e:
if "not a directory" in str(e):
return ConsistencyResult(ok=True, expected_count=0, missing_record_count=0)
raise
# ... existing logic
### Option B (filesystem layer — broader)
In `viking_fs.py:_iter_visible_tree_entries`, check `entry.is_dir` before calling `tree_directory()`:
for entry in entries:
if entry.is_dir:
raw_entries = await self._async_agfs.tree_directory(entry.uri)
# ... recurse
else:
yield entry, entry.uri
Error Logs
.pyagfs.exceptions.AGFSPluginError: plugin error: not a directory: /changhe/user/hermes/memories/cases/mem_3a9aca10093d.md
HTTP Status: 503
Error code: `UNAVAILABLE`
Message: `Storage backend unavailable: plugin error: not a directory: ...`
OpenViking Version
0.4.7 (Docker, Python 3.13, /app/.venv/)
Python Version
3.13
Operating System
Linux
Model Backend
None
Additional Context
Additional Context
- This bug was discovered during a
/system/consistencycheck of user memory directories - The
.abstract.mdfiles are auto-generated by OpenViking for directory summaries — they are files, not directories - The bug also affects any
.mdmemory file passed as the URI - The
reindexendpoint (POST /api/v1/content/reindex) does NOT trigger this bug (it has different code path) - The error message is misleading: "Storage backend unavailable" suggests the backend is down, but actually it's a file/directory type mismatch
- Client:
curl/ REST API - Environment: Docker (
/app/.venv/, Python 3.13) - Related code paths:
server/routers/system.py:260,service/core.py:516,storage/viking_fs.py:2380
中文翻译 / Chinese Translation
摘要
POST /api/v1/system/consistency 当 uri 参数指向文件(如 memory .md 文件)而非目录时,返回 503 UNAVAILABLE,错误信息为 AGFSPluginError: not a directory。当 URI 是目录时,该接口工作正常。
根本原因在 viking_fs.tree() / _iter_visible_tree_entries() 中,对条目调用 agfs.tree_directory() 时没有检查其是否为目录——因此任何文件 URI(或目录树内自动生成的 .abstract.md 文件)都会触发此错误。
复现步骤
步骤 1 — 传入文件 URI → 503
curl -s -X POST http://<host>:<port>/api/v1/system/consistency -H "Authorization: Bearer ***" -H "Content-Type: application/json" -d '{"uri": "viking://user/hermes/memories/cases/mem_3a9aca10093d.md"}'
返回:HTTP 503 / UNAVAILABLE: plugin error: not a directory
步骤 2 — 传入父目录 URI → 200 OK ✅
步骤 3 — 传入 .abstract.md 路径 → 同样 503
根因
service/core.py:516 的 check_consistency() 调用 self._viking_fs.tree(uri) 时,没有先判断 uri 指向的是文件还是目录。
修复建议
方案 A(service 层 - 最小改动):在 check_consistency 中捕获 AGFSPluginError,当 not a directory 时返回 ok: true。
方案 B(文件系统层 - 更彻底):在 viking_fs.py:_iter_visible_tree_entries 中,调 tree_directory() 前先判断 entry.is_dir。
环境
- Docker(Python 3.13)
- 相关代码:
server/routers/system.py:260、service/core.py:516、storage/viking_fs.py:2380