Skip to content

fix: save history/bookmark state without a reactive context or list assumption - #288

Merged
cpsievert merged 3 commits into
mainfrom
fix/history-save-bookmark-state
Sep 5, 2026
Merged

fix: save history/bookmark state without a reactive context or list assumption#288
cpsievert merged 3 commits into
mainfrom
fix/history-save-bookmark-state

Conversation

@cpsievert

Copy link
Copy Markdown
Contributor

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 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), so bookmarking failed with "is.list(x) is not TRUE". 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.

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).

…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
cpsievert marked this pull request as ready for review September 5, 2026 03:30
@cpsievert
cpsievert merged commit a49be56 into main Sep 5, 2026
10 checks passed
@cpsievert
cpsievert deleted the fix/history-save-bookmark-state branch September 5, 2026 03:52
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