fix(session-manager): chown new session dirs when host runs as root#2353
Open
netadmincmh-hash wants to merge 1 commit into
Open
fix(session-manager): chown new session dirs when host runs as root#2353netadmincmh-hash wants to merge 1 commit into
netadmincmh-hash wants to merge 1 commit into
Conversation
Two constraints collide on a Linux install where the NanoClaw host runs as
root and the data directory is on a network filesystem (NFS, etc.):
1. The agent image ships with USER node (uid 1000) and Claude Code refuses
to run as root with the error:
--dangerously-skip-permissions cannot be used with root/sudo privileges
so we cannot pass --user 0:0 to docker run as a workaround.
2. The host writes inbound.db and the session-folder scaffolding as uid 0.
On a network filesystem the container's uid 1000 cannot write outbound.db
or touch the heartbeat file, and bun:sqlite surfaces this as
Fatal error: attempt to write a readonly database
The result is an unrecoverable spawn loop: every container exits with code 1
microseconds after agent-runner startup, and the host sweep marks the inbound
message completed after a few retries.
This patch chowns each freshly-created session directory to 1000:1000 when
process.getuid() === 0. No-op when the host already runs as the container UID
(1000) or any other non-root UID — those paths fall through to the existing
--user $hostUid:$hostGid mapping in container-runner.ts. chown is best-effort:
if it fails, the agent will fail later with the clearer SQLite error and the
sweep retries until the operator notices.
Reproducer: run nanoclaw-v2 as root with /pods on NFS, send any inbound
message; container exits code=1 with 'attempt to write a readonly database'.
This was referenced May 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Linux installs that run NanoClaw as root with the data directory on a network filesystem hit an unrecoverable container spawn loop. Two constraints collide:
The agent image ships with
USER node(uid 1000) and Claude Code refuses to run as root:So
--user 0:0ondocker runis not a workaround.The host process writes
inbound.dband the session-folder scaffolding as uid 0. On a network filesystem (NFS in my case) the container's uid 1000 cannot writeoutbound.dbortouchthe heartbeat file.bun:sqlitesurfaces this as:The container exits code=1 microseconds after
agent-runnerstartup, the host sweep retries a few times, then marks the inbound message completed without ever sending a response.What this changes
initSessionFolderchowns each freshly-created session directory to1000:1000whenprocess.getuid() === 0. No-op for any non-root host UID — those paths fall through to the existing--user $hostUid:$hostGidmapping incontainer-runner.ts.execFileSync('chown', ...)is best-effort: if it fails, the agent fails later with the clearer SQLite error and the sweep retries until the operator notices.Test plan
pnpm run buildpasses (no new deps, no type changes)./pods), reproduced the spawn loop onmain. With this patch applied,chown -R 1000:1000 <session-dir>runs at session create, the container'snodeuser can writeoutbound.db, and Telegram round-trip completes (verified end-to-end).Reproducer
Notes / things to discuss
1000:1000matches the image'sUSER nodedirective but isn't future-proof if the image ever changes UID. If you'd prefer, this could be made configurable via env var (e.g.NANOCLAW_CONTAINER_UID:GID) or read from the image at startup. Happy to fold in either approach.chown -R 1000:1000 data/v2-sessions/.🤖 Generated with Claude Code