Skip to content

Remove commons_server() in favor of shinychat::chat_server() - #221

Draft
cpsievert wants to merge 2 commits into
agent-restore-detectionfrom
drop-commons-server
Draft

Remove commons_server() in favor of shinychat::chat_server()#221
cpsievert wants to merge 2 commits into
agent-restore-detectionfrom
drop-commons-server

Conversation

@cpsievert

@cpsievert cpsievert commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #202.

With shinychat now managing conversation identity and history restores first-class, commons_server() no longer adds much on top of shinychat::chat_server(), so this PR removes it. Custom apps now compose shinychat::chat_server() directly, and the idle-time pre-warm it used to do is exposed as an exported commons_prewarm() helper:

# before
commons_server("chat", agent)

# after
commons_prewarm(agent)
shinychat::chat_server("chat", client = agent)

The two call sites differ in error handling: a direct agent$prewarm() — typically cache warming ahead of deployment — lets failures propagate, so a cold cache fails the deploy; commons_prewarm() downgrades failures to warnings, since pre-warming is a pure optimization (everything it builds is rebuilt lazily at first use) and an error escaping a later::later() callback would stop the whole Shiny app.

Testing

  • New tests: prewarm() propagates failures; commons_prewarm() downgrades a prewarm failure to a warning (driven through later::run_now()); commons_app() prewarms the agent on idle; a commons agent runs under shinychat::chat_server() via shiny::testServer().
  • Deleted: the commons_server() tests.
With shinychat managing conversation identity and history restores
first-class, commons_server() no longer adds anything over
shinychat::chat_server(). Remove it and make commons_theme() the sole
building block for custom commons apps:

- commons_app() composes page_chat(), commons_theme(), and
  chat_server() directly; the same composition is shown in the
  examples, vignette, and onboarding skill for custom deployments.
- Conversation-id persistence (persist_conversation_id() and its
  history hooks) and the agent-side bookkeeping
  (get/set_conversation_id(), refresh_conversation_id(),
  last_streamed_turns) are deleted. ellmer stamps
  gen_ai.conversation.id on its own spans from the client's
  conversation_id binding, which shinychat allocates at first
  submission; span_conversation_id() still walks the ancestor chain so
  older traces with the id on commons' wrapper span remain readable.
- check_chat_packages() goes too: htmltools and shinychat are in
  Imports, and shinychat itself Imports shiny, so every package the
  chat functions touch is guaranteed installed with commons.
- commons_theme() moves from theme.R into chat.R.
commons_server() used to kick off pre-warming itself; with it gone,
export a helper so custom apps get the same behavior with one call.
commons_prewarm(agent) validates the agent and defers prewarm() to
post-startup idle time, and is used by commons_app() and throughout
the examples, vignette, and onboarding skill.

The error contract is split by call site. A direct agent$prewarm() is
typically warming caches ahead of deployment, so failures propagate: a
cold cache should fail the deploy, and a warning would sail through a
deploy script. commons_prewarm() downgrades failures to warnings,
since pre-warming is a pure optimization (everything it builds is
rebuilt lazily at first use) and an error escaping a later::later()
callback would stop the Shiny app.
@cpsievert

cpsievert commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator Author

@simonpcouch I think I'd also be open to just keeping common_server() for the easy "batteries included" API, but I generally still think we should go in this direction where "batteries become optional" and it's easy to pick and choose via a composable, functional, API

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

Labels

None yet

1 participant