Analysis of Issue #1054
Summary
Invalid JSON in settings.json (e.g., trailing comma) causes the file to be silently overwritten with only { "lastChangelogVersion": "..." }, losing all user settings.
Root Cause
The bug is in packages/coding-agent/src/core/settings-manager.ts:
File: settings-manager.ts lines 136-148
The flow:
- User has
settings.json with invalid JSON (trailing comma)
loadFromFile() catches the parse error, logs a warning, returns {}
globalSettings becomes {}
- On startup,
interactive-mode.ts calls setLastChangelogVersion()
save() method re-reads the file (fails again, returns {})
- Only
lastChangelogVersion is merged into {}
- File is written with
{ "lastChangelogVersion": "..." }, erasing all settings
Proposed Fix
Track whether loading failed due to a parse error and refuse to overwrite the file in that case.
Changes to settings-manager.ts:
- Add a new field to track load failures:
- Modify
loadFromFile to throw on parse errors instead of silently returning {}:
- Modify
create() to catch and store the error:
- Modify
save() to check for load errors before writing:
Files Affected
packages/coding-agent/src/core/settings-manager.ts