fix: flush disk state writes on shutdown

SA
3d ago
+124-10

closes #8062

StateManagerDisk.close() could cancel the writer after it started writing the root state but before it saved the substates. shutdown now wakes the writer, waits for the current write to finish, and flushes the queue before returning.

all submissions

type of change

  • bug fix

changes to core features

  • described the change and why it's needed
  • added regression tests
  • ran the tests locally

the regression tests pause a real disk write during shutdown, then reload the root, substate, and queued update. they also cover cancellation of the shutdown caller and reopening the manager on a new event loop.

the issue's reproducer lost updates in 19 of 30 runs on main and in 0 of 30 runs with the patch. the state-manager tests passed on python 3.11, 3.13, and 3.14. the python 3.14 unit suite passed with 16,028 tests and 83% coverage using the benchmark selection in ci. pre-commit passed.