Repository navigation
Description
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
-
Run:
sudo openclaw update
-
Update reports success:
Update Result: OK Before: 2026.5.3-1 After: 2026.5.5 -
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 -
Plugin update/config write then proceeds under sudo/root anyway.
-
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`. -
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. -
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:14986bytes- includes
gateway.mode = "local" - includes
gateway.port = 18789 - includes
gateway.auth.mode = "token" - includes
agents.listwith 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-goodexists,- the proposed write is a massive size drop,
gateway.modeis missing compared to last-good,- or the process effective UID differs from the owner of the user state directory.
Suggested fix
- In config-writing paths, treat
EACCES/ unreadable config as a hard blocker for full-file overwrites. - If loader is in best-effort config mode, allow read-only diagnostics but block writes unless an explicit recovery command is used.
- Upgrade the existing "Config write anomaly" detector from warning-only to fail-closed for severe cases like:
size-drop-vs-last-goodgateway-mode-missing-vs-last-good- missing
metabefore write after failed read
- Write the rejected candidate to
openclaw.json.rejected.<timestamp>instead of replacing the live config. - Add a guard to
openclaw updatewhen run withsudoagainst a user-owned~/.openclaw: either refuse state/config/plugin mutations or re-exec the state-mutating phase as the target user. - Add regression tests for:
- unreadable
openclaw.json+doctormust not overwrite config last-goodexists + proposed config dropsgateway.modemust 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, orplugin-skills
- unreadable
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
- Gateway CLI: https://docs.openclaw.ai/cli/gateway
- Gateway Runbook: https://docs.openclaw.ai/gateway/index
- Doctor: https://docs.openclaw.ai/gateway/doctor
- Plugin Internals: https://docs.openclaw.ai/plugins/architecture
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon May 6, 2026
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:
canonicalCanonical: #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:
fixed_by_candidate: fix(config): fail closed when config is unreadable before a full-file write #96469 - Supplied context identifies protection for the unreadable-config overwrite half, not Unix ownership admission.partial_overlap: openclaw update silently restores stale last-known-good config via post-update doctor, discarding intentional changes #90551 - It concerns stale last-known-good config rewrites rather than effective-account mismatch.partial_overlap: [Feature]: Makeopenclaw updateone transaction: prove candidate before activation, verified state checkpoint, whole-product rollback, no crash-loop on migration warnings #124396 - It proposes a broad transactional updater rather than this narrow ownership boundary.Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Maintainer decision needed
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:
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:
What I checked:
src/config/io.snapshot.ts:388, 61edeb8a6fe9)src/config/io.eacces.test.ts:143, 61edeb8a6fe9)src/cli/update-cli/update-command.ts:171, 61edeb8a6fe9)src/state/openclaw-state-ownership.ts:272, 61edeb8a6fe9)src/plugins/install-root-context.ts:23, 61edeb8a6fe9)Likely related people:
How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.haumanto commentedon May 8, 2026
Same root pattern reproduces on Linux/systemd via
sudo HOME=/home/openclaw openclaw plugins doctor(rather thansudo openclaw update).Reproduction (Ubuntu 24.04, systemd, v4.27 → v4.29 upgrade, 2026-05-01):
sudo npm install -g openclaw@<new>✓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).sudo systemctl restart openclaw.~/.openclaw/plugin-runtime-deps/openclaw-<new>-*/→ fails withERR_PNPM_EACCES: mkdir '…/node_modules/<pkg>/node_modules'.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 casepdfjs-distwas the culprit) under root ownership. The gateway runs asopenclawuser and can'tmkdirunder those root-owned subdirs.Recovery (worked):
This complements the macOS/LaunchAgent reproduction in this issue. Same family: any sudo-driven OpenClaw command that touches
node_modulesor 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 withHOME=user(warn + abort) since the user-mode equivalent (no sudo) also works.Detection cue:
sudo systemctl status openclawshows 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 haveowner.jsonfrom the dying gateway PID.Environment: OpenClaw 2026.4.29 → 2026.5.7 (still applicable), Ubuntu 24.04, Node v22.22.2.
openclaw-barnacle commentedon Jun 1, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
haumanto commentedon Jun 21, 2026
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 updateorsudo … 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-sudosystemctl 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.
haumanto commentedon Jun 24, 2026
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.
36 remaining items
steipete commentedon Oct 24, 2026
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.