Skip to content

Avoid root dirty delta for shared state events - #6841

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

harsh21234i wants to merge 25 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 regress 1 benchmark

1 warning

⚠️ 15 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

⚡ 6 improved benchmarks
❌ 1 regressed benchmark
✅ 141 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_route_argument_extraction 115.4 µs 120.6 µs -4.34%
⚡ test_modify_state[linked] 12.8 ms 11.4 ms +12.6%
⚡ test_process_event[linked_8_clients] 57.8 ms 51.9 ms +11.4%
⚡ test_process_event[linked_1_client] 11.9 ms 10.7 ms +11.35%
⚡ test_process_event[linked] 6.4 ms 5.8 ms +10.47%
⚡ test_hydration_snapshot[200] 8.9 ms 8.5 ms +4.7%
⚡ test_hydration_snapshot[20] 958.3 µs 917.9 µs +4.4%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing harsh21234i:fix/shared-state-root-dirty-6392 (333562e) with main (aeea15a)

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; the copied-storage-field issue is addressed.

Summary

Prevents ordinary linked-state events from sending unchanged root/router values.

  • Linked-state events leave temporary router changes out of their final delta.
  • The Redis and app-name tests wait and set up their checks more directly.

Reviews (30) · Last reviewed commit: "fix: preserve synchronized storage updat..." · Reviewed by Greptile

Comment thread reflex/istate/shared.py Resolved

@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 Resolved
Comment thread reflex/istate/shared.py Resolved
Comment thread reflex/istate/shared.py Resolved
@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 Resolved
Comment thread reflex/istate/shared.py Resolved

@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.

@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 Resolved
Comment thread reflex/istate/shared.py Resolved
Comment thread reflex/istate/shared.py Resolved
Comment thread reflex/istate/shared.py Resolved

@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 Resolved

@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 Resolved
Comment thread reflex/istate/shared.py Resolved

@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 Resolved
@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 Resolved
Comment thread tests/units/test_state.py Resolved
Comment thread tests/units/test_state.py Resolved
@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 Resolved

@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 Resolved
Comment thread reflex/istate/shared.py Resolved
Comment thread reflex/istate/shared.py Resolved
@masenf masenf added the bug Something isn't working label Oct 6, 2026
Comment thread tests/units/istate/test_shared.py Resolved
@harsh21234i

Copy link
Copy Markdown
Contributor Author

hey @masenf please take a look!!

Comment thread reflex/istate/shared.py Resolved

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