Skip to content

Avoid root dirty delta for shared state events - #6841

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

harsh21234i wants to merge 16 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 degrade performance by 17.19%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 5 regressed benchmarks
✅ 141 untouched benchmarks
⏩ 18 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_modify_state[linked] 17.1 ms 21.6 ms -21.11%
❌ test_process_event[linked_1_client] 15.8 ms 19.5 ms -18.92%
❌ test_process_event[linked] 8.6 ms 10.5 ms -18.01%
❌ test_process_event[linked_8_clients] 75.9 ms 91.9 ms -17.39%
❌ test_link_and_unlink[private] 6.1 ms 6.8 ms -10.11%

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 (078c9fd) with main (52d1c1c)

Open in CodSpeed

Footnotes

  1. 18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@greptile-apps

greptile-apps Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes state delta leakage in shared state events.

The PR appears safe to merge; no new actionable issue was identified.

Summary

The PR prevents temporary router dirtiness from appearing in linked/shared-state event deltas and adds regression coverage. The change since the previous review also avoids invoking fan-out when there are no affected tokens.

Reviews (22) · Last reviewed commit: "Merge upstream main into shared state fi..."

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

This comment has been minimized.

@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

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

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