Repository navigation
fix(state): persist cancelled redis handler updates - #7412
kr1shna-exe wants to merge 3 commits into
Conversation
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryPreserves cancelled foreground handlers’ Redis state before releasing their locks.
The earlier unnumbered thread was manually resolved without explanation. The current shielded save also addresses its concern about a second cancellation interrupting the write. No new actionable issues were found. Tests were inspected, not run. Reviews (3) · Last reviewed commit: "Merge main into fix/7248-persist-cancell..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
|
|
||
| To do so, we can use the Python keyword `yield`. For every yield inside the function, a `StateUpdate` will be sent to the frontend with the changes up to this point in the execution of the event handler. | ||
|
|
||
| When using Redis, cancelling a foreground event handler preserves its state changes as long as it still holds the state lock. This includes updates already yielded to the frontend before another invocation of an `@rx.event(supersedes=True)` handler cancels it. |
There was a problem hiding this comment.
Please add one sentence here: a write the cancelled handler makes after its last yield (for example in its except asyncio.CancelledError cleanup) is stored, but the frontend receives it only with a later update that touches the same var.
Evidence: the disk and memory managers keep the dirty-var bookkeeping on the live state object, so the replacement handler's next delta carries that write. Redis rebuilds the bookkeeping on unpickle (_init_bookkeeping in __setstate__), so the replacement handler's delta does not include it.
Repro: a @rx.event(supersedes=True) handler sets self.entries before the yield and sets Child.last_cancelled only in its except asyncio.CancelledError block. After the replacement handler completes on Redis, the page shows entries with the cancelled handler's values, but Child.last_cancelled stays empty until a page reload. The same app on the disk state manager shows Child.last_cancelled right away.
Generated by Claude Code
Summary
Fixes #7248.
When a foreground handler is cancelled by a superseding event, Redis can discard every state change it made before cancellation, including updates already yielded to the client. The replacement handler then reads the old state. Preserve those changes before releasing the Redis lock so the replacement sees the same history as it does with in-memory state.
What changed
Verification
uv run pytest tests/units --cov --no-cov-on-fail --cov-report=: 11,193 passed, 155 skipped; 78.68% coverage.uv run ruff check .,uv run ruff format --check .anduv run pyright reflex testspassed.--pythonplatform Linux, matching CI. The remainingtyand Biome hooks passed separately.