OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug] v0.4.19 regression: snapshot commit fails on all paths (full-tree PERMISSION_DENIED, explicit-path HTTP 500)

Open xbyzr opened this issue 2 months ago • 4 comments

Environment: v0.4.19 (pip install), Ubuntu 24.04, Python 3.12, local deployment, single account with per-user api_keys.

Regression: on v0.4.17, ov snapshot commit -m "..." (no paths) committed the full account tree and worked. After upgrading to v0.4.19 every invocation path fails (v0.4.18 untested — we jumped 0.4.17 → 0.4.19):

  1. No paths (full tree) → PERMISSION_DENIED "Snapshot commit requires explicit paths" — yet the CLI help still says "Omit to snapshot the full account tree".
  2. Explicit paths ov snapshot commit -m test --paths viking://user/<agent> with that user's own key over its own domain → HTTP 500 INTERNAL "Internal server error". Reproduces consistently across multiple domains/keys.
  3. Root/admin API key on POST /api/v1/snapshot/commit → PERMISSION_DENIED "ROOT API keys cannot access tenant-scoped data APIs in api_key mode".
  4. Cross-domain path with a user key is correctly denied (isolation working as intended).

Server-side traceback for case 2 (paths generalized):

server/routers/snapshot.py:63 commit
  → service/fs_service.py:1187 commit
  → storage/viking_fs/_snapshot.py:287 commit
  → pyagfs/async_client.py:96 run → asyncio to_thread → error

Impact: our automated nightly backup takes a full-tree snapshot before archiving; that step has been silently failing since the upgrade (the deployment is currently protected only by plain filesystem backups of the data dir).

Questions: what is the intended permission model in v0.4.19 — is there a sanctioned way to programmatically commit an account-tree snapshot? And the 500 on explicit paths looks like a genuine bug. Minimal repro: create a user key, then ov snapshot commit -m test --paths viking://user/<that-user>.

Happy to retest on any build containing a fix and report back — that workflow closed the loop nicely on #4329 for us.

xbyzr avatar Sep 26 '26 14:09 xbyzr

I could not reproduce case 2 with the current snapshot implementation and the real Rust binding/local git backend. An in-process HTTP → FSService → VikingFS test returned:

  • paths=["viking://user/alice"]: 200, created (one file).
  • paths=["viking://user/alice/memories"]: 200, noop on the second snapshot.
  • No paths: 403, explicit paths required.
  • Another user's path: 403.

This test injects the USER request context; it does not reproduce your API-key deployment or prove v0.4.19 works. The 43 existing native snapshot tests also passed. The snapshot mixin/router bytes match current main.

Could you provide the final exception type and message after asyncio.to_thread in the server traceback, plus the effective git.enabled, git backend and RAGFS/pathlock backend (redact credentials and local paths)? That will distinguish the native failure from the intentional full-tree restriction. #5070 addresses missing/deleted targets, so it should not automatically be treated as a fix for this existing-directory failure.

The CLI help is inconsistent: omitting paths currently requires an internal ROOT context, while ROOT API keys are rejected on tenant data routes. At minimum the help should state the explicit-path requirement for API-key clients. I have not changed the access checks.

AI-assisted local reproduction and analysis.

r266-tech avatar Sep 28 '26 10:09 r266-tech

Thanks for reporting this. Following up on the request above, we'd like to investigate case 2: HTTP 500 when taking a snapshot of your own directory with your user key.

Could you share:

  1. The full server traceback for one failed request, including the final exception type and message after asyncio.to_thread. The excerpt currently stops before the actual error.
  2. The failing command and its complete terminal output. Can the same user key list and read that directory successfully? Does the snapshot failure also occur for a small, newly created directory, or only existing data?
  3. The relevant git and storage.agfs configuration, including the storage and pathlock backends. Please redact API keys, credentials, and sensitive paths while keeping identifiers consistent across the examples.

The explicit-path 500 is separate from the permission errors when omitting paths or using a ROOT key. We don't yet have enough information to identify its cause, so we're keeping this issue open.

qin-ctx avatar Sep 28 '26 12:09 qin-ctx

Thanks for taking a look. Here are the details you asked for:

Terminal exception (explicit-path case, from the server journal):

ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
Error: vfs: plugin error: is a directory:
  /default/user/<agent>/memories/experiences/<name>.md

Root cause located on our deployment: the extraction pipeline under v0.4.19 had accumulated 212 empty .md-named directories inside memories/experiences/ (see #5404 — the rejected content.edit() operations appear to leave these orphans behind). One of them sat on the snapshot path. git_commit in pyagfs expects experiences/*.md to be files, hits an empty directory, and dies with the vfs error above.

After deleting the empty orphan directories, explicit-path snapshot commit works again (verified: POST /api/v1/snapshot/commit with a user key, paths: ["viking://user/<agent>"] → commit_oid created). 0.4.17 full-tree never had this problem — which is probably why it doesn't reproduce in your environment (0.4.17 leaves no orphans).

Backend config (sanitized): storage.agfs.backend: local, storage.vectordb: {name: context, backend: local}, server.auth_mode: api_key, local pip install, single account with per-user keys.

Still open for us, in case you can advise: the full-tree commit (empty paths) still returns PERMISSION_DENIED "Snapshot commit requires explicit paths" for our own account tree, while the CLI help says omitting paths snapshots the full tree — is that intended?

xbyzr avatar Sep 28 '26 12:09 xbyzr

Thanks, this adds a useful distinction. I reproduced the same HTTP 500 shape through HTTP → FSService → VikingFS with the real Rust/local-git binding (the installed 0.4.22 wheel), using an injected USER context:

  1. Commit user/alice/memories/note.md as a regular file: 200, created.
  2. Add a new, never-snapshotted empty orphan.md directory under the same scope: 200, noop.
  3. Replace the previously snapshotted note.md file with an empty directory at the same path: 500, INTERNAL (native error: is a directory).
  4. Remove that empty directory and commit the same scope: 200, deletion recorded.

Current main's Rust candidate loop explains this difference: it unions current files with paths from the previous snapshot to detect deletions, then attempts to read a former file even when its current stat says directory. I plan to fix that file→directory transition at the snapshot layer and cover it with real-local-filesystem regression tests, including preserving unrelated snapshot contents. This does not yet establish how your 212 directories were created or whether all were previously tracked; I have not reproduced the extraction/parser cleanup path.

On the permission question: current VikingFS.commit explicitly requires paths for both USER and ADMIN contexts. Only an internal/local ROOT context may omit it; a ROOT API key is deliberately rejected on tenant data APIs. Thus omitting paths is not currently an account-wide backup operation available through API-key HTTP access. Continue supplying the writable scopes explicitly (such as your own viking://user/<agent>); a partial commit preserves the previous snapshot outside those scopes. The CLI wording is misleading, while the current snapshot guide already documents the ROOT-only omission rule. I will keep the existing authorization checks intact.

AI-assisted local reproduction; this does not reproduce your API-key deployment or establish the orphan-creation cause.

r266-tech avatar Sep 28 '26 17:09 r266-tech