Persistent 417 Nextcloud Assistant and LocalAI on NC 30.0.5 Despite Common Solutions

Hello everyone,

I am really hoping someone can help me untangle this issue. I’m facing a persistent problem with Nextcloud Assistant (latest) and LocalAI on Nextcloud 30.0.5 (Docker). I get a 417 “Expectation Failed” error, but the complete absence of relevant logs is the biggest roadblock.

The Core Problem:

When using Nextcloud Assistant, the UI loader spins indefinitely, and I see a 417 “Expectation Failed” error in the browser console. However, I cannot find any corresponding log entries in Nextcloud, Apache, or Docker logs - even with debug => true and loglevel => 0 in config.php!

The OpenAI Twist:

Interestingly, when I configure the plugin OpenAI/localAi, the connection works, the models are found. This strongly suggests that my network connectivity is functional.

My Setup/Configuration:

Nextcloud 30.0.5 (installed via Docker)

Web server: Apache
# Proxy Nextcloud
ProxyPass /nextcloud/ http://localhost:8081/
ProxyPassReverse /nextcloud/ http://localhost:8081/

RequestHeader set X-Forwarded-Proto “https”
RequestHeader set X-Forwarded-Host “xxx.access.ly”
RequestHeader set X-Forwarded-Port “443”
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/nextcloud/(.*) “ws://localhost:8081/nextcloud/$1” [P,L]

LimitRequestFieldSize 16380

Database: MySQL

LocalAI: Running in a separate Docker container, accessible via http://172.24.0.100:8080

config.php settings:

‘debug’ => true,

‘loglevel’ => 0,

‘expect_100_continue’ => false,

‘allow_local_remote_servers’ => true,

‘trusted_domains’ => array( … ‘172.24.0.100’, … ),

Troubleshooting Steps Already Taken:

I’ve already attempted the following solutions, without success:

Disabled the “Expect: 100-continue” header in config.php

Enabled allow_local_remote_servers in config.php

Added the LocalAI IP to trusted_domains in config.php

Restarted Apache and Docker containers

Verified the Apache reverse proxy configuration (including ProxyPass directives and X-Forwarded-* headers)

Confirmed that LocalAI is accessible via its internal URL from inside the Nextcloud container

Increased header limits (LimitRequestFieldSize) in apache

Extensive Log Review: Examined Nextcloud, Apache, and Docker logs, but found no relevant error messages pertaining to the Assistant or the 417 error, even with debug mode enabled.

The Critical Issue: Lack of Logging

The most perplexing part is that, even with debug => true and loglevel => 0 in config.php, I cannot find any log entries related to Nextcloud Assistant or the 417 error. This makes it extremely difficult to diagnose the root cause.

I have a similar issue and i am following in hope for a solutin.

I fixed the issue and documented it for myself so i thought to share it.
This fix is for setup with Nextcloud on TrueNAS Scale

Links:

Below is a comprehensive, start‑to‑finish guide to permanently fixing the “417 errors” and 5‑minute delays when using the Nextcloud AI Assistant on a TrueNAS SCALE installation. These instructions assume:

  • You’ve installed Nextcloud in a Docker container on TrueNAS SCALE (for example, named ix-nextcloud-nextcloud-1).
  • You want the AI Assistant to respond instantly rather than waiting for the default background job interval.

Why This Fix Is Needed

  • Nextcloud 30+ runs many AI tasks via the background job system.
  • By default, those jobs only run every 5 minutes, resulting in 417 Expectation Failed errors until the job is processed.
  • Solution: continuously run the Nextcloud background‑job worker so it picks up tasks immediately.

1. Identify Your Nextcloud Container Name

On TrueNAS SCALE, your container might be named ix-nextcloud-nextcloud-1. If you’re unsure, run:
docker ps

Locate your Nextcloud container in the output. Use that exact container name in the steps below.


2. Create a Worker Script

  1. SSH into your TrueNAS SCALE host (not inside the container).
  2. Pick a location for the script; for example, /mnt/Pool/scripts/nextcloud-ai-worker.sh.
  3. Create/Edit the script (using vi, nano, etc.):
#!/bin/bash
# /mnt/Pool/scripts/nextcloud-ai-worker.sh

CONTAINER_NAME="ix-nextcloud-nextcloud-1"

while true; do
  if docker ps --filter "name=${CONTAINER_NAME}" --format "{{.Names}}" | grep -q "${CONTAINER_NAME}"; then
    echo "$(date): Container ${CONTAINER_NAME} is running. Starting worker..."
    echo "$(date): Starting worker..."
    docker exec -u www-data ${CONTAINER_NAME} php occ background-job:worker -v -t 60 'OC\TaskProcessing\SynchronousBackgroundJob'
    echo "$(date): Worker run complete"
    RC=$?
    echo "$(date): Worker exited with status ${RC}"
  else
    echo "$(date): Container ${CONTAINER_NAME} is not running. Waiting for it to start..."
  fi
  sleep 1
done
  1. Fix Windows Line Endings (if needed):
    If you see errors like $'\r': command not found,
    run:
    sed -i 's/\r//' /mnt/Pool/scripts/nextcloud-ai-worker.sh

  2. Make the Script Executable:
    chmod +x /mnt/Pool/scripts/nextcloud-ai-worker.sh


3. Test the Worker Script Manually

Run it once from the TrueNAS host to confirm it works:

bash /mnt/Pool/scripts/nextcloud-ai-worker.sh

  • You should see messages like:

    Fri Mar 7 00:12:47 PST 2025: Container ix-nextcloud-nextcloud-1 is running. Starting worker... Background job worker will stop after 60 seconds Waiting for new jobs to be queued ...

  • Open Nextcloud AI Chat and send a message. It should respond instantly, with no 417 errors.

  • After 60 seconds, you’ll see “Worker exited with status …” (which is normal, as the worker exits and the script loop restarts it).

Press Ctrl+C to stop it once you’ve confirmed it’s working.


4. Make the Worker Start Automatically After Reboot

TrueNAS SCALE lets you define “Init/Shutdown Scripts.” We’ll create an Init or post init command that runs your script in the background on every boot.

  1. Log in to the TrueNAS SCALE Web UI.
  2. Navigate to: System Settings → Advanced → Init/Shutdown Scripts (the exact path can vary by SCALE version).
  3. Add a New Entry:
    • Description: “Nextcloud AI Worker” (or similar).

    • Type: Choose Command.

    • Command:
      bash /mnt/Pool/scripts/nextcloud-ai-worker.sh &

      The trailing & ensures it runs in the background.

    • When: Usually Post Init is best, so the container is up when the script runs.

    • Enabled: Check this box to enable it.

    • Timeout: You can leave it at 10 seconds, because the command will background itself almost immediately.

  4. Save the entry, then Reboot TrueNAS.

5. Verify the Worker Auto-Starts

After the reboot:

  1. Check the Script’s Logs (if you decided to redirect them in the script) or simply check if the process is running:
    ps aux | grep nextcloud-ai-worker.sh
    You should see a process line for it.

  2. Open the Nextcloud AI Chat and send a test message. It should respond immediately, with no 417 errors.


6. Common Questions and Notes

  1. “context canceled” or “Waiting for new jobs to be queued”:
    These are normal messages. “context canceled” often shows when the container or worker is stopped. “Waiting for new jobs…” appears when the worker is idle.
  2. Memory Limit Warning:
    You might see “Failed to set memory limit to 0 bytes” or “Current memory usage is …”. Generally, it’s just a warning; you can ignore it unless you want to increase php.ini memory.
  3. Why -t 60?
    The -t 60 means each worker instance exits after 60 seconds, letting it pick up new code or config changes on each restart. If you remove -t 60, it will run indefinitely (but you’d have to manually restart it if you update Nextcloud or its apps).

Final Recap

  • Create the looping script with the docker exec background‑job worker call.
  • Test it manually to ensure near-instant AI chat responses.
  • Set it up to run on reboot via TrueNAS SCALE’s “Init/Shutdown Scripts.”

Dear Mostafa_Wahied,

Thank you very much for sharing your comprehensive guide to fix the 417 errors and 5-minute delays with the Nextcloud AI Assistant on TrueNAS SCALE. I followed your instructions step-by-step, and I can confirm that the solution works. i still have somme others probleme but i’m now in the good way.

Your detailed guide was incredibly helpful, and I appreciate the time and effort you put into documenting it.
Thank you again for your assistance!

Best regards,

1 Like

I am happy it helped!