Skip to content

sudo openclaw update can create mixed ownership, then doctor overwrites config after EACCES/read failure #78493

Closed

Description

@scarlettdetekelala

Summary

On macOS / LaunchAgent, running sudo openclaw update against a user-local install upgraded OpenClaw successfully, but it also left OpenClaw state/config/plugin files with mixed root/user ownership. A later normal-user openclaw doctor hit EACCES reading ~/.openclaw/openclaw.json, continued with best-effort config, and eventually overwrote the real config with a 330-byte skeletal file.

The command detected a dangerous write anomaly:

size-drop-vs-last-good:14992->330, gateway-mode-missing-vs-last-good

but still wrote the bad config. The gateway then refused to start because gateway.mode was missing, which matches current docs saying an existing config missing gateway.mode=local should be treated as broken/clobbered.

Environment

  • OS: macOS, LaunchAgent gateway
  • OpenClaw before update: 2026.5.3-1
  • OpenClaw after update: 2026.5.5 (b1abf9d)
  • Gateway port: 18789
  • User UID/GID: 501:20
  • Install root: ~/.local/lib/node_modules/openclaw
  • State/config dir: ~/.openclaw

Reproduction / observed sequence

  1. Run:

    sudo openclaw update
  2. Update reports success:

    Update Result: OK
    Before: 2026.5.3-1
    After: 2026.5.5
    
  3. During the sudo-run update, plugin warnings appear because root sees user-owned plugin candidates as suspicious:

    blocked plugin candidate: suspicious ownership
    ... uid=501, expected uid=0 or root
    
  4. Plugin update/config write then proceeds under sudo/root anyway.

  5. Gateway refresh fails with the documented "wrong user / sudo" class of error:

    updated install refresh failed (.../openclaw/dist/index.js):
    This usually means you are running from SSH/headless context or as the wrong user (including sudo).
    Fix: sign in to the macOS desktop as the target user and rerun
    `openclaw gateway install --force`.
    
  6. Running as the normal user:

    openclaw doctor

    repeatedly reports:

    EACCES: permission denied, open '~/.openclaw/openclaw.json'
    Config file is not readable by the current process.
    
  7. Doctor continues with best-effort config and later writes:

    Config overwrite: ~/.openclaw/openclaw.json
    Config write anomaly: ... missing-meta-before-write
    Config observe anomaly: ... size-drop-vs-last-good:14992->330, gateway-mode-missing-vs-last-good
    Updated ~/.openclaw/openclaw.json
    

Local evidence after the failure

Current config is only 330 bytes and contains only:

{
  "channels": { "telegram": { "enabled": true } },
  "wizard": { "...": "..." },
  "meta": { "...": "..." }
}

Recovered backup shape is intact:

  • ~/.openclaw/openclaw.json.last-good: 14986 bytes
  • includes gateway.mode = "local"
  • includes gateway.port = 18789
  • includes gateway.auth.mode = "token"
  • includes agents.list with 5 entries
  • includes plugins.entries

Root-owned / mixed ownership files produced or left around include:

~/.openclaw/plugins/installs.json                         root:staff
~/.openclaw/plugin-skills                                 root:staff
~/.openclaw/npm/node_modules/@openclaw/brave-plugin       root:staff
~/.openclaw/npm/node_modules/@openclaw/codex              root:staff
~/.local/lib/node_modules/openclaw                        root:staff
~/.local/bin/openclaw                                     root:staff symlink

openclaw gateway status --json --no-probe reports the service is installed/running but last start failed:

Gateway start blocked: existing config is missing gateway.mode.
Treat this as suspicious or clobbered config.

Expected behavior

OpenClaw should fail closed when the config cannot be read due to EACCES, especially if the command is about to write ~/.openclaw/openclaw.json.

It should not serialize a best-effort/empty/default config over a previously valid config when:

  • config read failed,
  • openclaw.json.last-good exists,
  • the proposed write is a massive size drop,
  • gateway.mode is missing compared to last-good,
  • or the process effective UID differs from the owner of the user state directory.

Suggested fix

  1. In config-writing paths, treat EACCES / unreadable config as a hard blocker for full-file overwrites.
  2. If loader is in best-effort config mode, allow read-only diagnostics but block writes unless an explicit recovery command is used.
  3. Upgrade the existing "Config write anomaly" detector from warning-only to fail-closed for severe cases like:
    • size-drop-vs-last-good
    • gateway-mode-missing-vs-last-good
    • missing meta before write after failed read
  4. Write the rejected candidate to openclaw.json.rejected.<timestamp> instead of replacing the live config.
  5. Add a guard to openclaw update when run with sudo against a user-owned ~/.openclaw: either refuse state/config/plugin mutations or re-exec the state-mutating phase as the target user.
  6. Add regression tests for:
    • unreadable openclaw.json + doctor must not overwrite config
    • last-good exists + proposed config drops gateway.mode must be rejected
    • sudo/root update against user-owned state must not leave root-owned state files
    • plugin update under wrong UID must not create mixed ownership in ~/.openclaw/npm, plugins, or plugin-skills

Workaround used locally

Restore ~/.openclaw/openclaw.json.last-good, fix ownership back to UID 501, then run openclaw gateway install --force as the logged-in macOS user, not via sudo.

Documentation cross-check

Activity

  1. clawsweeper commented on May 6, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 30, 2026, 2:01 PM ET / 18:01 UTC.

    Summary
    The unreadable-config overwrite is guarded on current main, but update and finalization still do not admit filesystem ownership before mutating user-derived state. The remaining boundary needs a maintainer policy decision for intentional system-managed installs.

    Reproducibility: yes. —current source shows update and finalization admit writes without comparing the effective Unix account with the owner of the user-derived state tree; no runtime command was run in this read-only review.

    Root-cause cluster
    Relationship: canonical
    Canonical: #78493
    Summary: This is the canonical narrow report for privileged mutation of user-derived state; related work fixes only config overwrite or proposes a broader updater redesign.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Maintainer decision needed

    Question Recommendation
    Should privileged update, Doctor, and plugin commands fail before mutating a user-owned state tree, or may a documented system-service identity mutate it? Fail closed on owner mismatch: Reject state-mutating work when the effective account differs from an existing user-state owner and direct the operator to run that phase as the owning account.

    Why: The current source lacks Unix ownership admission, but a generic check could disrupt intentional system-managed deployments and automatic ownership changes would themselves mutate user state.

    Next step
    A maintainer must define the supported ownership contract before a repair can safely reject or permit privileged mutations.

    Review details

    Best possible solution:

    Establish one explicit state-ownership contract: fail before mutation on account mismatch, except for a narrowly verified system-service contract.

    Do we have a high-confidence way to reproduce the issue?

    Yes—current source shows update and finalization admit writes without comparing the effective Unix account with the owner of the user-derived state tree; no runtime command was run in this read-only review.

    Is this the best way to solve the issue?

    Unclear—the config-overwrite half is guarded, but the remaining privilege boundary requires maintainer policy for intentional system-managed installs before selecting the canonical enforcement path.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A blanket effective-UID check could break intentional system-managed installations unless their service identity and state ownership are explicitly defined.

    Codex review notes: model internal, reasoning high; reviewed against 242a63b17f1b.

    Label changes

    Label justifications:

    • P1: A wrong-account update or repair can leave an existing installation unable to start or recover.
    • impact:security: The remaining defect is a missing privilege and filesystem-ownership boundary before state mutation.
    • impact:crash-loop: Incorrectly owned or overwritten state can prevent a supervised Gateway from recovering normally.
    Evidence reviewed

    Acceptance criteria:

    • Create a non-root user state tree, invoke each update, Doctor, and plugin mutation entrypoint under a different effective account, and verify no state changes occur.
    • Exercise the documented system-service contract, if accepted, and verify only its authoritative owner may mutate state.
    • Verify the unreadable-config path preserves the original configuration and writes only a rejected candidate artifact.

    What I checked:

    • Current config-write guard: A present but unreadable config records readError, which becomes a blocking write reason even when size-drop writes are allowed; rejected payloads are written separately instead of replacing the config. (src/config/io.snapshot.ts:388, 61edeb8a6fe9)
    • Regression coverage for the fixed half: The EACCES test covers both ordinary writes and the update-Doctor size-drop path, asserting refusal rather than overwrite. (src/config/io.eacces.test.ts:143, 61edeb8a6fe9)
    • Remaining update entrypoints: Update admission and finalization call the state-write guard, but pass only the SQLite path and do not supply or establish a Unix account/tree-owner contract. (src/cli/update-cli/update-command.ts:171, 61edeb8a6fe9)
    • Guard scope: The current state-write guard resolves the database and checks external-supervisor ownership metadata; it has no filesystem UID/GID comparison. (src/state/openclaw-state-ownership.ts:272, 61edeb8a6fe9)
    • User-derived plugin roots: Plugin install roots are derived from the active config/state home, so an elevated process can target the caller-derived plugin tree without a separate Unix ownership admission shown here. (src/plugins/install-root-context.ts:23, 61edeb8a6fe9)
    • Current-main and release check: The checkout is clean; origin/main is 242a63b, and the reviewed source paths have no diff from the local checkout. No reachable release tag was found for that fetched main SHA. (242a63b17f1b)

    Likely related people:

    • yetval: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. haumanto commented on May 8, 2026

    @haumanto

    Same root pattern reproduces on Linux/systemd via sudo HOME=/home/openclaw openclaw plugins doctor (rather than sudo openclaw update).

    Reproduction (Ubuntu 24.04, systemd, v4.27 → v4.29 upgrade, 2026-05-01):

    1. sudo npm install -g openclaw@<new> ✓
    2. sudo HOME=/home/openclaw openclaw plugins doctor (recommended preempt for prior EACCES-on-restart issues like [Bug]: sudo --preserve-env=HOME openclaw doctor --fix leaves root-owned files in ~/.npm/_cacache, breaking every subsequent non-root plugin runtime-deps install (EACCES) #71255).
    3. sudo systemctl restart openclaw.
    4. Gateway boots → starts pnpm install of new ~/.openclaw/plugin-runtime-deps/openclaw-<new>-*/ → fails with ERR_PNPM_EACCES: mkdir '…/node_modules/<pkg>/node_modules'.
    5. Hits ~8min plugin-load timeout, exits code=exited, status=1/FAILURE. systemd auto-restarts → fresh pnpm install → same EACCES → crash-loop.

    Cause: step 2 (running as root with HOME=/home/openclaw) writes some node_modules subdirs (in our case pdfjs-dist was the culprit) under root ownership. The gateway runs as openclaw user and can't mkdir under those root-owned subdirs.

    Recovery (worked):

    sudo systemctl stop openclaw
    sudo chown -R openclaw:openclaw ~/.openclaw/plugin-runtime-deps/openclaw-<new>-*/
    cd ~/.openclaw/plugin-runtime-deps/openclaw-<new>-*/
    pnpm install --prod --ignore-scripts --ignore-workspace \
      --config.frozen-lockfile=false --config.minimum-release-age=0 \
      --config.store-dir=.openclaw-pnpm-store \
      --config.node-linker=hoisted --config.virtual-store-dir=.pnpm
    sudo systemctl start openclaw

    This complements the macOS/LaunchAgent reproduction in this issue. Same family: any sudo-driven OpenClaw command that touches node_modules or config files under the user's HOME leaves root-owned artifacts that bite the next non-root operation. The most user-friendly fix is probably to chown back to the invoking user automatically when sudo is detected, or refuse to run as root with HOME=user (warn + abort) since the user-mode equivalent (no sudo) also works.

    Detection cue: sudo systemctl status openclaw shows the restart counter climbing and pnpm install running on every boot. The lock dir at ~/.openclaw/plugin-runtime-deps/openclaw-*/.openclaw-runtime-deps.lock/ will have owner.json from the dying gateway PID.

    Environment: OpenClaw 2026.4.29 → 2026.5.7 (still applicable), Ubuntu 24.04, Node v22.22.2.

  3. openclaw-barnacle commented on Jun 1, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  4. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:data-lossCan lose, corrupt, or silently drop user/session/config data.
    impact:crash-loopCrash, hang, restart loop, or process-level availability failure.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    on Jun 14, 2026
  5. haumanto commented on Jun 21, 2026

    @haumanto

    Still reproducible as of 2026.6.9 (upgraded today). The risky path — config write proceeding after an unreadable-config (EACCES) fallback — is unchanged; the June 18 review reflects main.

    Mitigation that's reliably avoided it across ~10 upgrades on Linux/systemd: never sudo openclaw update or sudo … plugins doctor (the root-owned writes poison the next boot). Instead: sudo npm install -g openclaw@<ver> only → chmod 700 ~/.openclaw && chmod 600 ~/.openclaw/openclaw.json (npm resets the dir to 755) → a normal non-sudo systemctl restart.

    The real fix still seems worth it: a write-guard that refuses to persist config after a read returned EACCES (rather than overwriting with defaults) would kill the data-loss class entirely, independent of how the ownership got mixed.

  6. haumanto commented on Jun 24, 2026

    @haumanto

    Still reproducible on 2026.6.10 (upgraded today) — the risky path (config write proceeding after an unreadable-config / EACCES fallback) is unchanged across 6.8 → 6.9 → 6.10. Flagging to keep this off the stale timer: it's a P1 data-loss / crash-loop class issue with a clear fix shape — refuse to persist config after a read returns EACCES, rather than overwriting with defaults. Happy to retest against any candidate fix.

  7. 36 remaining items

  8. added
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    and removed
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    on Aug 16, 2026
  9. steipete commented on Oct 24, 2026

    @steipete
    Contributor

    Thanks for filing this. We're closing older issues that no longer look actionable on current main.

    The harmful part, Doctor overwriting config after an EACCES read failure, is fixed: config writes now fail closed when openclaw.json could not be read (#96469). Running update with sudo against a user-local install is unsupported. Please open a fresh issue if a supported update path still produces mixed ownership.

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

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions