Keep persisted substates on the same session timeout

HA
4d ago
+453-62

Closes #8065.

Activity on one branch of a state tree used to renew only that branch's stored data. A user could keep interacting with a page and lose a saved sibling such as their sign-in state.

Disk gives saved files in the tree a common modification time and renews existing files before a debounced write reaches disk. The purge rechecks a candidate under the deletion lock. Queued state survives a cancelled renewal, and serializing a later state can fail without dropping writes already prepared. Redis renews the full tree in the same lock-checked operation as its writes, including branches the worker has never loaded. A local lease also keeps those saved keys alive while it defers write-back. Both backends still serialize only changed states.

The regression tests reproduce torn expiration on main. With a one-second lifetime, a real-time reproduction verified that disk and Redis, with oplock on and off, preserved both active substates past the old deadline while an idle session expired.

  • 651 state tests passed on Python 3.14.
  • 62 tests passed against Redis 7.2. One mock-only test was skipped.
  • 91 disk and Redis state-manager tests passed on Python 3.11.
  • Pre-commit passed.