Skip to content

config: stop automatic writes and guard Nix mutators - #78047

Merged
joshp123 merged 2 commits into
mainfrom
jp/nix-mode-no-config-mutation
May 6, 2026
Merged

joshp123 merged 2 commits into
mainfrom
jp/nix-mode-no-config-mutation

Conversation

@joshp123

@joshp123 joshp123 commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Human written summary:

The intent of this change is, as written by a human:

It should just be no automatic stuff. The config set stuff should be explicitly disabled in Nix mode, in my opinion, because the whole point is it's immutable.

The policy boundary: yes, explicit tools can write config, but not in Nix mode.

The rest of this PR was written by GPT-5-Codex, running in the Codex desktop harness. Full environment + prompt history appear at the end.

Changes

  • Stop automatic config mutation during normal runtime/startup paths: plugin auto-enable, generated gateway auth tokens, Control UI allowed-origin seeding, generated owner-display secrets, and read-time plugins.installs compatibility migration are runtime-only.
  • Add a central Nix-mode config write guard for replaceConfigFile, mutateConfigFile, and direct config writes.
  • Refuse mutating operator flows early in Nix mode before package/install side effects: plugin install/update/uninstall/enable/disable, chat plugin write commands, mutating openclaw update, onboarding plugin installs, and doctor repair/token-generation.
  • Make Nix-mode refusal errors agent-first: they explain immutable config, name OPENCLAW_NIX_MODE=1, point to first-party nix-openclaw, and note that other Nix packages may also manage config.
  • Update docs/changelog so documented mutable workflows remain valid for normal installs while Nix users are directed to edit their Nix source instead.

Tests

  • env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm test -- src/auto-reply/reply/commands-plugins.install.test.ts src/auto-reply/reply/commands-plugins.test.ts src/commands/onboarding-plugin-install.test.ts src/commands/channel-setup/plugin-install.test.ts src/cli/update-cli.test.ts src/cli/plugins-cli.install.test.ts src/cli/plugins-cli.update.test.ts src/cli/plugins-cli.uninstall.test.ts src/cli/plugins-cli.policy.test.ts src/commands/doctor.runs-legacy-state-migrations-yes-mode-without.e2e.test.ts src/gateway/startup-auth.test.ts src/gateway/startup-control-ui-origins.test.ts src/gateway/server-startup-config.recovery.test.ts src/config/mutate.test.ts src/config/io.write-config.test.ts src/config/io.owner-display-secret.test.ts passed: 6 Vitest shards, 349 tests.
  • env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm check passed.
  • env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm check:docs passed.
  • env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm build passed.
  • env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm format:check failed on 10 unchanged files; the same files fail on clean current origin/main, so this is unrelated to this PR.
  • env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm config:docs:check failed with the existing docs/.generated/config-baseline.sha256 mismatch; the same failure reproduces on clean current origin/main, and this PR does not change the config schema baseline.

Risks

  • CODEOWNERS/security review is required for touched auth/secret paths: src/gateway/startup-auth.ts, src/gateway/startup-auth.test.ts, src/config/io.owner-display-secret.ts, and src/config/io.owner-display-secret.test.ts.
  • Normal installs no longer get startup-generated config persisted automatically. That is intentional: durable config changes now require explicit tools.
  • Nix-mode plugin lifecycle/update/repair refusal may surprise users who previously ran those commands manually; docs now point agents/users to edit the Nix-managed source instead.

Follow-ups

  • None for this PR. After merge, nix-openclaw can drop any downstream workaround once it pins an OpenClaw release containing this behavior.

Root Cause

  • Startup/read paths had grown implicit config writers: plugin auto-enable, generated gateway auth tokens, Control UI origin seeding, owner-display secret generation, and read-time shipped-plugin install migration.
  • Core write helpers did not enforce OPENCLAW_NIX_MODE=1, so even explicit mutators could rewrite a declarative config file.
  • Some plugin/update/onboarding flows could perform package-manager or install side effects before reaching the config writer, so central refusal alone was not enough for Nix mode.

Real behavior proof

  • Behavior or issue addressed: OpenClaw could mutate openclaw.json automatically during startup/read paths, and could mutate declarative config even when OPENCLAW_NIX_MODE=1 said Nix owned config.
  • Real environment tested: local OpenClaw CLI and gateway code from this branch on macOS Darwin, using temp OPENCLAW_CONFIG_PATH files, OPENCLAW_NIX_MODE=1, Node 22, and the repo's Nix-provided pnpm toolchain.
  • Exact steps or command run after this patch: ran temp-config CLI/gateway smoke scripts against the built branch with OPENCLAW_CONFIG_PATH set to disposable files; commands exercised openclaw config get, openclaw config set, openclaw plugins enable, openclaw update, and gateway startup auth generation.
  • Evidence after fix: copied terminal output from the live smoke run:
nix_config_get: status=0 changed=false
nix_config_set: status=1 changed=false contains_OPENCLAW_NIX_MODE=1 true contains_nix_docs=true
nix_plugins_enable: status=1 changed=false contains_nix_docs=true
nix_update: status=1 changed=false contains_nix_docs=true
normal_config_set: status=0 changed=true
gateway_missing_token_startup: generated_runtime_token=true changed=false log="Generated a runtime token for this startup without changing config"
  • Observed result after fix: read-only Nix commands still work; Nix mutators fail before changing the config hash; normal non-Nix config writes still work; gateway startup no longer persists generated auth into config.
  • What was not tested: a full Home Manager rebuild on a Linux NixOS host was not rerun in this PR worktree. The repo-level behavior was tested through OPENCLAW_NIX_MODE=1, and nix-openclaw was inspected to confirm first-party Nix sets that mode and owns rendered config.
  • Before evidence: on clean origin/main, a temp-config repro with OPENCLAW_NIX_MODE=1 and replaceConfigFile changed the config hash and wrote metadata; startup auth with { "gateway": { "mode": "local", "auth": { "mode": "token" } } } persisted a generated token and meta.lastTouched* when startup requested persistence.

Docs Boundary Review

  • Existing docs for openclaw config set, setup, plugin lifecycle commands, update, and doctor repair describe mutable workflows for normal installs. This PR keeps those workflows available outside Nix mode.
  • Nix docs now explicitly say first-party nix-openclaw and other Nix packages can set OPENCLAW_NIX_MODE=1, config is immutable, startup-derived defaults are runtime-only, and mutating commands are refused.
  • Config/plugin/setup/update/doctor docs now call out the Nix exception so documented non-Nix workflows are not silently broken.
  • Startup/legacy migration docs now distinguish runtime compatibility from doctor-driven persisted repair; startup no longer rewrites config.
  • Config include docs still describe explicit write-through behavior for normal installs; in Nix mode the new guard refuses writes before include write-through.

Compatibility

  • Backward compatible for normal mutable installs: explicit config and doctor repair commands still write config outside Nix mode.
  • Behavior change for automatic startup/read paths: they no longer persist generated or compatibility-derived config for anyone.
  • Behavior change for Nix mode: mutating config tools now fail fast with agent-first documentation pointers.

Prompt History

Environment

Harness: Codex desktop app
Model: GPT-5 Codex
Thinking level: not exposed by harness
Terminal: zsh
System: macOS Darwin, local worktree at /tmp/openclaw-nix-mode-pr

Prompts

ISO-8601 Prompt
2026-05-05T21:44:00+02:00 Okay, I think your diagnosis on the patch is right, but we should indeed fix it in upstream OpenClaw if that's indeed the correct diagnosis. Basically, the name of the game here is: in Nix mode, we don't mutate config. It's that simple. In Nix mode, Nix owns config, so if OpenClaw is mutating config, then yeah, we shouldn't mutate it, but then the question is: is what they're doing really the right way of doing things, or can we have a better suggestion? I think it's fine to open a draft PR against OpenClaw, but don't merge it yourself, because there's a whole procedure and we need to follow the procedure. Opening a PR as draft is fine, and adding a comment saying, "Hey, this breaks on Nix packaging shit because we're mutating config, whereas with Nix mode on, config should be immutable." That's good.
2026-05-06T08:xx:00+02:00 Assess this pull request. This is something we found in our Nix OpenClaw work, which I guess I'll give you a link to the session below. ... The main goal is that config should not be mutated by open floor except using the doctor plugin, which is not supported in Nix mode anyway. We want to take our original fix and broaden it from just Nix mode to general for everybody.
2026-05-06T08:xx:00+02:00 I agree with your recommendation. It should just be no automatic stuff. The config set stuff should be explicitly disabled in Nix mode, in my opinion, because the whole point is it's immutable. Setup and onboarding, plugin installing, enabling. Again, in Nix mode, these are not desired paths because that's what you use Nix mode for. ... We should have: ... ensure that none of the OpenClaw behaviour mutates the config files automatically, except the operator commands. ... gating the operator commands behind: if the gateway is running in Nix mode, then just tell them to fuck off.
2026-05-06T08:xx:00+02:00 I think you're mostly correct. The error messages should explicitly point to the agent first documentation so that the agents will understand that either they're using nix-openclaw, which is the official distribution, or their users might have configured a different one. In this installation, the config should be immutable. ... red-green-red or red-green-green-red-green ... First test this or reproduce it and make sure it's fucked on master. Add tests. Show that the test breaks. Fix the tests.
2026-05-06T08:xx:00+02:00 /goal drive this feature to "PR is ready to merge" state, follow professional software development lifecycle the whole way. Ensure you do everything that we discussed in this chat ... checking for regressions ... ensuring that you've tested everything so it's bulletproof
2026-05-06T08:xx:00+02:00 What I meant is that if the documentation says you can edit stuff, we should be aware of that so we don't break existing documented workflows.
2026-05-06T09:xx:00+02:00 Make sure to undo any of the Discord-related stuff if you did anything based on my accidental messages.
2026-05-06T10:xx:00+02:00 Then, exactly as you mentioned before, let's go back to the pull request 78047 and continue against our full plan

Prompt history note: this thread was compacted during implementation. The PR body preserves the earlier draft prompts already present and the visible prompts from the active compacted thread; no Discord/discrawl work was performed from the accidental messages.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels May 5, 2026
@joshp123

joshp123 commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

note to self/codex from discord discussions: we shouldn't mutate ANY config (except in doctor command), regardless of nix mode on/off.

@clawsweeper

clawsweeper Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR makes startup-derived config state runtime-only, adds a Nix-mode config write guard, blocks mutating CLI/chat/onboarding/doctor flows in Nix mode, and updates docs and changelog.

Reproducibility: yes. Current main source shows startup/plugin and generated-auth config writes despite the documented Nix self-mutation boundary, and the PR body includes before/after temp-config smoke output for the changed behavior.

Real behavior proof
Sufficient (terminal): The PR body includes after-fix terminal output from real temp-config CLI and gateway smoke runs showing the changed runtime behavior and unchanged config hashes.

Next step before merge
No automated repair remains; maintainers/CODEOWNERS should decide whether to merge the broad config and auth policy change.

Security
Cleared: The diff touches auth and secret-adjacent startup paths but adds no dependencies, workflows, secret exposure, or broader code-execution surface; it removes automatic secret persistence.

Review details

Best possible solution:

Land this branch after owner approval, keeping startup-derived state runtime-only and preserving legacy install records for runtime compatibility.

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

Yes. Current main source shows startup/plugin and generated-auth config writes despite the documented Nix self-mutation boundary, and the PR body includes before/after temp-config smoke output for the changed behavior.

Is this the best way to solve the issue?

Yes. The runtime-only startup path plus a central Nix write guard and early mutator checks is the narrow maintainable direction, and the current head preserves legacy install records without reintroducing passive writes.

What I checked:

  • Current main Nix contract: Current main documents OPENCLAW_NIX_MODE=1 as disabling auto-install/self-mutation flows, which supports treating Nix-managed config as externally owned. Public docs: docs/install/nix.md. (docs/install/nix.md:67, 28e27ca5d16a)
  • Current main startup auto-enable writes config: Current main persists startup plugin auto-enable changes through replaceConfigFile, matching one of the automatic mutation paths the PR removes. (src/gateway/server-startup-config.ts:102, 28e27ca5d16a)
  • Current main generated auth persists config: Current main writes generated gateway auth tokens with replaceConfigFile when startup persistence is requested. (src/gateway/startup-auth.ts:220, 28e27ca5d16a)
  • Legacy install-record compatibility repaired: At the current PR head, passive read migration returns the original config for runtime/source snapshots and a stripped validation config, so valid legacy install records remain available without persistence. (src/config/io.ts:1335, e34ccca16608)
  • Runtime snapshots retain legacy install records: The PR explicitly reattaches legacy plugins.installs records to runtime/source snapshots after validation, preserving plugin loader compatibility. (src/config/io.ts:1390, e34ccca16608)
  • Regression coverage for passive and explicit migration: The updated tests assert passive loads keep legacy install records without writing config or plugin index, while explicit writes migrate records into plugins/installs.json and remove the config key. (src/config/io.write-config.test.ts:257, e34ccca16608)

Likely related people:

  • @steipete: Recent history connects this handle to config IO, recovery, filesystem safety, plugin install boundaries, and gateway auth hardening touched by the PR. (role: recent maintainer; confidence: high; commits: 538605ff44d2, 0ee52e940547, 630f2bcabe22; files: src/config/io.ts, src/config/mutate.ts, src/gateway/startup-auth.ts)
  • @shakkernerd: Recent merged work introduced the shipped plugins.installs migration and maintained plugin metadata reuse and startup auto-enable paths affected by the compatibility change. (role: adjacent owner; confidence: high; commits: 194c26bcd2f1, d62cc59388b5, 5a72378b2797; files: src/config/plugin-install-config-migration.ts, src/config/io.ts, src/gateway/server-startup-config.ts)
  • @vincentkoc: Recent plugin lifecycle/index work and gateway startup cleanup overlap the install-record and startup surfaces changed here. (role: adjacent maintainer; confidence: medium; commits: 71e361af8ae8, 7fae11b3b1e4, 1497425b8dbb; files: src/plugins/installed-plugin-index-install-records.ts, src/cli/plugins-install-command.ts, src/gateway/startup-auth.ts)

Remaining risk / open question:

  • Broad config/auth behavior changes still need maintainer and CODEOWNERS review before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 28e27ca5d16a.

@joshp123 joshp123 changed the title gateway: keep Nix startup config immutable gateway: keep config immutable (outside of doctor commands) May 6, 2026
@joshp123
joshp123 force-pushed the jp/nix-mode-no-config-mutation branch from 6b4af1d to d76f649 Compare May 6, 2026 09:01
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: slack Channel integration: slack cli CLI command changes commands Command implementations size: XL and removed size: S labels May 6, 2026
@joshp123 joshp123 changed the title gateway: keep config immutable (outside of doctor commands) config: stop automatic writes and guard Nix mutators May 6, 2026
@joshp123
joshp123 marked this pull request as ready for review May 6, 2026 09:06
@joshp123
joshp123 requested a review from a team as a code owner May 6, 2026 09:06
@joshp123
joshp123 force-pushed the jp/nix-mode-no-config-mutation branch from d76f649 to 6701964 Compare May 6, 2026 09:11
@joshp123

joshp123 commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed on the current head (6701964f40):

  • startup-derived plugin enablement, generated gateway auth tokens, Control UI origins, and owner-display secrets are runtime-only instead of persisted config writes
  • Nix mode refuses config writers plus setup/onboarding/update/plugin lifecycle/doctor repair mutators with agent-first docs pointers
  • PR body now includes real behavior proof, and the Real behavior proof check is passing

@clawsweeper

clawsweeper Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@joshp123
joshp123 force-pushed the jp/nix-mode-no-config-mutation branch from 6701964 to 2ebbba4 Compare May 6, 2026 09:27
@joshp123

joshp123 commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final head is 2ebbba450f.

Changes since the last ClawSweeper review:

  • fixed the remaining changelog attribution issue with Thanks @joshp123
  • force-pushed the amended two-commit branch
  • full PR CI is now green, including docs, lint, prod/test types, build artifacts, build smoke, security high, critical quality config/core-auth, additional boundary checks, and the real behavior proof check

Please refresh the durable review comment against the current head.

@clawsweeper

clawsweeper Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@joshp123
joshp123 force-pushed the jp/nix-mode-no-config-mutation branch from 2ebbba4 to e34ccca Compare May 6, 2026 09:57
@joshp123
joshp123 force-pushed the jp/nix-mode-no-config-mutation branch from e34ccca to 05a2c71 Compare May 6, 2026 12:39
@joshp123
joshp123 merged commit d4b4660 into main May 6, 2026
110 checks passed
@joshp123
joshp123 deleted the jp/nix-mode-no-config-mutation branch May 6, 2026 12:43
@joshp123

joshp123 commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Landed via squash merge.

Source head: 05a2c71
Landed commit: d4b4660

Verification before merge:

@100yenadmin

Copy link
Copy Markdown
Contributor

Thanks @joshp123 I'm so tired of OC steamrolling my config and our users. Every patch something comes through and breaks a core configuration or removes something that should be there or adds something that is not compatible with the rest of the config 😮‍💨

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Keep startup-derived plugin enablement, gateway auth tokens, control UI origins, and owner-display secrets runtime-only instead of persisting them into openclaw.json.

Refuse config writers, mutating update/plugin lifecycle commands, and doctor repair/token generation in Nix mode with agent-first nix-openclaw guidance.

Verification:
- pnpm check
- pnpm build
- pnpm test -- src/config/io.write-config.test.ts src/config/mutate.test.ts src/config/io.owner-display-secret.test.ts src/gateway/server-startup-config.recovery.test.ts src/gateway/startup-auth.test.ts src/gateway/startup-control-ui-origins.test.ts src/cli/plugins-cli.install.test.ts src/cli/plugins-cli.policy.test.ts src/cli/plugins-cli.uninstall.test.ts src/cli/plugins-cli.update.test.ts src/cli/update-cli.test.ts src/auto-reply/reply/commands-plugins.install.test.ts src/auto-reply/reply/commands-plugins.test.ts src/commands/onboarding-plugin-install.test.ts src/commands/doctor.runs-legacy-state-migrations-yes-mode-without.e2e.test.ts src/commands/doctor/shared/codex-route-warnings.test.ts src/commands/doctor/repair-sequencing.test.ts src/agents/auth-profile-runtime-contract.test.ts src/auto-reply/reply/agent-runner-execution.test.ts
- GitHub CI green on 05a2c71

Co-authored-by: Codex <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
Keep startup-derived plugin enablement, gateway auth tokens, control UI origins, and owner-display secrets runtime-only instead of persisting them into openclaw.json.

Refuse config writers, mutating update/plugin lifecycle commands, and doctor repair/token generation in Nix mode with agent-first nix-openclaw guidance.

Verification:
- pnpm check
- pnpm build
- pnpm test -- src/config/io.write-config.test.ts src/config/mutate.test.ts src/config/io.owner-display-secret.test.ts src/gateway/server-startup-config.recovery.test.ts src/gateway/startup-auth.test.ts src/gateway/startup-control-ui-origins.test.ts src/cli/plugins-cli.install.test.ts src/cli/plugins-cli.policy.test.ts src/cli/plugins-cli.uninstall.test.ts src/cli/plugins-cli.update.test.ts src/cli/update-cli.test.ts src/auto-reply/reply/commands-plugins.install.test.ts src/auto-reply/reply/commands-plugins.test.ts src/commands/onboarding-plugin-install.test.ts src/commands/doctor.runs-legacy-state-migrations-yes-mode-without.e2e.test.ts src/commands/doctor/shared/codex-route-warnings.test.ts src/commands/doctor/repair-sequencing.test.ts src/agents/auth-profile-runtime-contract.test.ts src/auto-reply/reply/agent-runner-execution.test.ts
- GitHub CI green on 05a2c71

Co-authored-by: Codex <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Keep startup-derived plugin enablement, gateway auth tokens, control UI origins, and owner-display secrets runtime-only instead of persisting them into openclaw.json.

Refuse config writers, mutating update/plugin lifecycle commands, and doctor repair/token generation in Nix mode with agent-first nix-openclaw guidance.

Verification:
- pnpm check
- pnpm build
- pnpm test -- src/config/io.write-config.test.ts src/config/mutate.test.ts src/config/io.owner-display-secret.test.ts src/gateway/server-startup-config.recovery.test.ts src/gateway/startup-auth.test.ts src/gateway/startup-control-ui-origins.test.ts src/cli/plugins-cli.install.test.ts src/cli/plugins-cli.policy.test.ts src/cli/plugins-cli.uninstall.test.ts src/cli/plugins-cli.update.test.ts src/cli/update-cli.test.ts src/auto-reply/reply/commands-plugins.install.test.ts src/auto-reply/reply/commands-plugins.test.ts src/commands/onboarding-plugin-install.test.ts src/commands/doctor.runs-legacy-state-migrations-yes-mode-without.e2e.test.ts src/commands/doctor/shared/codex-route-warnings.test.ts src/commands/doctor/repair-sequencing.test.ts src/agents/auth-profile-runtime-contract.test.ts src/auto-reply/reply/agent-runner-execution.test.ts
- GitHub CI green on 05a2c71

Co-authored-by: Codex <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: slack Channel integration: slack cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR proof: sufficient ClawSweeper judged the real behavior proof convincing. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants