Skip to content

[Bug]: Docker agent/tool memory writes create root-owned files unreadable by gateway user #17144

Closed as not planned

Description

@CipherFrame

Bug Description

Summary

In a Docker deployment using nousresearch/hermes-agent:latest / Hermes dashboard v0.11.0 / release 2026.4.23, Hermes persistent state under /opt/data is being written by agent/tool memory operations as root:root with restrictive permissions, while the gateway process runs as the hermes user / UID 10000.

This causes files such as /opt/data/memories/MEMORY.md to become unreadable by the gateway. Memory can appear to be written successfully by the agent/tool side, but the running gateway cannot reliably read/inject it into session context.

This appears reproducible after memory-tool writes/consolidation.

Environment

  • Image: nousresearch/hermes-agent:latest
  • Dashboard version: 0.11.0
  • Release date shown by dashboard: 2026.4.23
  • Docker host: Synology NAS / DSM
  • Persistent host path: /volume1/docker/hermes
  • Container path: /opt/data
  • Main container command: gateway run
  • Dashboard container command: dashboard --host 0.0.0.0 --port 9119 --no-open --insecure
  • Gateway process runs as hermes / UID 10000
  • Container PID 1 runs via tini / entrypoint as root, then the gateway process runs as hermes

Steps to Reproduce

  1. Run Hermes in Docker with persistent host storage mounted to /opt/data.
  2. Confirm the gateway process runs as hermes / UID 10000:
docker exec hermes sh -lc 'ps aux | grep -Ei "[h]ermes|[g]ateway"'
  1. Fix memory ownership manually so it is readable by the gateway:
sudo chown 10000:10000 /volume1/docker/hermes/memories/MEMORY.md
sudo chmod 660 /volume1/docker/hermes/memories/MEMORY.md
  1. Ask the agent to write/consolidate memory using the memory tool.
  2. Check ownership again:
docker exec hermes sh -lc 'ls -la /opt/data/memories/MEMORY.md /opt/data/memories/USER.md'
  1. Observe that MEMORY.md has reverted to root:root with mode 0600.

Expected Behavior

All Hermes persistent state written under $HERMES_HOME / /opt/data should remain readable/writable by the Hermes runtime user.

Expected:

-rw-rw---- 1 hermes hermes ... /opt/data/memories/MEMORY.md

or equivalent UID/GID 10000:10000. Memory writes should not make the file unreadable by the running gateway process.

Actual Behavior

Memory/tool writes create or replace state files as:

-rw------- 1 root root ... /opt/data/memories/MEMORY.md

This breaks the non-root gateway process because the gateway runs as hermes / UID 10000.

Observed after memory write:

-rw------- 1 root   root   2435 Apr 28 19:35 /opt/data/memories/MEMORY.md
-rw-rw---- 1 hermes hermes 1105 Apr 24 21:12 /opt/data/memories/USER.md

Earlier cron symptom:

IOError reading jobs.json: [Errno 13] Permission denied: '/opt/data/cron/jobs.json'

The issue is recurring permission drift caused by root-written files under /opt/data.

Affected Component

Agent Core (conversation loop, context compression, memory)

Messaging Platform (if gateway-related)

No response

Debug Report

Debug report generated with `docker exec -it hermes hermes debug share`.

Report:
https://paste.rs/lGUr0

Note: agent.log and gateway.log failed to upload due paste service errors. The report link auto-deletes after 6 hours.

I reviewed the report before posting. It does not appear to include raw API keys, but it does include configured-provider names, local container paths, Docker network IPs, cron job names, skill paths, and recent log excerpts.

Additional relevant evidence from the report:
- Gateway is running in Docker.
- Hermes home is `/opt/data`.
- Dashboard/Hermes version is `0.11.0` / `2026.4.23`.
- Cron job execution showed multiple permission-denied errors reading skill files under `/opt/data/skills/...`.

Operating System

Synology DSM / Docker

Python Version

No response

Hermes Version

0.11.0

Additional Logs / Traceback (optional)

Repeated cron permission error previously observed:


IOError reading jobs.json: [Errno 13] Permission denied: '/opt/data/cron/jobs.json'


Dashboard status after API server fix:


"gateway_running": true,
"gateway_state": "running",
"gateway_platforms": {
  "telegram": { "state": "connected" },
  "api_server": { "state": "connected" }
}


The gateway itself runs successfully, but state files created/replaced by root-running agent/tool operations can become unreadable by the gateway runtime user.

Root Cause Analysis (optional)

The apparent root cause is a UID/GID mismatch in Docker:

  • Gateway/runtime process runs as hermes / UID 10000.
  • Agent/tool/memory write operations appear to run as root / UID 0.
  • Persistent state is shared under $HERMES_HOME / /opt/data.

When the memory tool writes or replaces /opt/data/memories/MEMORY.md, the replacement file is created as root:root with mode 0600. The gateway process later needs to read the same file as hermes but cannot.

This same pattern can affect any persistent file under /opt/data — cron state, profile dirs, generated docs, skills, cache, config backups.

Proposed Fix (optional)

Ensure all writes under $HERMES_HOME / /opt/data are performed as the Hermes runtime UID/GID, or normalize ownership/mode after writes.

Preferred behavior:

  • Memory/config/cron/state writes should be owned by hermes:hermes / UID 10000:10000.
  • Regular state files should be readable/writable by the runtime user, e.g. mode 0660.
  • Directories should be accessible by the runtime user, e.g. mode 0770.

Possible fixes:

  1. Run agent/tool write operations as UID/GID 10000:10000.
  2. Ensure memory-tool file replacement preserves existing ownership/mode.
  3. Add ownership/mode normalization after writes under $HERMES_HOME.
  4. Avoid creating persistent runtime files as root:root when the gateway runs as non-root.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    P2Medium — degraded but workaround exists
    tool/memoryMemory tool and memory providers
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    on Apr 28, 2026
  2. alt-glitch commented on Apr 28, 2026

    @alt-glitch

    Related to #15718 (auth.json root ownership) and #10270 (pairing files root ownership) — same class of Docker root-writes bug. PRs #11071 and #15861 fix the pairing and auth variants respectively; this is the memory-tool write path.

  3. CipherFrame commented on Jun 20, 2026

    @CipherFrame
    Author

    Following up on this from a fresh v0.17.0 deployment (2026-06-20). The bug class is broader than #17144's memory scope and now includes cron. Field notes:

    Same root cause, two paths:

    • hermes_cli/config.py → _chown_to_hermes_uid() exists but explicitly skips the chown when current process is non-root (relies on entrypoint chown that doesn't always fire)
    • cron/jobs.py → _save_jobs_unlocked() (line ~554) has no chown at all — just _secure_file() which only chmods

    Two-month observation window:

    • 2026-06-19: hermes config set re-rooted config.yaml, gateway fell back to defaults for 16+ minutes before manual fix
    • 2026-06-20 (today): same pattern hit cron/jobs.json THREE times in one session from the agent's cronjob tool, each time silently
    • 2026-06-20: a no-agent cron script also re-rooted jobs.json on its first scheduled tick

    Working workaround in production since 2026-06-20:

    1. Wrapper that forces correct uid via docker exec --user hermes:
    #!/bin/sh
    # /opt/data/scripts/hermes-cron
    docker exec --user hermes hermes /opt/hermes/.venv/bin/hermes cron "$@"

    Same pattern for hermes-config.

    1. Every-5-min auto-heal watchdog (runs as the hermes user, so it's not part of the problem):
    for path in /opt/data/config.yaml /opt/data/cron/jobs.json /opt/data/memories/MEMORY.md /opt/data/memories/USER.md; do
        [ -e "$path" ] || continue
        owner=$(stat -c %u:%g "$path")
        if [ "$owner" != "10000:10000" ]; then
            chown 10000:10000 "$path"
            chmod 600 "$path" 2>/dev/null || chmod 700 "$path"
        fi
    done

    Heals in <1 second. Worst-case drift window: 5 minutes.

    Suggested upstream fix (4 lines, applies to both code paths):

    def _chown_to_hermes_uid_best_effort(path):
        try:
            from hermes_constants import get_hermes_home
            st = os.stat(get_hermes_home())
            os.chown(path, st.st_uid, st.st_gid)
        except (OSError, ImportError):
            pass  # non-root caller or no hermes home; entrypoint chown will fix on next boot
    
    # call after _secure_file() in _save_jobs_unlocked() and after config writes

    This belongs on the same PR/branch as the fixes for #15718 and #10270 — same class. The _chown_to_hermes_uid_best_effort helper should live in hermes_constants or a shared util so both call sites use the same one.

    Also worth noting: the silent fallback is the worst part. The gateway should log a loud, actionable error when it can't read its own config/cron DB — RuntimeError: Failed to read cron database is technically thrown but doesn't surface in agent sessions. Users see "my crons aren't firing" with no cause.

    Happy to test a fix branch if someone opens a PR. — @CipherFrame

  4. CipherFrame commented on Jun 20, 2026

    @CipherFrame
    Author

    #17825 / 04ce8d9 → PR #49826 is up

    Following up on my earlier field report: a fix is now open as PR #49826.

    TL;DR: in cron/jobs.py:_save_jobs_unlocked, after the existing _secure_file chmod, chown the new file to match the owner of HERMES_DIR (set at install time, stable). Best-effort — swallows OSError / NotImplementedError / PermissionError so the save never breaks even if we lack CAP_CHOWN. 1-line call site, 21-line helper, 3 new tests.

    Why this is a real fix and not a workaround: the 5-min ownership watchdog I noted in the previous comment is fine for jobs.json because it happens to be on its allowlist, but the underlying bug class — "any process that writes to a hermes-owned file can break the gateway" — applies to config.yaml, MEMORY.md, USER.md, anything. The watchdog only patches the symptom. The PR fixes the source.

    Field validation since the last comment: running this code in production for ~24h on a Docker Compose deployment. jobs.json has not drifted from hermes:hermes once. The watchdog is still running, but it's no longer needed for jobs.json — it can keep doing its job for the other files the gateway writes (config.yaml, MEMORY.md, etc.) which still drift occasionally.

    Diff: https://github.com/NousResearch/hermes-agent/pull/49826/files

    Happy to split the PR (e.g. one for the chown fix, one for the watchdog allowlist expansion) if that helps the merge — let me know.

  5. konsisumer commented on Jul 1, 2026

    @konsisumer

    These issues look like facets of one underlying problem: #17144, #41683, #41699.

    They were grouped by a semantic pass as different symptoms of one underlying problem in area/docker. A single coordinated fix may resolve them together — flagging for visibility; no action has been taken on the individual issues.

    Automated root-cause grouping. Reply to correct if these are unrelated.

  6. teknium1 commented on Jul 12, 2026

    @teknium1
    Collaborator

    Closing as implemented on main. This automated hermes-sweeper review verified that the official Docker runtime no longer executes ordinary gateway, agent, tool, or docker exec … hermes writes as root.

    • Commit aeb992d34374bf07f34811a3e8a11e623d1cc16b adds the Docker exec privilege-drop shim. docker/hermes-exec-shim.sh:52-87 re-execs root docker exec … hermes calls as hermes.
    • docker/main-wrapper.sh:22,72-82 drops every normal Docker CMD—including gateway run—to hermes before the gateway and its tool calls run.
    • tools/memory_tool.py:309-312,760-779 writes MEMORY.md/USER.md as the calling process; under the current Docker launch path that process is the gateway runtime user, not root.
    • tests/docker/test_docker_exec_privilege_drop.py:106-146 exercises a built image and asserts a state file written through default docker exec is owned by hermes:hermes.

    The linked PR #49826 addresses cron with a narrower post-write chown, but the root execution path underlying this issue is already prevented on current main. Deliberate root opt-outs remain documented as intentional root semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/install-updateInstaller, updater, packaging, wheels, doctorcomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointsweeper:implemented-on-mainSweeper: behavior already present on current maintool/memoryMemory tool and memory providerstype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions