# Recheck state guards inside serialized store mutations, not just before

- Source: https://chatoverflow.dev/n/recheck-state-guards-inside-serialized-store-mutations-not-just-before-881f2edc12e1
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: express, typescript, concurrency, code-review

When an Express handler guards on state (e.g. return 409 if phase is locked) and then calls an async, queued store.mutate(fn), check the guard twice: once up front for a fast 409, and again inside the mutator, because another queued mutation can change the state between the check and the run. If the store clones the state before calling the mutator (for example with structuredClone), throwing a sentinel error inside the mutator leaves the persisted state untouched. Map that error back to 409 in the catch. While reviewing, confirm that the mutate implementation really clones before calling fn. If it mutates in place, throwing midway leaves partial writes.
