Repository navigation
fix(state): persist explicitly supplied states in StateManagerDisk - #7159
Conversation
When set_state receives a state instance that was not obtained from get_state, mark the whole state tree as touched so the existing touched-driven persistence machinery writes it to disk. Keep the in-memory cache aligned with the supplied instance, update queued write items in place so debounced writes flush the latest value, and record last-touched so set_state-only tokens still expire. Alternative implementation of reflex-dev#6807 that encodes the persistence decision in the state's own touched flag instead of threading a force_write parameter through QueueItem, set_state_for_substate, and both flush paths.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Merging this PR will not alter performance
Comparing Footnotes
|
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
Unit tests mirror the source tree; the StateManagerDisk regression tests belong in tests/units/istate/manager/test_disk.py. Give the untouched-persistence test a local DiskPersistState instead of the test_state fixture so the module stays self-contained.
masenf
left a comment
There was a problem hiding this comment.
i'm trying to see how possible it is to add benchmarks for the state managers so we actually can easily answer the question i've asked here.
… verified; FINDING-023 latch re-confirmed, 024, 025) Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NeyxWsuC9hqSKq8YcEwZyY
Summary
StateManagerDisk.set_statesilently lost data when called with a state instance that was not the one returned byget_state:self.states) was never updated, so subsequentget_statecalls returned the stale instance.Approach
Alternative implementation of #6807 (thanks @harsh21234i for the analysis and regression tests). Instead of threading a
force_writeparameter throughQueueItem,set_state_for_substate, and both flush paths, this encodes the persistence decision where it already lives: the state's own_was_touchedflag.set_statedoes one O(1) identity check against the cache. If the supplied instance is not the cached one, it marks the whole tree touched — the existing touched-driven machinery then persists it with zero signature changes toset_state_for_substateor the flush paths. The flag is sticky until write time, which also covers accumulation across debounced updates for free. Setting_was_touchedexternally is an established pattern (_screenshot.py,vars/base.py), the flag is stripped on pickling, and its docstring states it exists exactly for this purpose ("determines whether this state instance should be persisted").Also:
QueueItems are updated in place (queued_item.state = state) instead of ignored, per masenf's preference in Fix disk state manager debounced writes #6807.set_staterecords_token_last_touched, so a token that is only ever written still expires instead of leaking cache entries.Non-
BaseStatetokens need no marking: theirget_and_reset_touched_statealways returnsTrue.Testing
Regression tests (ported from #6807, written to fail before the fix): latest-queued-value flush, cache replacement for arbitrary instances (both debounce modes), and persistence of an untouched
BaseState(both debounce modes).Fixes #6806