You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A dictionary key starting with $ (or a hand-added "$schema") saves fine, but the next load archives the file as .corrupt and resets every setting to defaults #376
AppData.JsonSerializerOptions sets ReferenceHandler = ReferenceHandler.Preserve (AppDataStorage/AppData.cs:45). Under that option, System.Text.Json happily writes a dictionary key such as "$HOME". When it reads the file back, it throws:
JsonException: Properties that start with '$' are not allowed in types that support metadata
A top-level "$schema" property that a user adds by hand for editor validation fails the same way, though other unknown properties are ignored as usual.
LoadOrCreate (AppData.cs:785-794) catches the JsonException, archives the file as settings.json.corrupt.<timestamp> and returns defaults. So one key the library itself wrote silently wipes every unrelated setting.
Expected: Theme=Dark Variables.Count=1, and no .corrupt file.
The same failure without a dictionary: deserializing {"$schema":"./s.json","Theme":"Dark"} with these options throws the same JsonException (path $.$schema). By contrast, {"Theme":"Dark","Unknown":1} loads fine.
Why it matters
Dictionaries keyed by environment variables, template placeholders or shell variables are normal things to keep in settings, and $ keys are common in them. The save succeeds, so the data loss only shows on the next launch. At that point every setting resets, not just the dictionary.
Suggested fix
Preferred: stop using ReferenceHandler.Preserve, for example by switching to IgnoreCycles. Existing files contain $id/$values, so keep a fallback for them: retry with Preserve when a plain read meets $id/$values, or migrate on first load.
At minimum: have Save() refuse (throw) before writing a document it can't read back, for example by round-tripping it or rejecting $-prefixed keys. That turns silent data loss into an error at save time.
Acceptance:
A test shows a $-prefixed dictionary key round-trips, or the save is refused.
A test shows a hand-added top-level $schema loads without creating a .corrupt file.
Related but different: #353, also caused by Preserve, is about a mismatched-type $ref throwing InvalidOperationException.
Priority: High. A key the library itself saved makes the next load discard the whole file. Every unrelated setting resets to defaults, and nothing is reported until the next launch.
Area / suggested assignment: Serialization options and load path (AppData.JsonSerializerOptions, LoadOrCreate). It belongs with whoever owns the ReferenceHandler.Preserve decision.
In progress: No open PR covers this. Bump System.Text.Json from 10.0.14 to 11.0.0 #372 (System.Text.Json 11.0.0 bump) does not change ReferenceHandler behaviour. Re-run the repro after it merges anyway.
Next step: Ship the "at minimum" guard first: refuse a save that can't be read back, which turns silent data loss into an error. Then migrate off Preserve, keeping a fallback reader for existing $id/$values files.
Activity
matt-edmondson commentedon Nov 11, 2026
Triage
AppData.JsonSerializerOptions,LoadOrCreate). It belongs with whoever owns theReferenceHandler.Preservedecision.$ref) but a different trigger. One redesign away fromPreservecould close both, so consider fixing them together.ReferenceHandlerbehaviour. Re-run the repro after it merges anyway.Preserve, keeping a fallback reader for existing$id/$valuesfiles.Generated by Claude Code