Repository navigation
config: stop automatic writes and guard Nix mutators - #78047
Conversation
|
note to self/codex from discord discussions: we shouldn't mutate ANY config (except in |
|
Codex review: needs maintainer review before merge. Summary 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 Next step before merge Security Review detailsBest 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:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 28e27ca5d16a. |
6b4af1d to
d76f649
Compare
d76f649 to
6701964
Compare
|
@clawsweeper re-review Addressed on the current head (
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
6701964 to
2ebbba4
Compare
|
@clawsweeper re-review Final head is Changes since the last ClawSweeper review:
Please refresh the durable review comment against the current head. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
2ebbba4 to
e34ccca
Compare
Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
e34ccca to
05a2c71
Compare
|
Landed via squash merge. Source head: 05a2c71 Verification before merge:
|
|
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 😮💨 |
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]>
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]>
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]>
Human written summary:
The intent of this change is, as written by a human:
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
plugins.installscompatibility migration are runtime-only.replaceConfigFile,mutateConfigFile, and direct config writes.openclaw update, onboarding plugin installs, and doctor repair/token-generation.OPENCLAW_NIX_MODE=1, point to first-partynix-openclaw, and note that other Nix packages may also manage config.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.tspassed: 6 Vitest shards, 349 tests.env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm checkpassed.env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm check:docspassed.env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm buildpassed.env -u OPENCLAW_GATEWAY_TOKEN -u OPENCLAW_NIX_MODE nix shell nixpkgs#nodejs_22 nixpkgs#pnpm --command pnpm format:checkfailed on 10 unchanged files; the same files fail on clean currentorigin/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:checkfailed with the existingdocs/.generated/config-baseline.sha256mismatch; the same failure reproduces on clean currentorigin/main, and this PR does not change the config schema baseline.Risks
src/gateway/startup-auth.ts,src/gateway/startup-auth.test.ts,src/config/io.owner-display-secret.ts, andsrc/config/io.owner-display-secret.test.ts.Follow-ups
nix-openclawcan drop any downstream workaround once it pins an OpenClaw release containing this behavior.Root Cause
OPENCLAW_NIX_MODE=1, so even explicit mutators could rewrite a declarative config file.Real behavior proof
openclaw.jsonautomatically during startup/read paths, and could mutate declarative config even whenOPENCLAW_NIX_MODE=1said Nix owned config.OPENCLAW_CONFIG_PATHfiles,OPENCLAW_NIX_MODE=1, Node 22, and the repo's Nix-providedpnpmtoolchain.OPENCLAW_CONFIG_PATHset to disposable files; commands exercisedopenclaw config get,openclaw config set,openclaw plugins enable,openclaw update, and gateway startup auth generation.OPENCLAW_NIX_MODE=1, andnix-openclawwas inspected to confirm first-party Nix sets that mode and owns rendered config.origin/main, a temp-config repro withOPENCLAW_NIX_MODE=1andreplaceConfigFilechanged the config hash and wrote metadata; startup auth with{ "gateway": { "mode": "local", "auth": { "mode": "token" } } }persisted a generated token andmeta.lastTouched*when startup requested persistence.Docs Boundary Review
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-openclawand other Nix packages can setOPENCLAW_NIX_MODE=1, config is immutable, startup-derived defaults are runtime-only, and mutating commands are refused.Compatibility
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-prPrompts
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.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.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.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./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 bulletproofWhat 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.Make sure to undo any of the Discord-related stuff if you did anything based on my accidental messages.Then, exactly as you mentioned before, let's go back to the pull request 78047 and continue against our full planPrompt 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.