ncl tasks delete half-fails on Linux: Docker-created root-owned mount points block the session directory rmSync
Summary
On Linux (rootful Docker), deleting a scheduled task leaves an orphaned active session with no mailbox. After that, the host logs collectTasks: inbound.db unreadable … SqliteError: unable to open database file once a minute, indefinitely.
Cause
buildMounts (src/container-runner.ts) bind-mounts the session directory at /workspace and nests other mounts inside it: /workspace/agent, /workspace/global, provider state volumes such as /workspace/group, and allowlisted extras at /workspace/extra/<name>. When a nested target doesn't exist in the host session directory, the Docker daemon creates it there as root.
deleteTaskCommand (src/cli/resources/tasks.ts) then runs, in order:
destroySessionMailbox(...): succeeds, soinbound.db/outbound.dbare gonefs.rmSync(sessionDir(...), { recursive: true, force: true }): throwsEACCESon the root-owned stubsdeleteSession(id)anddeleteRunLog(...): never run
The sessions row stays active, pointing at a directory with no databases. A retry can't help: step 2 fails the same way every time, and the task no longer shows in ncl tasks list because that list is read from the destroyed mailbox.
Reproduce
- On Linux with rootful Docker, create a recurring task and let it run once, so its session container spawns.
ls -la data/v2-sessions/<ag>/<task-session>/:agent/,global/,group/are owned byroot.ncl tasks delete <series>: the mailbox is removed, and the command errors or leaves the directory in place.SELECT status FROM sessions WHERE id='<task-session>'still returnsactive;logs/nanoclaw.error.logshows thecollectTaskswarning every 60s.
Scale on one install: 176 of 179 session directories had root-owned stubs, so this affects essentially every task delete.
Suggested fix
Pre-create nested mount targets as the host user before spawn, so Docker never has to create them. For each mount whose nearest enclosing mount is /workspace, mkdir -p the target inside sessDir (or create an empty file if the source is a file). Skip targets nested under another mount, targets outside /workspace, existing paths, and anything that resolves outside sessDir.
A local patch doing this (ensureSessionMountPoints, called at the end of buildMounts, with unit tests) is available as a PR if that's useful.
Optional hardening in deleteTaskCommand: delete the central sessions row even when the directory rmSync fails, and report the leftover path, so a permissions problem can't leave an orphaned session behind.
Existing installs also need a one-time cleanup: the stubs are root-owned, so the host can't fix them itself. Something like docker run --rm --user 0 -v "$PWD/data/v2-sessions:/s" <agent-image> find /s -mindepth 3 -maxdepth 4 -user root -type d -exec chown <uid>:<gid> {} +, or a note in the release notes.
Source: nanocoai/nanoclaw