Skip to content

fix(cli): keep routed config writes identical to offline writes - #184194

Merged
RomneyDa merged 2 commits into
mainfrom
fix/config-route-writer-parity
Oct 26, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
fix/config-route-writer-parity

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Problem

#182951 routes openclaw config set/patch/unset through a running Gateway as one config.patch. The offline writer gets explicitSetPaths and unsetPaths. config.patch cannot carry them, and older Gateways close its schema, so no field can be added. The Gateway's writer therefore works out env-reference restoration and roster/auth/session-store ownership from the merged result alone. I ran the same commands offline and routed against a real in-process Gateway (isolated state and ports, synthetic values) and found three cases where the routed write reports success but saves something else:

Command Offline file Routed file (before)
config set models.providers.p.apiKey '${SYNTH_KEY}' over an escaped "$${SYNTH_KEY}" "${SYNTH_KEY}" (reference activated) unchanged "$${SYNTH_KEY}", yet the CLI printed Updated ... (silent no-op)
batch: add agents.entries.ops + agents.defaults.authInheritance.agentId=ops (roster already explicit) authInheritance.agentId: "ops" authInheritance.agentId: "main" (the writer re-pins the legacy owner)
batch: session.store → new path + agents.defaults.sessionStore.agentId=main owner kept owner silently removed

Related refusals: when adding an agent turns a single-agent config into a multi-agent one, the Gateway rejected the write with .ownership: multi-agent rosters require agents.ownership="explicit". The offline writer stamps that ownership itself. A routed session.store change also dropped the offline Cleared agents.defaults.sessionStore.agentId ... notice.

Nothing became plaintext and no reference was lost. Unrelated sets next to ${VAR} refs, setting a literal ${VAR}, escaping an active ref, and replacing a parent with the resolved value all matched offline byte for byte. Deferred plugin migrations are inert on both paths: ordinary CLI and Gateway reads load no pending facts, so the config-rpc [[]] branch only runs in Doctor/update flows.

Solution

prepareConfigOwnerChange in src/cli/config-cli-owner-patch.ts runs the writer's own prepareConfigWriteTopology twice:

  1. With the command's explicit and unset paths. This is the exact authored result the offline writer would save, including ownership stamping, and it becomes the patch target.
  2. Without them, on that patch merged over the snapshot's resolved source. This is what the Gateway's writer derives.

If the two differ, or the second run throws, the CLI refuses before sending. The message says nothing was sent and suggests splitting the owner change into its own command or stopping the Gateway. The CLI now also prints the session-store owner notice for routed writes. No protocol fields were added. Docs list the new refusal group.

Evidence

  • Offline-vs-routed probe over 20 scenarios (env refs, auth inheritance, session store, deferred migrations), before and after the change. After the change, every case that differed now matches offline or is refused with nothing sent. Single→multi agent add now saves the same ownership, systemAgent and talk.agentId stamping as offline; the only difference is the per-root absolute workspace path.
  • New process test refuses changes the Gateway's writer would save differently in src/cli/config-owner-route.process.test.ts. Without the fix it fails with expected +0 to be 1 (the escaped-literal no-op). With the fix, all 10 tests pass.
  • oxfmt, oxlint on changed files, pnpm tsgo:core, pnpm tsgo:core:test all pass.

Remaining gap: the CLI runs the Gateway-side preparation with its own environment and plugin metadata. A Gateway whose env resolves ${VAR} differently, or an older Gateway whose writer topology differs, is not modeled.

Data model and upgrade compatibility

  • No stored data changes. There is no schema, migration or config shape change. The routed path saves nothing new: it either sends the same config.patch as before or refuses before sending anything. Offline writes and existing config files are unaffected.
  • Upgrade from stable (v2026.10.7): the Gateway side is unchanged, and the request still carries only raw, baseHash and replacePaths, all accepted by v2026.10.7's closed config.patch schema. The new check runs entirely in the CLI. Against an older Gateway, the model uses this CLI's writer logic, so it can only add refusals. It cannot change what a successful routed write sends. That is the existing fix(cli): route config mutations through a running Gateway #182951 request, already proven against an installed v2026.10.7 Gateway.
  • Type assertion: applyMergePatch returns unknown. The modeled merge combines validated configs only to predict the Gateway's result, and the Gateway validates the real merge before writing, so the cast carries a // SAFETY: invariant (the ratchet passes). I avoided running the full config validator here because any normalization it applies could make the equality check refuse valid writes.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: S labels Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR prepares routed config edits through the shared writer and refuses edits whose modeled Gateway result differs from the offline result.

Example: Set messages.responsePrefix to '${SYNTH_ROUTE_PREFIX}' over an existing '$${SYNTH_ROUTE_PREFIX}' while the Gateway runs.

  • Before: The command reports success while the escaped literal remains saved.
  • After: The command refuses before sending and explains how to apply the change safely.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, focused patch with the previous finding resolved; confidence remains limited by upgrade validation.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Some config commands report success while saving a different reference or ownership value than the same command saves offline.
Reason: Preventing silent config divergence has clear value, and the maintainer-authored direction explicitly accepts refusal when faithful routing is unavailable.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR addresses a current config-write fidelity defect; the previous assertion finding is resolved, and no additional concrete code defect was found.

Priority: P2
Reviewed head: fffd96b780f02615055aed2c010cffad28f8bb11

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Show the changed routed topology behavior through the CLI during an upgrade from v2026.10.7, preserving existing references and ownership settings; redact credentials and non-public endpoints.
Agent review details

How this fits together

The config CLI translates authored edits into authenticated, hash-guarded config.patch requests; the Gateway owns persistence and runtime application.

flowchart LR
 A[Config CLI edit] --> B[Shared writer preparation]
 B --> C[Model Gateway preparation]
 C --> D[Compare authored results]
 D --> E[Refuse divergent edit]
 D --> F[Authenticated config patch]
 F --> G[Gateway persistence and reload]
Loading

Technical review

Best possible solution:

Keep the shared-writer fidelity check and validate its new topology payloads across a stable-to-current upgrade.

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

Main omits intent paths that the shared writer uses for environment-reference restoration and ownership preparation; the body records matching offline-versus-routed failures, and this read-only review ran no target code.

Is this the best way to solve the issue?

Reusing the existing topology owner and refusing intent that the closed stable protocol cannot carry is a focused repair, with distinct regression cases and no unnecessary production layer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2b11e1ea1e02.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Raw commit 5f62201 adds src/cli/config-cli-runner.ts:498 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5f622010788d; files: src/cli/config-cli-runner.ts)
  • Vincent Koc: Raw commit 7d7b5ba adds src/cli/config-cli-runner.ts:488 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7d7b5ba1b5a9; files: src/cli/config-cli-runner.ts)
  • Peter Steinberger: Raw commit 0636e55 adds src/cli/config-cli-runner.ts:489 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0636e5523960; files: src/cli/config-cli-runner.ts)

PR surface

Source +76, Tests +45, Docs +8. Total +129 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 84 8 +76
Tests 1 46 1 +45
Docs 1 12 4 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 142 13 +129

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status no longer selects a status label.

Label justifications:

  • P2: The repair prevents silent divergence in specific advanced config mutations with a limited blast radius.
  • merge-risk: 🚨 compatibility: Routed admission and some authored topology payloads change; the maintainer accepts the local-model limitation, while upgrade compatibility remains a separate validation gate.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-26T04:42:49.753Z sha 7953b0c :: blocked before merge. :: [P2] Remove the new uncommented merge-result assertion

Reviewed October 26, 2026, 1:04 AM ET / 05:04 UTC (Revision 2).

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 26, 2026
@RomneyDa
RomneyDa merged commit cadea14 into main Oct 26, 2026
140 of 141 checks passed
@RomneyDa
RomneyDa deleted the fix/config-route-writer-parity branch October 26, 2026 08:39
RomneyDa added a commit that referenced this pull request Oct 26, 2026
)

* fix(cli): keep routed config writes identical to offline writes

* fix(cli): document the routed merge-model assertion

(cherry picked from commit cadea14)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…claw#184194)

* fix(cli): keep routed config writes identical to offline writes

* fix(cli): document the routed merge-model assertion
obviyus added a commit that referenced this pull request Nov 21, 2026
…teway runs (#203235)

Root cause: src/cli/config-cli-owner-patch.ts:84 builds the routed `replacePaths` consent from the authored config only (`collectReplacePaths(patch, previous)`), while the Gateway's guard at src/gateway/server-methods/config.ts:879-880 (`rejectDestructiveArrayPatchWithoutIntent({ currentConfig: snapshot.config, ... })`) checks the runtime view, where an omitted provider `models` list or a plugin schema default exists as an array. Deleting the section therefore "removes" an array the CLI never named, and the Gateway refuses.

Fixes #203175

Thanks @woodmanlegion for the detailed report and source trace.

## What Problem This Solves

With the Gateway running, `openclaw config unset models.providers.ollama` (or `config unset models`) fails with `config.patch would remove entries from array path(s): models.providers.ollama.models` when the provider has no `models` list in the file. The same happens for plugin config sections with array schema defaults, such as `plugins.entries.anthropic.config.managedNativeTools`. The same command works with the Gateway stopped, and the error suggests options the CLI does not have. Routed CLI writes are supposed to match offline writes (#184194; docs/cli/config.md: "Output and exit codes match the offline command").

## User Impact

`config unset` of a section holding a runtime-default array now removes it through a running Gateway, and the saved file is byte-for-byte what the offline command writes. No workaround (writing `[]` first, or stopping the Gateway) is needed.

## Why This Change Was Made

The CLI already sends consent, in the existing `replacePaths` field, for every array removed below a subtree the command explicitly deletes or replaces. It now also collects those arrays from the Gateway's own `config.get` view (the one the guard checks, read at the same revision as `baseHash`), still only below the removed subtree. The Gateway guard, the request fields and authorization are unchanged. A `set` that would drop entries from an authored list is still refused, and a raw `config.patch` that truncates an authored array without `replacePaths` is still refused by the guard.

## Evidence

Built CLI and Gateway (dist), isolated state per side, the issue's steps run against a running Gateway (routed) and with no Gateway (offline) from identical starting files. Proof lines: #203235 (comment)

- Base (2821214), routed: `config unset models.providers.ollama`, `config unset models` and `config unset plugins.entries.anthropic.config.managedNativeTools` exit 1 with `config.patch would remove entries from array path(s): ...`; offline the same commands exit 0 and the files differ.
- Candidate, routed: all three exit 0 (`Removed ...`), and after each of the 14 steps the routed file equals the offline file byte for byte.
- Controls on the candidate: offline results unchanged; `config set models.providers.vllm.models` dropping an authored entry is refused on both paths (`Refusing to replace ...`); unsetting a sibling provider or a sibling key leaves the other arrays untouched (files equal offline); a raw `config.patch` truncating `gateway.nodes.commands.allow` without `replacePaths` is still refused by the Gateway guard.
- Tests: `src/cli/config-cli-owner-patch.test.ts` now gives the synthetic owner a runtime view with default arrays inside and outside the removed subtree; it fails on base (inside path missing) and passes here, and the outside path is not consented. `src/cli/config-owner-route.process.test.ts` unsets an ollama provider without `models` through a real in-process Gateway.

Line deltas vs merge base: production +26 / -19 (one file, partly formatter rewrap), tests +23 / -7.

Merge danger: two-way door. CLI-only, no stored data, schema or protocol change; a revert restores the previous consent list. Blast radius: routed `config set/patch/unset`, `mcp` config commands and Gateway-owned `setup`; if wrong, a routed removal would consent to an array the Gateway materializes under the removed subtree, which the offline command removes too.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…teway runs (openclaw#203235)

Root cause: src/cli/config-cli-owner-patch.ts:84 builds the routed `replacePaths` consent from the authored config only (`collectReplacePaths(patch, previous)`), while the Gateway's guard at src/gateway/server-methods/config.ts:879-880 (`rejectDestructiveArrayPatchWithoutIntent({ currentConfig: snapshot.config, ... })`) checks the runtime view, where an omitted provider `models` list or a plugin schema default exists as an array. Deleting the section therefore "removes" an array the CLI never named, and the Gateway refuses.

Fixes openclaw#203175

Thanks @woodmanlegion for the detailed report and source trace.

## What Problem This Solves

With the Gateway running, `openclaw config unset models.providers.ollama` (or `config unset models`) fails with `config.patch would remove entries from array path(s): models.providers.ollama.models` when the provider has no `models` list in the file. The same happens for plugin config sections with array schema defaults, such as `plugins.entries.anthropic.config.managedNativeTools`. The same command works with the Gateway stopped, and the error suggests options the CLI does not have. Routed CLI writes are supposed to match offline writes (openclaw#184194; docs/cli/config.md: "Output and exit codes match the offline command").

## User Impact

`config unset` of a section holding a runtime-default array now removes it through a running Gateway, and the saved file is byte-for-byte what the offline command writes. No workaround (writing `[]` first, or stopping the Gateway) is needed.

## Why This Change Was Made

The CLI already sends consent, in the existing `replacePaths` field, for every array removed below a subtree the command explicitly deletes or replaces. It now also collects those arrays from the Gateway's own `config.get` view (the one the guard checks, read at the same revision as `baseHash`), still only below the removed subtree. The Gateway guard, the request fields and authorization are unchanged. A `set` that would drop entries from an authored list is still refused, and a raw `config.patch` that truncates an authored array without `replacePaths` is still refused by the guard.

## Evidence

Built CLI and Gateway (dist), isolated state per side, the issue's steps run against a running Gateway (routed) and with no Gateway (offline) from identical starting files. Proof lines: openclaw#203235 (comment)

- Base (0bcbb56), routed: `config unset models.providers.ollama`, `config unset models` and `config unset plugins.entries.anthropic.config.managedNativeTools` exit 1 with `config.patch would remove entries from array path(s): ...`; offline the same commands exit 0 and the files differ.
- Candidate, routed: all three exit 0 (`Removed ...`), and after each of the 14 steps the routed file equals the offline file byte for byte.
- Controls on the candidate: offline results unchanged; `config set models.providers.vllm.models` dropping an authored entry is refused on both paths (`Refusing to replace ...`); unsetting a sibling provider or a sibling key leaves the other arrays untouched (files equal offline); a raw `config.patch` truncating `gateway.nodes.commands.allow` without `replacePaths` is still refused by the Gateway guard.
- Tests: `src/cli/config-cli-owner-patch.test.ts` now gives the synthetic owner a runtime view with default arrays inside and outside the removed subtree; it fails on base (inside path missing) and passes here, and the outside path is not consented. `src/cli/config-owner-route.process.test.ts` unsets an ollama provider without `models` through a real in-process Gateway.

Line deltas vs merge base: production +26 / -19 (one file, partly formatter rewrap), tests +23 / -7.

Merge danger: two-way door. CLI-only, no stored data, schema or protocol change; a revert restores the previous consent list. Blast radius: routed `config set/patch/unset`, `mcp` config commands and Gateway-owned `setup`; if wrong, a routed removal would consent to an array the Gateway materializes under the removed subtree, which the offline command removes too.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…teway runs (#203235)

Root cause: src/cli/config-cli-owner-patch.ts:84 builds the routed `replacePaths` consent from the authored config only (`collectReplacePaths(patch, previous)`), while the Gateway's guard at src/gateway/server-methods/config.ts:879-880 (`rejectDestructiveArrayPatchWithoutIntent({ currentConfig: snapshot.config, ... })`) checks the runtime view, where an omitted provider `models` list or a plugin schema default exists as an array. Deleting the section therefore "removes" an array the CLI never named, and the Gateway refuses.

Fixes #203175

Thanks @woodmanlegion for the detailed report and source trace.

With the Gateway running, `openclaw config unset models.providers.ollama` (or `config unset models`) fails with `config.patch would remove entries from array path(s): models.providers.ollama.models` when the provider has no `models` list in the file. The same happens for plugin config sections with array schema defaults, such as `plugins.entries.anthropic.config.managedNativeTools`. The same command works with the Gateway stopped, and the error suggests options the CLI does not have. Routed CLI writes are supposed to match offline writes (#184194; docs/cli/config.md: "Output and exit codes match the offline command").

`config unset` of a section holding a runtime-default array now removes it through a running Gateway, and the saved file is byte-for-byte what the offline command writes. No workaround (writing `[]` first, or stopping the Gateway) is needed.

The CLI already sends consent, in the existing `replacePaths` field, for every array removed below a subtree the command explicitly deletes or replaces. It now also collects those arrays from the Gateway's own `config.get` view (the one the guard checks, read at the same revision as `baseHash`), still only below the removed subtree. The Gateway guard, the request fields and authorization are unchanged. A `set` that would drop entries from an authored list is still refused, and a raw `config.patch` that truncates an authored array without `replacePaths` is still refused by the guard.

Built CLI and Gateway (dist), isolated state per side, the issue's steps run against a running Gateway (routed) and with no Gateway (offline) from identical starting files. Proof lines: #203235 (comment)

- Base (2821214), routed: `config unset models.providers.ollama`, `config unset models` and `config unset plugins.entries.anthropic.config.managedNativeTools` exit 1 with `config.patch would remove entries from array path(s): ...`; offline the same commands exit 0 and the files differ.
- Candidate, routed: all three exit 0 (`Removed ...`), and after each of the 14 steps the routed file equals the offline file byte for byte.
- Controls on the candidate: offline results unchanged; `config set models.providers.vllm.models` dropping an authored entry is refused on both paths (`Refusing to replace ...`); unsetting a sibling provider or a sibling key leaves the other arrays untouched (files equal offline); a raw `config.patch` truncating `gateway.nodes.commands.allow` without `replacePaths` is still refused by the Gateway guard.
- Tests: `src/cli/config-cli-owner-patch.test.ts` now gives the synthetic owner a runtime view with default arrays inside and outside the removed subtree; it fails on base (inside path missing) and passes here, and the outside path is not consented. `src/cli/config-owner-route.process.test.ts` unsets an ollama provider without `models` through a real in-process Gateway.

Line deltas vs merge base: production +26 / -19 (one file, partly formatter rewrap), tests +23 / -7.

Merge danger: two-way door. CLI-only, no stored data, schema or protocol change; a revert restores the previous consent list. Blast radius: routed `config set/patch/unset`, `mcp` config commands and Gateway-owned `setup`; if wrong, a routed removal would consent to an array the Gateway materializes under the removed subtree, which the offline command removes too.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 4bedaed)

Companion audit: a012e91 is later busy-Gateway saved-edit confirmation and does not participate in array-path consent.

Release adaptation: Use the same-revision owner runtime config for explicit subtree array consent; keep the stable closed config.patch request, authored topology comparison and hash fence, and omit unrelated saved-config recovery.

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

Labels

cli CLI command changes docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant