nextcloud / nextcloud/context_chat

Embedding files can fail, when storage has multiple shared mounts

Open
#254 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority: medium
Dominant language
PHP
Stars
29
Forks
12
Avg merge
4d 4h
Merged PRs (30d)
5

Description

Which version of Nextcloud are you using?

v34.0.1

Which version of PHP context_chat are you using?

5.4.0

Which version of backend context_chat are you using?

5.4.0

Which browser are you using? In case you are using the phone App, specify the Android or iOS version and device please.

Firefox 152.0.3

Nextcloud deployment method?

AIO

Describe the Bug

After installing context_chat and context_chat_backend, I had the issue that only 1.7k of 10k eligible files were written to the vector database.

When trying to debug the issue, I found a lot of File not found or not a file errors triggered by the /ocs/v2.php/apps/context_chat/queues/documents?n=32&format=json endpoint. This happened even though I ran a full file scan before installing Context Chat.

I think root cause is $userId = $mounts[0]->getUser()->getUID() in OCA\ContextChat\Controller\QueueController::getFileSource().
It chooses a user by taking the first mount returned from IUserMountCache::getMountsForStorageId($storageId).
On a storage with many shared mounts, the first result is not always the owner / it can belong to a user that cannot access the queued file ID.
In this case getFirstNodeById($fileId) returns null and QueueController logs File not found or not a file.

To Reproduce
  1. Install a clean Nextcloud 32.0.0 instance.
  2. Create three users: owner, aaa, and bbb.
  3. As owner, create an eligible test file: /owner/files/Test-Text.md
  4. As owner, create another folder on the same home storage: /owner/files/other/
  5. Share Test-Text.md with aaa.
  6. Share other/ with bbb.
  7. Login as aaa and open Test-Text.md
  8. Login as bbb and open other/
  9. The returned mount order when calling getMountsForStorageId() should be:
    owner  /owner/
    aaa    /aaa/files/Test-Text.md/
    bbb    /bbb/files/other/
    
  10. Logout all users
  11. Upgrade the instance to Nextcloud 33, then to Nextcloud 34.
  12. After the upgrade, access the users in the following order via WebDAV (this fills oc_mounts again, but in a different order):
    curl -u bbb:<password> http://<nextcloud>/remote.php/dav/files/bbb/
    curl -u aaa:<password> http://<nextcloud>/remote.php/dav/files/aaa/
    curl -u owner:<password> http://<nextcloud>/remote.php/dav/files/owner/
    
  13. Call getMountsForStorageId() again, the returned mount order should have changed:
    bbb    /bbb/files/Other/
    aaa    /aaa/files/Test-Text.md/
    owner  /owner/
    
  14. Install and enable context_chat 5.4.0 and context_chat_backend.
  15. Trigger the initial indexing.
  16. You should see File not found or not a file in the logs, because $userId = $mounts[0]->getUser()->getUID(); returns a user who doesn't have access to Test-Text.md now.

I'm happy to provide a vServer with an affected Nextcloud instance if needed. Just let me know.

PHP logs (Warning these might contain sensitive information)

No response

Ex-App logs (Warning these might contain sensitive information)

No response

Server logs (if applicable)
{
  "reqId": "XJEkVDoB8Qajy8bOA0WC",
  "level": 2,
  "time": "2026-07-01T16:57:02+00:00",
  "remoteAddr": "XXX.XXX.XXX.XXX",
  "user": "--",
  "app": "context_chat",
  "method": "GET",
  "url": "/ocs/v2.php/apps/context_chat/queues/documents?n=32&format=json",
  "scriptName": "/ocs/v2.php",
  "message": "File not found or not a file",
  "userAgent": "ExApp/context_chat_backend/5.4.0 (niquests/3.19.1)",
  "version": "34.0.1.2",
  "exception": {
    "Exception": "Exception",
    "Message": "File not found or not a file",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/html/custom_apps/context_chat/lib/Controller/QueueController.php",
        "line": 125,
        "function": "getFileSource",
        "class": "OCA\\ContextChat\\Controller\\QueueController",
        "type": "->",
        "args": [
          { "__class__": "OCA\\ContextChat\\Db\\QueueFile", "id": 24118 },
          { "__class__": "OC\\Files\\Node\\LazyRoot" },
          { "__class__": "OCA\\ContextChat\\Service\\StorageService" },
          { "__class__": "OC\\Files\\Config\\UserMountCache" }
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 165,
        "function": "getDocumentsQueueItems",
        "class": "OCA\\ContextChat\\Controller\\QueueController",
        "type": "->",
        "args": [
          { "__class__": "OCA\\ContextChat\\Service\\StorageService" },
          { "__class__": "OC\\Files\\Node\\LazyRoot" },
          { "__class__": "OCA\\ContextChat\\Db\\QueueMapper" },
          { "__class__": "OCA\\ContextChat\\Db\\QueueContentItemMapper" },
          { "__class__": "OC\\Files\\Config\\UserMountCache" },
          32
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 78,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [ { "__class__": "OCA\\ContextChat\\Controller\\QueueController" }, "getDocumentsQueueItems" ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/App.php",
        "line": 137,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [ { "__class__": "OCA\\ContextChat\\Controller\\QueueController" }, "getDocumentsQueueItems" ]
      },
      {
        "file": "/var/www/html/lib/private/Route/Router.php",
        "line": 324,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\ContextChat\\Controller\\QueueController",
          "getDocumentsQueueItems",
          { "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer" },
          { "_route": "ocs.context_chat.queue.getdocumentsqueueitems" }
        ]
      },
      { "file": "/var/www/html/ocs/v1.php", "line": 63, "function": "match", "class": "OC\\Route\\Router", "type": "->", "args": [ "/ocsapp/apps/context_chat/queues/documents" ] },
      { "file": "/var/www/html/ocs/v2.php", "line": 10, "args": [ "/var/www/html/ocs/v1.php" ], "function": "require_once" }
    ],
    "File": "/var/www/html/custom_apps/context_chat/lib/Controller/QueueController.php",
    "Line": 301,
    "message": "File not found or not a file",
    "exception": "{\"class\":\"Exception\",\"message\":\"File not found or not a file\",\"code\":0,\"file\":\"/var/www/html/custom_apps/context_chat/lib/Controller/QueueController.php:301\",\"trace\":\"#0 /var/www/html/custom_apps/context_chat/lib/Controller/QueueController.php(125): OCA\\ContextChat\\Controller\\QueueController->getFileSource(Object(OCA\\ContextChat\\Db\\QueueFile), Object(OC\\Files\\Node\\LazyRoot), Object(OCA\\ContextChat\\Service\\StorageService), Object(OC\\Files\\Config\\UserMountCache))\\n#1 /var/www/html/lib/private/AppFramework/Http/Dispatcher.php(165): OCA\\ContextChat\\Controller\\QueueController->getDocumentsQueueItems(Object(OCA\\ContextChat\\Service\\StorageService), Object(OC\\Files\\Node\\LazyRoot), Object(OCA\\ContextChat\\Db\\QueueMapper), Object(OCA\\ContextChat\\Db\\QueueContentItemMapper), Object(OC\\Files\\Config\\UserMountCache), 32)\\n#2 /var/www/html/lib/private/AppFramework/Http/Dispatcher.php(78): OC\\AppFramework\\Http\\Dispatcher->executeController(Object(OCA\\ContextChat\\Controller\\QueueController), 'getDocumentsQue...')\\n#3 /var/www/html/lib/private/AppFramework/App.php(137): OC\\AppFramework\\Http\\Dispatcher->dispatch(Object(OCA\\ContextChat\\Controller\\QueueController), 'getDocumentsQue...')\\n#4 /var/www/html/lib/private/Route/Router.php(324): OC\\AppFramework\\App::main('OCA\\\\ContextChat...', 'getDocumentsQue...', Object(OC\\AppFramework\\DependencyInjection\\DIContainer), Array)\\n#5 /var/www/html/ocs/v1.php(63): OC\\Route\\Router->match('/ocsapp/apps/co...')\\n#6 /var/www/html/ocs/v2.php(10): require_once('/var/www/html/o...')\\n#7 {main}\"}",
    "CustomMessage": "File not found or not a file"
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/Controller/QueueController.php, especially getFileSource() and the /ocs/v2.php/apps/context_chat/queues/documents endpoint, then trace how getMountsForStorageId() selects a user for a storage. Reproduce the documented shared-mount ordering scenario and verify that initial indexing can process eligible files without File not found or not a file errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.