Fix disk state manager debounced writes - #6807
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. |
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR fixes a silent data-loss bug in
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| reflex/istate/manager/disk.py | Removes frozen=True from QueueItem to allow mutation, then updates set_state to overwrite the existing queue item's state field instead of silently discarding later writes. Timestamp is intentionally preserved so the debounce window is anchored to the original enqueue time, not the most recent update. |
| tests/units/test_state.py | Adds test_state_manager_disk_debounced_set_state_flushes_latest_non_base_state, which verifies that (1) a second set_state call updates the same QueueItem in place and (2) after close() the value persisted to disk is the latest one. Imports StateToken for direct queue inspection. |
| news/6807.bugfix.md | New changelog entry for the bugfix; single-line, accurate description. |
Reviews (6): Last reviewed commit: "Reuse queued disk state items" | Re-trigger Greptile
|
hey @masenf @FarhanAliRaza can you go through this? |
masenf
left a comment
There was a problem hiding this comment.
appreciate the contribution, but i'm inclined to close this one. if it's rescoped just to persisting the state in set_state, we could probably take that.
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
this leaves open the hole that i mentioned in my first comment i'm okay with updating the state reference in the QueueItem (rather than recreating), but both of the fixes are necessary for handling the "calling i'm not convinced how important that case is to handle, but it's potentially a correctness issue, so I can see a case being made for supporting it -- but if we're going to support it, it needs to be consistent from both sides and not significantly impact performance |
Fixes #6806
Summary
Fix debounced
StateManagerDisk.set_state()writes so repeated updates for the same token persist the latest value instead of the first queued value.Problem
When disk write debouncing was enabled, only the first write for a token was retained in
_write_queue. A later write before the debounce flush was silently discarded, so background processing orclose()could persist stale state.Changes
set_state(); in-memory cache behavior is intentionally outside this PR.Testing
uv run pytest tests/units/test_state.py::test_state_manager_disk_debounced_set_state_flushes_latest_non_base_state -quv run ruff check reflex/istate/manager/disk.py tests/units/test_state.pyuv run ruff format --check reflex/istate/manager/disk.py tests/units/test_state.pygit diff --check