Skip to content

fix(config): prevent config wipeout on resolution or validation failure#1083

Closed
mukhtharcm wants to merge 3 commits intoopenclaw:mainfrom
mukhtharcm:fix/config-wipeout-prevention
Closed

fix(config): prevent config wipeout on resolution or validation failure#1083
mukhtharcm wants to merge 3 commits intoopenclaw:mainfrom
mukhtharcm:fix/config-wipeout-prevention

Conversation

@mukhtharcm
Copy link
Copy Markdown
Member

Description

This PR ensures the configuration is preserved when config.apply is used, even if the current config has resolution errors (missing env vars or broken includes).

Why it was needed

A regression was introduced in a36735b (Env Var Substitution) where a resolution failure would return an empty object {}. When tools like model switching (config.apply) then merged their changes into this empty object and wrote it back, the user's entire config was wiped out.

Changes

  1. Robust Loader (src/config/io.ts): Failure during $include resolution or ${VAR} substitution now returns the best-effort config instead of {}. This ensures we don't "forget" the existing data.
  2. Safe Merging (src/gateway/server-methods/config.ts): Updated config.apply to use applyMergePatch against the snapshot, providing a second layer of protection against destructive overwrites during quick toggles/swaps.

Notes

This extends the logic from PR #764 to cover new failure modes introduced by recent config features.

@steipete
Copy link
Copy Markdown
Contributor

Config semantics today:

  • config.set + config.apply = full replace (user intent: “here’s the whole
    config”).
  • config.patch = merge‑patch (partial updates; null deletes).

PR change made config.apply behave like merge‑patch:

  • Missing keys no longer delete → stale config sticks around (surprising for
    “apply”).
  • If base config is invalid, merge drags invalid keys forward → validation keeps
    failing.

@steipete
Copy link
Copy Markdown
Contributor

Landed on main with updated config safety + backup rotation; kept latest Fixes ordering in CHANGELOG while resolving conflicts.

Commit: f8e673c

@steipete steipete closed this Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants