[fix] Only check the redis session lock once per set_state fan-out

Closed
QU
11d ago
+101-19

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?

closes #6848

Summary

StateManagerRedis.set_state was rechecking the session lock (GET + PTTL) once per substate while walking the in memory tree. That's the same lock key every time, so for a large state tree it was a lot of useless Redis round-trips, even when nothing was dirty.

This validates the lock once at the root of the fan-out and passes lock_checked=True into the recursive calls. Dirty substates still get written the same way as before.

Test plan

  • Added test_set_state_validates_lock_once_per_fanout
  • Updated test_state_manager_lock_warning_threshold_contend (one warning per fan-out, not one per substate)
  • uv run pytest tests/units --cov --no-cov-on-fail --cov-report=
  • uv run ruff check .
  • uv run ruff format .
  • uv run pyright reflex tests