← All challenges
medium★ Curatedpmndrs/zustand · v5.0.14

Cleared Zustand storage restores stale state

Try this bug with AI

Fix it in the original repo with an AI agent and get feedback on how you worked.

2 free rounds each week

Round mode
  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to210 XP
Sign up or sign in to start

Read the sample report

From a simulated Django round

You changed code before reproducing the bug.

Run the failing test before the first edit, so you know the failure you are fixing and can tell when it is gone.

Problem statement

A Zustand store gets its saved state from asynchronous storage. Start restoring the saved state, then clear storage before the pending read or migration finishes. When that work eventually completes, it can still overwrite the current state and tell listeners the restore finished.

Update the persistence behavior so clearing storage invalidates any restore already in progress.

  • A pending storage read or migration must leave live state alone after the clear and must not report successful hydration.
  • Clearing storage must preserve the current live state even if it was hydrated earlier.
  • If removing storage throws synchronously, let that exception reach the caller. The pending restore should remain invalid.
  • A later restore should continue to work normally.

Reproduce the behavior and add a focused test for your change. Run the repository's existing persistence tests before submitting.

The environment starts at commit f44cecc72a8e (pmndrs/zustand 5.0.14). Grading uses hidden tests for the fix and existing behavior.

An upstream fix is publicly available. An assistant may already recognize this task. For a cold rehearsal, pick another exercise if you know the fix.