fix: only record an uncached var as sent once its delta is delivered
Merged
MA
24d ago+407+407+012345678901234567890123456789-77-77-01234567890123456789
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- Bug fix (non-breaking change which fixes an issue)
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
- Have you successfully ran tests with your changes locally?
Summary
closes #7212
#6946 dedupes unchanged @rx.var(cache=False) values by remembering the last value sent per client. The memo was written while the delta was built (BaseState.get_delta → ComputedVar._record_delta_value), so a downstream get_delta override that withholds an entry — the pattern the get_delta docstring documents, and what reflex-enterprise 0.9.5's auth filtering does — left the memo claiming the client had a value it never received. Once the filter stopped withholding, the identical value was deduped away and the client stayed stale until the value changed again. Regression vs 0.9.11.post1.
What changed
get_deltagathers candidate_DeltaRecords (state, key, value, instance, memo attribute, stored key) into aContextVarwhile building the delta;ComputedVar._record_delta_valuebecame_pending_delta_recordand no longer writes the memo._get_resolved_delta— the single chokepoint every delivery path uses (app.py,istate/proxy.py, reflex-basebase_state_processor.py,istate/shared.py), and the one place that sees the delta after the override chain with coroutines resolved — commits a record only wheredelta[state][key] is value, i.e. the very object that was computed survived. Dropped or replaced entries are owed to the client again._suppress_delta_recording()is still honoured, and a suppressed traversal nested inside a recording one records nothing.- Behaviour change to be aware of: a bare
get_delta()call no longer dedupes (only delivered deltas record). Ten existing #6946 unit tests moved ontoawait state._get_resolved_delta()with their assertions unchanged.
Tests
- New:
test_uncached_var_withheld_by_delta_override_is_resent(dropped / replaced-with-placeholder × sync / async) andtest_uncached_computed_var_recorded_only_once_delivered. The sync cases and the latter fail onmainand pass here; the async cases document that a filter closes the coroutine before it can reach the memo. - Mutation checks: making
_delta_value_keyreturn a bare value, or a constant instead of_UNKEYABLE_VALUE, fails the corresponding #6946 tests again (a first version of this change had left two of them on the non-recording path; fixed during review). uv run pyright reflex tests: 0 errors. ruff / format clean.uv run pytest tests/units --ignore=tests/units/reflex_cli: 9137 passed together with the other three campaign fixes.
Verification against the real breakage
- Browser-free probe from the pre-release campaign: on the published 0.9.12a1 the withheld var is never re-sent (steps 3/4
False); on this branch it is delivered (True), matching 0.9.11.post1. - Playwright repro (
elapppage/filtered), dev in-memory and dev + redis: the published alpha shows the stalesecret-0after the filter is lifted andsecret-2after the next round; this branch showssecret-1andsecret-3, with zero console/page/network errors. #6946's savings are intact: the campaign's/uncachedprobe sends the same 24 delta frames with the same keys (15.3 KB inbound vs 26.1 KB on 0.9.11.post1).
Notes for review
- The commit still happens before
emit_update, so a delta the socket never delivers is recorded as sent (pre-existing; a reconnect re-hydrates viadict()). Moving it past the emit is a separate decision. - A downstream package that filters after
_get_resolved_deltawould still get values recorded; reflex-enterprise 0.9.5 wraps onlyget_deltaanddict(verified from the wheel), passing surviving values through by reference. - Survival is tested by identity; a filter that returns a copy of a value loses the dedupe for that var (chattier, never stale).
- Withholding an async uncached var leaves the inner coroutine unawaited (
RuntimeWarning; pre-existing, reproduced onmain, filtered in the new test). - Independent adversarial review blocked the first version (two pyright errors, two vacuous tests); both fixed in the amended commit. Report with the review and follow-up: fixes/f003/REPORT.md.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NeyxWsuC9hqSKq8YcEwZyY
Generated by Claude Code