Skip to content

Add self-healing settings file with corruption recovery#1591

Merged
mohnjiles merged 9 commits intomainfrom
claude/fix-settings-self-healing-Vyzlh
Apr 8, 2026
Merged

Add self-healing settings file with corruption recovery#1591
mohnjiles merged 9 commits intomainfrom
claude/fix-settings-self-healing-Vyzlh

Conversation

@mohnjiles
Copy link
Copy Markdown
Contributor

Fix startup crash when settings.json is corrupted (issue #1590).

  • Add SettingsJsonSanitizer utility that strips null bytes, fixes
    missing braces, and performs property-level JSON recovery
  • Wrap LoadSettings/LoadSettingsAsync deserialization in try-catch
    with progressive recovery: sanitize text -> property-level salvage
    -> fall back to defaults
  • Back up corrupted settings files to settings.json.bak before recovery
  • Make SaveSettings/SaveSettingsAsync atomic using temp-file-rename
    pattern to prevent partial writes that cause corruption
  • Add comprehensive tests for all recovery scenarios

https://claude.ai/code/session_01Gej4ey7eUsbPRDqFWwxKyZ

Fix startup crash when settings.json is corrupted (issue #1590).

- Add SettingsJsonSanitizer utility that strips null bytes, fixes
  missing braces, and performs property-level JSON recovery
- Wrap LoadSettings/LoadSettingsAsync deserialization in try-catch
  with progressive recovery: sanitize text -> property-level salvage
  -> fall back to defaults
- Back up corrupted settings files to settings.json.bak before recovery
- Make SaveSettings/SaveSettingsAsync atomic using temp-file-rename
  pattern to prevent partial writes that cause corruption
- Add comprehensive tests for all recovery scenarios

https://claude.ai/code/session_01Gej4ey7eUsbPRDqFWwxKyZ
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

CLA Assistant Lite bot CLA Assistant bot All Contributors have signed the CLA.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a SettingsJsonSanitizer service to handle corrupted settings files by stripping null bytes, fixing missing braces, and performing property-level recovery. Additionally, SettingsManager is updated to implement atomic file saves and automatic backups of corrupted settings. The review feedback highlights a potential issue with truncated JSON strings in the brace-fixing logic, notes that the property-level validation loop may be ineffective without schema checks, and recommends refactoring duplicated recovery logic in SettingsManager into a shared helper method.

claude added 2 commits April 6, 2026 19:00
- Replace manual byte-by-byte loop with Array.IndexOf + Array.FindAll
- Refactor TryFixBraces to use a Stack<char> for correct LIFO ordering
  of mixed {} and [] bracket pairs
- Add test for mixed bracket truncation recovery

https://claude.ai/code/session_01Gej4ey7eUsbPRDqFWwxKyZ
- Close truncated string literals before appending missing brackets
  in TryFixBraces (fixes recovery of JSON cut mid-string)
- Remove ineffective ToJsonString() validation loop since JsonNode.Parse
  already validates syntax; the typed deserializer handles type mismatches
  via Settings property initializer defaults
- Extract duplicated recovery logic from LoadSettings/LoadSettingsAsync
  into shared DeserializeOrRecoverSettings helper
- Add test for truncated-inside-string recovery

https://claude.ai/code/session_01Gej4ey7eUsbPRDqFWwxKyZ
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA


Generated by Claude Code

@mohnjiles
Copy link
Copy Markdown
Contributor Author

recheck

- Add timestamp to .bak filenames (e.g. settings.json.20260408-020219.bak)
  to preserve original backup if corruption recurs
- Add try-catch around File.Move in SaveSettings/SaveSettingsAsync to
  clean up orphaned .tmp files if the move fails due to file locks

https://claude.ai/code/session_01Gej4ey7eUsbPRDqFWwxKyZ
@mohnjiles mohnjiles merged commit eb2e34d into main Apr 8, 2026
3 checks passed
@mohnjiles mohnjiles deleted the claude/fix-settings-self-healing-Vyzlh branch April 8, 2026 02:32
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants