fix: replace queued write with latest state in StateManagerDisk - #6840
fix: replace queued write with latest state in StateManagerDisk#6840honma89 wants to merge 1 commit into
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Greptile SummaryThis PR fixes debounced disk-state persistence so repeated writes for the same token retain the latest state while preserving the original flush schedule.
Confidence Score: 5/5The PR appears safe to merge, with the replacement preserving the queue’s existing scheduling and persistence contracts. The queue continues to use the original token and timestamp, while normal processing and shutdown flushing retrieve the latest replacement value from the queue.
|
| Filename | Overview |
|---|---|
| reflex/istate/manager/disk.py | Correctly updates an existing queued item’s state without changing its token or debounce timestamp. |
| tests/units/test_state.py | Adds focused coverage proving both the in-memory queue entry and flushed disk value use the latest state. |
Reviews (1): Last reviewed commit: "fix: replace queued write with latest st..." | Re-trigger Greptile
There was a problem hiding this comment.
No issues found across 2 files
Tip: cubic could auto-approve low-risk PRs like this, if it thinks it's safe to merge. Learn more
Re-trigger cubic
|
The implementation looks correct to me. Replacing the queued One CI issue remains: pyright flags the test because it assigns through Also, the PR body mentions a news fragment, but I don’t see one in the diff. Could you add the fragment . |
All Submissions:
Type of change
Changes To Core Features:
What does this PR do and why?
StateManagerDisk.set_stateonly enqueued a token for a debounced write if that token wasn't already in_write_queue:If
set_statewas called again for the same token before the queued item flushed, the existingQueueItemwas left untouched, so_flush_write_queue/_process_write_queuewould later write the first queued value to disk instead of the latest one. Directset_statecalls with a replacement state object (as opposed tomodify_state, which mutates the object in place) could silently lose data during the debounce window.This PR changes
set_stateso that when a token is already queued, the queuedQueueItemis replaced with one carrying the latest state viadataclasses.replace(sinceQueueItemis a frozen dataclass), while preserving the originaltimestampso the flush still happens at its originally scheduled time — only the value that gets written changes.A regression test (
test_state_manager_disk_set_state_updates_queued_write) was added that mirrors the reproduction from the linked issue: it callsset_statetwice for the same token with debouncing enabled, asserts the queued state reflects the latest call, then verifies the value persisted to disk afterclose()also reflects the latest call. Verified this test fails on the pre-fix code (1 == 2) and passes with the fix.Also added a towncrier news fragment (
news/+disk-state-manager-stale-write-queue.bugfix.md) per repo convention.closes #6839