Skip to content

fix(state): reset disk write queue task on close#6715

Open
anxkhn wants to merge 1 commit into
reflex-dev:mainfrom
anxkhn:patch-10
Open

fix(state): reset disk write queue task on close#6715
anxkhn wants to merge 1 commit into
reflex-dev:mainfrom
anxkhn:patch-10

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Reset StateManagerDisk._write_queue_task to None after close() cancels and
awaits the background write queue task.

The assignment was inside the contextlib.suppress(asyncio.CancelledError) block,
immediately after awaiting the cancelled task. Since the write queue task re-raises
CancelledError after flushing pending writes, the suppressed exception skipped
the assignment and left _write_queue_task pointing at a cancelled task.

This moves the reset outside the suppress block, matching the pattern already used
by StateManagerMemory.close().

Testing

  • uv run pytest tests/units/test_state.py::test_state_manager_disk_close_resets_write_queue_task -q
  • uv run pytest tests/units/test_state.py -q
  • uv run ruff check reflex/istate/manager/disk.py tests/units/test_state.py
  • uv run ruff format reflex/istate/manager/disk.py tests/units/test_state.py --check
  • uv run pyright reflex/istate/manager/disk.py tests/units/test_state.py

The new regression test fails on the old indentation and passes with this change.

@anxkhn anxkhn requested a review from a team as a code owner July 7, 2026 09:38
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a one-line indentation bug in StateManagerDisk.close() where _write_queue_task = None was placed inside the contextlib.suppress(asyncio.CancelledError) block. Because the write queue task re-raises CancelledError after flushing pending writes, the suppressed exception caused the None assignment to be skipped, leaving _write_queue_task pointing at a dead cancelled task after close() returned.

  • Moves self._write_queue_task = None one indent level out, so it always executes after the suppressed await, matching the pattern already used by StateManagerMemory.close().
  • Adds a focused regression test (test_state_manager_disk_close_resets_write_queue_task) that schedules the write queue task, calls close(), and asserts the attribute is reset to None.

Confidence Score: 5/5

Safe to merge — the fix is a single-line dedent that moves an assignment to always execute after close(), and a regression test confirms the corrected behavior.

The change is minimal and precise: one line moved out of a suppress block so it cannot be silently skipped by a re-raised CancelledError. The logic matches the existing pattern in StateManagerMemory.close(), and the added regression test directly validates the post-close state of _write_queue_task. No other behavior is altered.

No files require special attention.

Important Files Changed

Filename Overview
reflex/istate/manager/disk.py One-line dedent moves the _write_queue_task = None reset outside the suppress block so it always executes after close, regardless of how the awaited task exits.
tests/units/test_state.py Adds a regression test that schedules the write queue task, calls close(), and asserts _write_queue_task is None — would have caught the original bug.
news/6715.bugfix.md Changelog entry for the bugfix.

Reviews (2): Last reviewed commit: "fix(state): reset disk write queue task ..." | Re-trigger Greptile

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
@anxkhn

anxkhn commented Jul 7, 2026

Copy link
Copy Markdown
Author

Pushed a revision addressing the latest review/CI feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant