Skip to content

docs(py): Explain why on_response() is safe without a lock - #422

Draft
jat255 wants to merge 1 commit into
mainfrom
jat255/history-docstring-lock
Draft

jat255 wants to merge 1 commit into
mainfrom
jat255/history-docstring-lock

Conversation

@jat255

@jat255 jat255 commented Oct 2, 2026 •

Copy link
Copy Markdown

This fixes a docstring in the conversation history code. It said on_response() is safe because of a lock that py-shiny no longer takes.

Summary

The HistoryController.on_response() docstring said that on_response() is safe without a lock because "Shiny serializes reactive flushes behind a single process-wide reactive.lock()". posit-dev/py-shiny#2508 removes Shiny's use of that lock, and posit-dev/py-shiny#2520 deprecates it. The new docstring states the two guarantees that keep the method safe:

  • Shiny does not start a new run of an effect while its previous run continues, so two calls from _save_on_response cannot overlap.
  • Client inputs trigger the other effects that change self.record. Shiny holds input changes until all effects of the session are finished, so those effects cannot run while on_response() is paused at an await.

Review Notes

  • Both guarantees are true in the current Shiny release and also with feat: Run reactive effects py-shiny#2508. You can merge this PR before or after that release.
  • This PR changes only a docstring. There is no code change and no changelog entry.
  • I checked the second guarantee against feat: Run reactive effects py-shiny#2508. When an effect of a session is invalidated, the busy count of the session increases, whatever the trigger was. Input updates wait until the busy count is zero.

Testing

ruff check passes. ruff format --check reports a difference on one line that this PR does not change. The same difference is on main.

Refs posit-dev/py-shiny#2508, posit-dev/py-shiny#2520

The docstring said Shiny serializes effects behind a process-wide
reactive.lock(). Shiny no longer takes that lock (posit-dev/py-shiny#2508)
and is deprecating it (posit-dev/py-shiny#2520). State the guarantees
that keep this method safe in both the current and the upcoming Shiny.
@jat255 jat255 mentioned this pull request Oct 2, 2026
13 of 16 tasks

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant