Skip to content

fix: hydrate AsyncStorage keys independently - #11

Open
robbe1912 wants to merge 2 commits into
alvarolorentedev:mainfrom
robbe1912:fix/hydration-per-key-trycatch
Open

fix: hydrate AsyncStorage keys independently#11
robbe1912 wants to merge 2 commits into
alvarolorentedev:mainfrom
robbe1912:fix/hydration-per-key-trycatch

Conversation

@robbe1912

Copy link
Copy Markdown

Problem

If any single AsyncStorage key holds a corrupt value (e.g. truncated JSON written by a crashed prior run), the entire outer \ ry/catch\ in \hydrateState\ fires and the remaining keys are silently skipped. The user is left with defaults for everything, not just the corrupt key.

Fix

Rewrite hydration as a \loadKey(key, parse, apply)\ helper with per-key \ ry/catch. A corrupt value is logged and purged (\AsyncStorage.removeItem) so subsequent writes replace it cleanly; the remaining keys hydrate normally.

Files changed

  • \providers/use-opencode-persistence.ts\ (+43 / -34 LOC)
  • \docs/state-and-data.md\ (+2 / -1 LOC) — Hydration rules section now documents per-key isolation + corrupt-value purge behavior.

Validation


  • pm run typecheck\ ✓

  • pm run lint\ ✓

  • pm run test:fake-server:self\ ✓

All four persisted keys (settings, chat preferences, active project,
last session map) were wrapped in a single try/catch. One corrupt value
aborted all remaining hydration steps, leaving the user with defaults
even for keys that were intact.

Wrap each key in its own try/catch and drop the corrupt value so the
next write replaces it cleanly. Run them in parallel via Promise.all
since the order doesn't matter.
Oracle review flagged a contract drift: the per-key try/catch added
in this branch also purges the corrupt key via AsyncStorage.removeItem,
but docs/state-and-data.md only said 'hydration failures are ignored
and defaults are kept'. Document the new behavior explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant