Skip to content

Avoid root dirty delta for shared state events - #6841

Open
harsh21234i wants to merge 23 commits into
reflex-dev:mainfrom
harsh21234i:fix/shared-state-root-dirty-6392
Open

harsh21234i wants to merge 23 commits into
reflex-dev:mainfrom
harsh21234i:fix/shared-state-root-dirty-6392

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tests

  • uv run --frozen pytest tests/units/test_state.py::test_linked_state_event_does_not_dirty_root_state -q
  • uv run --frozen pytest tests/units/test_state.py::test_linked_state_event_does_not_dirty_root_state tests/units/test_state.py::test_router_var_dep tests/units/test_state.py::test_computed_var_depends_on_parent_non_cached tests/units/test_state.py::test_async_computed_var_get_state -q
  • uv run --frozen pytest tests/units/test_state.py -q
  • uv run --frozen pre-commit run --files reflex/istate/shared.py tests/units/test_state.py news/6841.bugfix.md

Closes #6392

Review in cubic

@harsh21234i
harsh21234i requested a review from a team as a code owner August 4, 2026 11:06
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@codspeed

codspeed Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 9.96%

2 warnings

⚠️ 22 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

⚡ 5 improved benchmarks
✅ 143 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_modify_state[linked] 12.6 ms 11.1 ms +13.03%
⚡ test_process_event[linked_8_clients] 57 ms 51.2 ms +11.29%
⚡ test_process_event[linked_1_client] 11.7 ms 10.5 ms +10.98%
⚡ test_process_event[linked] 6.3 ms 5.7 ms +9.92%
⚡ test_hydration_snapshot[200] 8.9 ms 8.4 ms +4.76%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing harsh21234i:fix/shared-state-root-dirty-6392 (ae45ca2) with main (be0c685)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issues were found.

Summary

The PR prevents temporary router dirtiness from leaking into linked-state event updates.

  • Linked-state events leave unchanged router values out of their deltas.
  • The Redis lock test waits until both requests reach the queue.

The changes since the previous review only adjust Redis test synchronization. No new actionable issues were found. Tests were not run during this review.

Reviews (28) · Last reviewed commit: "test: synchronize redis lock contention ..." · Reviewed by Greptile

Comment thread reflex/istate/shared.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated
@harsh21234i

Copy link
Copy Markdown
Contributor Author

hey @masenf The state-dirty cleanup changes and regression tests are now implemented, including descendant cleanup when delta resolution fails. Most CI checks are passing, but reflex-install-and-init is failing. Could you confirm whether that failure is infrastructure-related or requires a code change? Once it passes, could you please review the latest commit?

Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py

@masenf masenf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patch breaks delta calculation for computed vars in shared state that depend on root state.

see https://github.com/reflex-dev/reflex/blob/claude/substate-dirty-tracking-demo-rple7z/shared_state_router_delta_repro.py

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread reflex/istate/shared.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread tests/units/test_state.py Outdated
@harsh21234i

Copy link
Copy Markdown
Contributor Author

hey @mansef could you please review the latest commit?

@harsh21234i
harsh21234i force-pushed the fix/shared-state-root-dirty-6392 branch from 12ba89d to d4f64bc Compare September 27, 2026 11:29
Comment thread reflex/istate/shared.py Outdated
Comment thread tests/units/test_state.py Outdated
Comment thread tests/units/test_state.py Outdated
@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P1 Dirty markers survive patch exit reflex/istate/shared.py:283 ▶

    If a computed var on another state depends on the restored private state, this call marks that var and its ancestor path dirty. Patch exit occurs after the event delta has been resolved and cleaned, so the marker survives into a later event and can emit an unrelated computed-var delta.

@masenf masenf added the perf Performance-improving changes label Sep 29, 2026
Comment thread reflex/istate/shared.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated
Comment thread reflex/istate/shared.py Outdated
@masenf masenf added the bug Something isn't working label Oct 6, 2026
Comment thread tests/units/istate/test_shared.py Outdated
@harsh21234i

Copy link
Copy Markdown
Contributor Author

hey @masenf please take a look!!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working perf Performance-improving changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Events against SharedState should not mark root state dirty all the time

2 participants