#22342: fix(doctor): --fix now actually removes unrecognized config keys
commands
size: XS
trusted-contributor
Cluster:
Doctor and Memory Health Checks
## Summary
When running `openclaw doctor --fix`, unrecognized config keys were identified and reported as 'Doctor changes' but were never actually removed from the config file because `shouldWriteConfig` was never set to `true` in the repair path.
## Root Cause
In `loadAndMaybeMigrateDoctorConfig()`, when `shouldRepair` is true (i.e., `--fix` mode):
- The code correctly identified and removed unrecognized keys
- It set `cfg = unknown.config` with the cleaned config
- But it **never set** `shouldWriteConfig = true`
Without `shouldWriteConfig = true`, the config was never written back to disk.
## Fix
Single line change: add `shouldWriteConfig = true` when unrecognized keys are removed in repair mode.
## Testing
- `pnpm vitest run src/commands/doctor-config-flow.include-warning.test.ts` passes
- Existing doctor tests pass
## Fixes
- Fixes #22272
---
AI-Assisted: This fix was identified with AI assistance (Claude)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes bug where `openclaw doctor --fix` reported removing unrecognized config keys but never persisted the changes to disk. Added `shouldWriteConfig = true` in 6 repair paths where config modifications occur: normalized legacy values, plugin auto-enable, Telegram username resolution, Discord numeric ID conversion, allowFrom wildcard repair, and unknown key stripping.
<h3>Confidence Score: 5/5</h3>
- Safe to merge - surgical fix addresses specific bug with existing test coverage
- The change is minimal, focused, and follows established patterns throughout the codebase. Each addition of `shouldWriteConfig = true` is placed immediately after `cfg = *.config` assignments in repair mode, matching the pattern used consistently in the function. The fix is validated by existing test coverage in `doctor-config-flow.e2e.test.ts`.
- No files require special attention
<sub>Last reviewed commit: 8399f14</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22408: fix: doctor --fix now persists config when removing unrecognized keys
by astroclaw · 2026-02-21
93.8%
#22501: fix(doctor): preserve logging config in doctor --fix
by Shuai-DaiDai · 2026-02-21
85.0%
#21240: fix: GH#20607 prevent doctor from dropping custom config sections
by theognis1002 · 2026-02-19
83.5%
#18546: fix(doctor): replace deprecated `auth add` command reference
by Phineas1500 · 2026-02-16
79.6%
#11602: fix(config): skip stale legacy config files when openclaw.json exists
by akoscz · 2026-02-08
79.4%
#23432: Doctor: prevent permissive secret file modes during --fix
by bmendonca3 · 2026-02-22
79.2%
#22524: fix(doctor): preserve precision of large Discord snowflake IDs in -...
by jmasson · 2026-02-21
78.5%
#21742: fix(doctor): warn on conflicting exec approval config surfaces
by habakan · 2026-02-20
77.5%
#18939: fix: tighten permissions on cron/, browser/, settings/, logs/ in do...
by sriram369 · 2026-02-17
76.6%
#22327: fix(doctor): use gateway health status for memory search key check
by therk · 2026-02-21
76.5%