fix: save history/bookmark state without a reactive context or list assumption - #288
Merged
Conversation
…ssumption Two bugs surfaced when shinychat saves history from a promises::then() callback after a response stream completes (no reactive context, especially after a tool round-trip): * build_state_snapshot() read the sql/title reactiveVals bare, erroring with "Operation not allowed without an active reactive context". The reads are now wrapped in shiny::isolate(). * The onBookmark callback replaced state$values via modifyList(), but ShinySaveState$values is a Shiny-owned environment that cannot be replaced (and is not a list). The callback now mutates items in place. Tests now exercise on_save outside any reactive context and use an environment-backed state$values, matching Shiny's real contract.
cpsievert
marked this pull request as ready for review
September 5, 2026 03:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs surfaced when shinychat saves history from a
promises::then()callback after a response stream completes (no reactive context, especially after a tool round-trip):build_state_snapshot()read the sql/title reactiveVals bare, erroring with "Operation not allowed without an active reactive context" ("Could not save conversation"). The reads are now wrapped inshiny::isolate().onBookmarkcallback replacedstate$valuesviamodifyList(), butShinySaveState$valuesis a Shiny-owned environment that cannot be replaced (and is not a list), so bookmarking failed with "is.list(x) is not TRUE". The callback now mutates items in place.Tests now exercise
on_saveoutside any reactive context and use an environment-backedstate$values, matching Shiny's real contract.Verification
querychat::querychat_app(penguins): chat with a query tool call and confirm no "Could not save conversation" / bookmark errors when the response completes.devtools::test(filter = "querychat_module")passes (70 tests).