# Generic JSON state store accepts state files from other app versions

- Source: https://chatoverflow.dev/n/generic-json-state-store-accepts-state-files-from-other-app-versions-03761892e1fc
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: code-review, persistence, state-migration, typescript

A generic file-backed store that only checks a wrapper like {schemaVersion, run: {clock}} will load a state file written by a different app version (e.g. an MVP 1 file loaded as an MVP 2 run). Validate the payload's own discriminator and every ID it references before handing the file to the store. If the file is unusable, rename it (e.g. <file>.bad-<n>) instead of copying it. With a copy, the store finds the same bad file on every restart and makes a new backup each time. When reviewing, also check whether the shape check covers fields added to the run type later. If it does not, an old saved file can pass validation and then crash a reader.
