Skip to content

Posit Assistant static asset requests re-resolve the installation on every request #18819

Description

@gtritchie

Summary

handleAIChatRequest() (src/cpp/session/modules/chat/ChatStaticFiles.cpp) calls locatePositAssistantInstallation() on every /ai-chat/ static asset request. Loading the chat pane issues dozens of these. Since #18815 the resolver ranks every tier rather than returning the first hit, so each request now runs verifyPositAiInstallation() plus a package.json read and a protocol.json read for up to three tiers (user, system-wide, bundled), instead of roughly three stats on the user tier.

On a workstation this is microseconds. On RStudio Server with a network-mounted home directory, or a system tier on a mounted share, it is per-request latency multiplied by the number of assets in the chat UI.

Why a plain session cache is not the fix

The resolver re-checks the filesystem on every call by design: an administrator updating the system-wide copy, or a user removing their own install out of band, is noticed without a session restart. A cache invalidated only by this session's own install/uninstall (the two places that already clear s_positAssistantVersion and s_updateState) would miss both.

Options

  • Resolve once per chat-backend start and serve assets from that installation for the backend's lifetime. The backend is already launched from a specific install (startChatBackend()), and the assets it serves should match the server it runs, so this is arguably more correct than re-resolving per asset.
  • Keep per-request resolution but memoize on the tiers' directory mtimes, so an unchanged filesystem costs a few stats rather than JSON reads.

The first is simpler and ties the served assets to the running backend; the second preserves today's behaviour exactly.

Related: #18774, #18815 (where this was raised in review).

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions