openclaw - ✅(Solved) Fix [Bug]: openclaw doctor --fix silently prunes custom/unrecognized JSON objects from openclaw.json [2 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#69631Fetched 2026-04-22 07:49:55
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
commented ×2cross-referenced ×2labeled ×2

The openclaw doctor --fix command, intended to repair configuration syntax errors, exhibits destructive behavior. Instead of only fixing syntax issues, it performs a strict schema validation that causes it to silently delete any custom or unrecognized JSON objects/keys within openclaw.json. This results in loss of configuration data for valid integrations and agent settings that the tool does not explicitly recognize.

Error Message

Warn the user about unrecognized keys and ask for confirmation before deleting them.

Root Cause

The openclaw doctor --fix command, intended to repair configuration syntax errors, exhibits destructive behavior. Instead of only fixing syntax issues, it performs a strict schema validation that causes it to silently delete any custom or unrecognized JSON objects/keys within openclaw.json. This results in loss of configuration data for valid integrations and agent settings that the tool does not explicitly recognize.

Fix Action

Fixed

PR fix notes

PR #69649: fix(doctor): preserve unknown config keys during --fix to prevent silent data loss

Description (problem / solution / changelog)

Problem

openclaw doctor --fix silently strips all keys not recognized by the Zod schema. This includes custom integrations, plugin data, and user-defined JSON objects that users intentionally placed in their config. The deletion happens without confirmation, even in interactive mode — the only indication is a "Doctor changes" note that lists the removed paths after the fact.

The automatic doctor --non-interactive --fix pass during openclaw update also triggers this behavior, meaning users can lose custom config data simply by upgrading.

Closes #69631

Solution

Make unknown key removal opt-in instead of automatic:

ModeBeforeAfter
doctor (preview)Shows "Unknown config keys" note, offers to applyShows "Unknown config keys (kept)" note with hint to use --force
doctor --fixSilently strips unknown keysPreserves unknown keys, reports them as kept
doctor --fix --force(same as --fix)Strips unknown keys (explicit opt-in)
update (auto doctor)Silently strips unknown keysPreserves unknown keys

The --force flag already exists on the doctor command for other destructive operations. This change makes unknown key removal consistent with that pattern.

Changes

  • config-flow-steps.ts: applyUnknownConfigKeyStep now accepts shouldForce and only applies the stripped config when both shouldRepair and shouldForce are true
  • doctor-config-flow.ts: Passes shouldForce through, updated note messaging to distinguish "kept" vs "removed"
  • update-runner.ts: Updated comment to reflect new behavior (unknown keys preserved during upgrades)
  • Tests: Updated existing assertions, added new test cases for --fix alone and --fix --force behaviors

Test Results

All 55 tests pass across 8 test files:

  • config-flow-steps.test.ts — 5 tests (3 new)
  • doctor-config-flow.test.ts — 28 tests (1 updated)
  • doctor-config-analysis.test.ts — 3 tests
  • Plus 4 additional test files (safe-bins, missing-accounts, include-warning, integration)

Changed files

  • src/commands/doctor-config-flow.test.ts (modified, +6/-1)
  • src/commands/doctor-config-flow.ts (modified, +10/-1)
  • src/commands/doctor/shared/config-flow-steps.test.ts (modified, +51/-4)
  • src/commands/doctor/shared/config-flow-steps.ts (modified, +24/-4)
  • src/infra/update-runner.ts (modified, +3/-2)

PR #69659: fix(doctor): merge raw JSON to prevent pruning unrecognized keys during repair #69631

Description (problem / solution / changelog)

Summary

  • Problem: openclaw doctor --fix removes unrecognized/custom keys from openclaw.json
  • Why it matters: Causes silent data loss for valid user-defined integrations and config extensions
  • What changed: Repair flow now merges the original parsed config with the repaired config before writing
  • What did NOT change (scope boundary): No changes to schema validation, parsing, or config structure

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Gateway / orchestration
  • Memory / storage

Linked Issue/PR

  • Closes #69631
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: Strict schema validation strips unknown keys, and the repaired config was written directly to disk
  • Missing detection / guardrail: No preservation of original config before write-back
  • Contributing context: Validation is strict by design, but unsafe when used as the persistence source

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:

    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: doctor-config-flow tests

  • Scenario the test should lock in: config contains unknown/custom keys → run doctor --fix → keys remain intact

  • Why this is the smallest reliable guardrail: issue occurs across read → validate → write boundary

  • Existing test that already covers this (if any): "preserves invalid config for doctor repairs"

  • If no new test is added, why not: existing tests already validate preservation behavior


User-visible / Behavior Changes

Custom/unrecognized keys are no longer removed during doctor --fix


Diagram (if applicable)

Before:
doctor --fix → validate → write stripped config → data loss

After:
doctor --fix → validate → merge(source + repaired) → write → data preserved

## Security Impact (required)

- New permissions/capabilities? No
- Secrets/tokens handling changed? No
- New/changed network calls? No
- Command/tool execution surface changed? No
- Data access scope changed? No

---

## Repro + Verification

### Environment

- OS: Arch Linux x86_64 
- Kernel: 6.19.11-arch1-1
- Runtime/container: Node v22 .22.2
- Model/provider: N/A
- Integration/channel (if any): N/A
- Relevant config (redacted): custom keys added to `~/.openclaw/openclaw.json`

### Steps

1. Add custom key to config  
2. Run `openclaw doctor --fix`  
3. Inspect config file  

### Expected

- Custom keys remain intact

### Actual

- Custom keys were removed (before fix)

---

## Evidence

- [x] Failing behavior reproduced before fix  
- [x] Verified preservation after fix  

---

## Human Verification (required)

- Verified scenarios:
  - top-level unknown keys preserved  
  - nested keys within top-level unknown objects preserved
  - known fields still repaired correctly  

- Edge cases checked:
  - partial/invalid configs  
  - mixed known + unknown fields  

- What you did **not** verify:
  - very large configs  
  - concurrent writes  

---

## Review Conversations

- [x] I replied to or resolved every bot review conversation I addressed in this PR.  
- [x] I left unresolved only the conversations that still need reviewer or maintainer judgment.  

---

## Compatibility / Migration

- Backward compatible? Yes  
- Config/env changes? No  
- Migration needed? No  

---

## Risks and Mitigations

- Risk:
  - shallow merge may not preserve custom keys injected deeply inside known core objects (e.g., custom flags inside the core models block).  

- Mitigation:
  - behavior aligns with expected use (users typically add top-level custom objects for their integrations). We can easily iterate to a deep-merge utility if maintainers prefer broader coverage in the future.

## Changed files

- `src/commands/doctor-config-flow.ts` (modified, +5/-0)
- `src/config/io.ts` (modified, +24/-12)
- `src/flows/doctor-health-contributions.ts` (modified, +120/-1)
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

The openclaw doctor --fix command, intended to repair configuration syntax errors, exhibits destructive behavior. Instead of only fixing syntax issues, it performs a strict schema validation that causes it to silently delete any custom or unrecognized JSON objects/keys within openclaw.json. This results in loss of configuration data for valid integrations and agent settings that the tool does not explicitly recognize.

Steps to reproduce

Open ~/.openclaw/openclaw.json and add a new, valid custom object (e.g., "myCustomIntegration": { "key": "value" }). Ensure the file is valid JSON (e.g., checked via jq .). Run the repair command: openclaw doctor --fix. Observe the file content.

Expected behavior

The tool should either: Only fix syntax errors (missing commas, brackets, etc.) and preserve all existing data. Warn the user about unrecognized keys and ask for confirmation before deleting them.

Actual behavior

The tool silently removes the custom object ("myCustomIntegration") entirely, treating it as invalid configuration, without warning or user confirmation.

OpenClaw version

OpenClaw 2026.4.15 (041266a)

Operating system

OS: Ubuntu on WSL2

Install method

npm global

Model

N/A (Core Configuration Tooling)

Provider / routing chain

Standard ~/.openclaw/openclaw.json local file read/write path.

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

Affected users/systems/channels: Any user who manually extends their openclaw.json with custom integrations or third-party tools. Severity: Blocks Workflow. It causes silent data loss of valid configuration, requiring manual recovery from backups. Frequency: Always. The tool consistently strips unrecognized objects during the repair process. Consequence: Users lose custom configurations, leading to broken integrations and service failures.

Additional information

No response

extent analysis

TL;DR

The openclaw doctor --fix command should be modified to preserve custom JSON objects/keys in openclaw.json instead of silently deleting them during schema validation.

Guidance

  • Review the openclaw doctor --fix command's implementation to identify where the strict schema validation is occurring and consider relaxing it to allow for custom objects/keys.
  • Add a warning mechanism to notify users about unrecognized keys and request confirmation before deleting them, ensuring transparency and preventing data loss.
  • Consider introducing a --preserve-custom flag or similar option for the --fix command, allowing users to explicitly choose whether to keep custom configurations during the repair process.
  • Evaluate the current validation logic to distinguish between syntax errors and unrecognized but valid custom configurations, ensuring that only actual errors are corrected.

Example

# Example of a potential warning message
echo "Warning: Unrecognized key 'myCustomIntegration' found in openclaw.json. Do you want to delete it? (y/n)"

Notes

The solution may require updates to the OpenClaw tool's codebase, specifically the doctor --fix command's logic. It's essential to balance the need for strict schema validation with the flexibility to support custom integrations and configurations.

Recommendation

Apply a workaround by manually backing up openclaw.json before running openclaw doctor --fix and restoring any custom configurations afterward, until a permanent fix is implemented. This approach ensures that critical custom data is preserved while still allowing for syntax error correction.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The tool should either: Only fix syntax errors (missing commas, brackets, etc.) and preserve all existing data. Warn the user about unrecognized keys and ask for confirmation before deleting them.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING