Repository navigation
Description
Summary
Posit Assistant is installed per-user at <user data dir>/pai/bin (e.g. ~/.local/share/rstudio/pai/bin on Linux, ~/Library/Application Support/RStudio/pai/bin on macOS, %LOCALAPPDATA%/RStudio/pai/bin on Windows). Every rsession the user runs — each desktop window on Mac/Windows/Linux, each RStudio Server/Workbench session — resolves and uses this same directory.
Update and uninstall mutate that shared directory with no cross-process coordination:
performInstall/installPackage(SessionChat.cpp) performs a destructive swap: deleteai.prev→ renamepai/bin→ai.prev→ mkdir → unzip → verify → deleteai.prev. The only "already in progress" guard is a session-local mutex, so it only protects against re-entry within one rsession.chatUninstallPositAssistantrecursively deletespai/bin.- Both stop only the invoking session's own chat backend and NES agent before mutating. Other sessions' processes keep running from the directory being renamed/deleted.
The running processes are tightly coupled to the directory: the chat backend is node launched with its working directory set to pai/bin and a relative script path (module resolution from CWD), the NES agent runs from pai/bin/dist/nes, and rsession serves the chat UI assets from pai/bin/dist/client from disk on every request.
#17365 is a known manifestation of this on Windows (uninstall from a second Desktop instance fails with "Access is denied", and after a successful uninstall other instances are left with a silently broken chat pane). This issue covers the full set of problems, including the update path.
Failure scenarios
Windows Desktop — update. Session B's node backend has its CWD inside pai\bin, which locks the directory against rename. Session A's update kills A's own backend and agent first, then fails the rename with a sharing violation — so A loses its working assistant and gets an error, while nothing was actually protecting B. (A "close all other instances" error message exists for this case, but it fires only after A's own processes are already gone.)
Windows Desktop — uninstall. The recursive delete removes files until it hits one locked by another session's process, leaving a partially deleted install. Session B's backend starts failing lazy module loads and its UI assets 404. This is the "Access is denied" in #17365, but the on-disk result is worse than a clean failure: neither session has a working install until restart + reinstall.
macOS / Linux Desktop — update. POSIX allows renaming/deleting a directory that is in use, so A's update "succeeds". B's running node silently follows the rename into ai.prev (CWD tracks the inode), and ai.prev is then deleted at the end of the successful install. B's backend is now running from a deleted directory: lazy require() calls fail, child-process spawns fail, and — because rsession serves chat UI assets from disk per request — B's browser gets new-version UI files driving B's still-running old-version backend. Symptoms are delayed and hard to diagnose.
RStudio Server / Workbench. Multiple concurrent sessions per user are the norm. On a single node the POSIX behavior above applies. On load-balanced Workbench with NFS home directories, deleting files that another node's process has open does not keep them alive — the other session's backend gets ESTALE and dies mid-conversation.
Concurrent installs. If two sessions both accept the same update prompt (or one hits the not-installed view during the other's swap window), both run the swap sequence with interleaved delete/rename/mkdir/unzip on the same three paths. One session can delete the other's ai.prev while it is the only good copy, rename a half-extracted tree into ai.prev, or have "rollback" restore a partial extraction. verifyPositAiInstallation checks only three sentinel paths, so a torn install can pass verification.
Mid-swap "not installed" window. During the swap, pai/bin briefly does not exist or is partially extracted. Another session opening the chat pane at that moment concludes Posit Assistant is not installed and offers to install it — which escalates into the concurrent-install case.
Version ping-pong across RStudio versions. The update manifest pins Posit Assistant versions per RStudio version, and downgrades are supported by design (shouldInstallVersion returns true whenever versions differ). A user running two RStudio versions (e.g. stable + preview) has two sessions that each want a different Posit Assistant version in the same shared directory: each "update" flips it, which triggers the other session's protocol-mismatch detection, stops its agent, and re-prompts — indefinitely.
No change notification. After a successful uninstall (or update) in one session, other sessions are not notified. Their cached update state and chat panes continue to present the assistant as available (also described in #17365).
Expected behavior
Update and uninstall should be coordinated across the user's rsessions:
- Mutations of the shared install should be serialized across processes (cross-process lock), not just within one rsession.
- A mutation should detect that another session is actively running Posit Assistant from the install and refuse with a clear, actionable message ("close Posit Assistant in your other sessions and try again") — before tearing down its own backend.
- Any in-use/lock mechanism must be robust to crashed sessions so stale state cannot produce false "in use by another session" errors.
Longer term, side-by-side versioned install directories with an atomically updated "current" pointer would let updates proceed safely while other sessions keep running the version they launched with, and would resolve the cross-RStudio-version ping-pong.
Activity
Coordinate Posit Assistant update/uninstall across concurrent sessions (