OpenMemory icon indicating copy to clipboard operation
OpenMemory copied to clipboard

Dashboard Settings page always fails to save (EACCES on /.env inside Docker)

Open ViolinKaine opened this issue 4 months ago • 4 comments

Summary (Co-Authored by Claude code)

The dashboard's Settings page always fails to save with "Failed to save settings. Check backend connection." — but it's not actually a backend/API connectivity issue. The Next.js API route that handles the save writes to a path that only resolves correctly in local dev (next dev from a git checkout), not in the Docker deployment that docker-compose.yml documents as the standard way to run the dashboard.

Root Cause

dashboard/app/api/settings/route.ts:5:

const ENV_PATH = path.resolve(process.cwd(), '../.env')

This assumes process.cwd() is the dashboard/ directory inside a full monorepo checkout, so ../.env resolves to the repo root's .env. That's true for local dev.

But dashboard/Dockerfile sets WORKDIR /app and copies only the built dashboard output into the image — there's no monorepo layout inside the container, no sibling .env one directory up, and /.env (where the path resolves to from /app) doesn't exist and isn't writable by the non-root nextjs user the container runs as.

Result: any Docker-based deployment (i.e. docker-compose.yml as shipped) gets a write failure on every settings save attempt, surfaced as a generic backend-connection error that has nothing to do with the actual cause.

Reproducer

  1. docker compose --profile ui up (per the repo's own docker-compose.yml)
  2. Open the dashboard → Settings
  3. Change any field, click "Save to .env"
  4. Server-side error (visible via docker compose logs dashboard):
    [Settings API] write error: Error: EACCES: permission denied, open '/.env'
    
  5. UI shows: "Failed to save settings. Check backend connection." — misleading, since the backend (:8080) was never involved; this route writes directly to a file on the dashboard container's own filesystem.

Suggested Fix

The settings route shouldn't write to a file inside the dashboard container's filesystem at all when running in Docker — that file isn't shared with the backend container and doesn't persist across image rebuilds either way. Options:

  • Have the dashboard call the backend server's own config/settings API (if one exists) instead of writing a local .env, so the write actually reaches the process that reads it.
  • If a shared .env truly needs editing, mount it as a volume into the dashboard container at a fixed path and reference that path (not a relative ../) so it doesn't depend on cwd.

Happy to open a PR if a preferred direction is confirmed.

Environment

  • Deployment: docker compose --profile ui up (repo's own compose file, unmodified aside from a local override for uid/gid and Ollama host networking)
  • Images built from current main via the repo's Dockerfiles
  • Dashboard on :3000, backend on :8080

ViolinKaine avatar Jul 30 '26 12:07 ViolinKaine

I will take this issue. Please assign it to me.

The problem is that the ENV_PATH in dashboard/app/api/settings/route.ts resolves incorrectly in the Docker environment. It tries to write to /.env, which is not writable. I would first verify the Docker setup and confirm the path resolution issue. The fix could involve changing the settings route to either call a backend API for configuration changes or mount the .env file as a volume at a fixed path. I will ensure the solution works with the existing Docker setup.

modelpath-dev avatar Sep 10 '26 21:09 modelpath-dev

I am still looking into this issue. I will verify the Docker setup and confirm the path resolution problem. Once confirmed, I will work on a solution that either involves calling a backend API for configuration changes or mounting the .env file as a volume. Let me know if there are any preferences or additional insights.

modelpath-dev avatar Sep 13 '26 08:09 modelpath-dev

The write path this issue named is gone on current main.

d638f52 (18 Aug) removed ENV_PATH = path.resolve(process.cwd(), '../.env') and the Save to .env UI. dashboard/app/api/settings/route.ts now returns read_only: true on GET and 405 on POST. The Settings page says configuration is read-only and to change env on the backend, then restart.

docker compose --profile ui up on current main cannot hit EACCES on /.env because nothing opens that file.

This can be closed as fixed by the rewrite. If anyone still sees the old save button, they are on a pre-rewrite image.

modelpath-dev avatar Sep 13 '26 11:09 modelpath-dev

Closing as fixed — as confirmed in the thread, the write path this issue named (ENV_PATH = path.resolve(process.cwd(), '../.env') in dashboard/app/api/settings/route.ts) was removed in d638f52. The Settings page is now read-only (GET returns read_only: true, POST returns 405) and tells the user to change env on the backend and restart, so there's no /.env write for Docker's non-root user to fail on.

Thanks for the clear root-cause report, and to @modelpath-dev for tracking it down and confirming the fix.

nullure avatar Oct 18 '26 09:10 nullure