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 cache coherence and queued writes in the disk state manager. The main changes are:
Confidence Score: 5/5No additional blocking issue was found in this follow-up.
Important Files Changed
Reviews (3): Last reviewed commit: "Add changelog fragment for disk state fi..." | Re-trigger Greptile |
Fixes #6806
Summary
Fixes a disk state manager bug where debounced
set_state()calls for non-BaseStatetokens could return stale in-memory values and flush the wrong value to disk.
Problem
When
StateManagerDiskused_write_debounce_seconds > 0,set_state()only queued the first value for a token. Alater
set_state()before the debounce flush did not update the queued item, soclose()or the background flushcould persist stale data.
Also, non-
BaseStatevalues were not updated in the in-memory cache while the write was pending, soget_state()could return the default/old value before the disk flush completed.
Changes
BaseStatetokens.Testing
uv run pytest tests/units/test_state.py::test_state_manager_disk_debounced_set_state_updates_non_base_state_cache tests/units/test_state.py::test_state_manager_disk_debounced_set_state_flushes_latest_non_base_state -quv run pytest tests/units/test_state.py -k "deserialize_gc_state_disk or state_manager_disk_close_resets_write_queue_task or state_manager_disk_debounced_set_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.pyuv run pyright reflex/istate/manager/disk.py tests/units/test_state.py