Skip to content

Run the newest compatible Posit Assistant installation - #18815

Merged
gtritchie merged 4 commits into
mainfrom
feature/pa-highest-version-install
Sep 15, 2026
Merged

gtritchie merged 4 commits into
mainfrom
feature/pa-highest-version-install

Conversation

@gtritchie

Copy link
Copy Markdown
Member

Intent

Posit Assistant discovery picks the newest compatible installation across the user, system-wide, and bundled tiers, instead of the first one found in a fixed order.

Fixes #18774.

Approach

locatePositAssistantInstallation() collects the valid installations among the tiers the settings allow and ranks them: an installation whose protocol.json matches this build outranks one that does not (a missing file counts as a mismatch, as in hasProtocolMismatch()), then the higher package.json version wins, and ties keep the previous order (user, system, bundled). An installation with no readable version ranks lowest but is still used when it is all there is.

A pinned posit-assistant-path stays outside the race. It is the administrator's explicit choice, so it is used as-is when it holds an installation, even over a newer user install; when it holds none it still ends the search for read-only copies rather than falling back to the bundle. Managed mode (allow-posit-assistant-installation=0) still skips the user tier, and already fell through to the bundled copy before this change.

Once a read-only copy can outrank the user tier, the update check needs a guard: a manifest version that ranks below the copy in use would be offered on every check, because each accepted install lands in the user data directory and loses the race. userInstallWouldBeSelected() reports whether an install of the offered version would actually be used, and onUpdateCheckComplete() makes no offer when it would not. The existing user install never competes there, since it is what the install overwrites, so a manifest rollback of a user-only install still takes effect.

Testing

ChatInstallationTests.cpp covers the ranking (newer bundle or system copy over a stale user install, tie order, versionless lowest, protocol compatibility over version, pinned path over a newer user install, invalid pinned path still honouring a user install) and the predicate (nothing installed, replacing the user tier, below and above a read-only copy, incompatible and versionless read-only copies, valid pinned path, managed mode).

GTEST_FILTER='Chat*:SessionAssistant*:PositAssistant*' ./build/src/cpp/rstudio-tests --scope rsession
[  PASSED  ] 266 tests.

Not exercised manually: open-source builds ship no bundle, so the bundled tier was driven only through the InstallSearchPaths seam.

locatePositAssistantInstallation() returned the first tier that held an
installation, in a fixed order: user data directory, then system-wide,
then bundled. A per-user install made before a bundle existed therefore
shadowed every newer bundled or system-wide copy indefinitely.

The user, system, and bundled tiers now compete: an installation whose
protocol.json matches this build ranks above one that does not, then the
highest package.json version wins, and ties keep the old order. A pinned
posit-assistant-path stays outside the race -- it is the administrator's
explicit choice, used as-is when valid, and still ends the search for
read-only copies when invalid. Managed mode still skips the user tier.

With a read-only copy able to outrank the user tier, a manifest version
that ranks below it would be offered forever: each accepted install lands
in the user data directory and loses the race. userInstallWouldBeSelected()
answers whether an install of the offered version would actually be used,
and onUpdateCheckComplete() offers nothing when it would not.

Addresses #18774
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2928 0 187 4
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 737 0 38 0
✅ desktop-macos 741 0 33 2
✅ desktop-windows 738 0 42 1
✅ server-linux 682 0 44 1
✅ setup 28 0 20 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 81cbe2eb9a0a88fdd1651cd0fbe1c56b162e54d1 - Run #1009

The resolver now reads every tier's package.json on each locate() call,
which runs per status, verify, chat, and static-file request. Going
through getInstalledVersion() made a tier with no readable version warn
on every one of those calls. Split the read into a quiet helper that
returns the failure as an Error; getInstalledVersion() keeps warning for
its callers, and the ranking treats an unreadable version as 0.0.0
without logging.
…stall

Review follow-ups on the ranked resolver:

- protocol.json is now read through a quiet helper like package.json, so a
  damaged file in an unselected tier no longer logs an error on every
  locate() call; getInstalledProtocolVersion() keeps logging for its callers.
- A valid posit-assistant-path that shadows an enabled user install now logs
  the same once-per-session notice as managed mode, since it is the same
  silent version change.
- The suppression log in onUpdateCheckComplete() no longer describes the
  resolved version as read-only, which it need not be.
- The versionless-ranks-lowest tests stage a compatible protocol.json, so
  they exercise the version ranking rather than the compatibility rule.
@gtritchie
gtritchie merged commit 52a9a6c into main Sep 15, 2026
34 checks passed
@gtritchie
gtritchie deleted the feature/pa-highest-version-install branch September 15, 2026 15:02
gtritchie added a commit that referenced this pull request Sep 15, 2026
…uns (#18832)

* Serve chat assets from the installation the backend runs

handleAIChatRequest() resolved the Posit Assistant installation on every
/ai-chat/ static asset request, and loading the chat pane issues dozens of
them. Since #18815 that search ranks every tier rather than returning the
first hit, so each request read and parsed package.json and protocol.json
for up to three tiers. On a network-mounted home directory that is
per-request latency multiplied by the number of assets in the chat UI.

startChatBackend() now hands the installation it resolved to the static
file handler, which serves assets from it for the backend's lifetime. The
UI and the server process it talks to come from the same installation, and
no filesystem work happens on the asset path at all. The pin is set before
the port, because setChatBackendPort() rebuilds the CSP header cache, which
reads dist/csp.json from the served installation.

The pin outlives the backend, so a page whose backend exited can still
load lazily-loaded chunks; the next start overwrites it, which is also how
an install or update takes effect. Uninstall clears it, having deleted the
directory it names, so requests resolve again and can still find a
system-wide or bundled copy.

An out-of-band change to the installation -- an administrator replacing the
system-wide copy mid-session -- now takes effect at the next backend start
rather than on the next asset request.

Addresses #18819

* Unpin the served installation as soon as uninstall deletes it

The pin was cleared on chatUninstallPositAssistant()'s success tail, but
the backup-removal failure returns after aiDir.removeIfExists() has already
succeeded, so that path left the static file handler pinned to a deleted
directory -- where validateAndResolvePath() fails to canonicalize the
client root and asset requests answer 403 rather than resolving to a
system-wide or bundled copy.

Clear it immediately after the installation directory is removed, which is
where the claim that it is gone becomes true, and which covers both exits.

Addresses #18819

* Pin the served installation only once the backend has launched

startChatBackend() pinned the installation before acquiring the in-use lock
and launching the process, and the failure paths in between do not clear it.
A start that failed therefore left the static file handler pinned while this
session held no in-use lock -- which is what stops another session from
mutating the installation -- so a concurrent uninstall could delete the
pinned directory and leave asset requests answering 403 instead of resolving
to a system-wide or bundled copy.

Pin after runProgram() succeeds instead. Every failure above it now returns
with nothing pinned, so asset requests resolve for themselves exactly as
they do before a backend has ever started, and no failure path needs to
remember to clear it.

This costs one tier search per backend start: setChatBackendPort() rebuilds
the CSP header cache, which reads dist/csp.json through the resolver, and now
does so before the pin is set. That is once per start against the dozens of
per-request searches this removes, and it resolves the same installation
startChatBackend() just chose.

Addresses #18819

* Tell the static file handler about the backend only once it runs

Moving the installation pin after runProgram() left setChatBackendPort()
ahead of it, so the CSP header cache -- which reads dist/csp.json through
the resolver and keeps it for the rest of the session -- could seed from a
different installation than the one whose assets are then served, if an
out-of-band mutation landed between the two.

Publish all three things the static file handler knows about the backend
together, after the launch succeeds: the installation first, then the port
(whose setter rebuilds the CSP cache, now reading from that installation),
then the auth token. The token is still generated before launch, because
the backend receives it in its environment.

Every failure path above now returns having told the handler nothing, so
asset requests resolve the installation for themselves exactly as they do
before a backend has started.

Addresses #18819

* Resolve per request when the pinned installation is gone

A rolled-back update or an out-of-band removal can leave the pin naming
a directory that no longer exists. Treat that as nothing pinned, so asset
requests fall back to whatever tier still holds an installation instead of
404ing for the rest of the session.

* Test that a pinned installation that is gone is not served from

e94b595 added the fallback but no coverage for it. The test pins a
staged installation, asserts it is served, removes the directory, and
asserts the next request is not answered from it.

The status assertion is what gives the test teeth: a dead pin reaches
validateAndResolvePath(), which cannot canonicalize the client root under
it and answers Forbidden. Asserting only on the body would pass either
way, since that failure returns an empty one -- confirmed by removing the
existence guard, where the body assertion still passed and the status
assertion caught it (403 vs 403).

Addresses #18819

* Test the pin against a complete installation, not just its root

e94b595 fell back when the pinned directory was gone, but a directory
that is there without being an installation stayed selected. installPackage()
extracts into pai/bin in place, and when unzip fails both the cleanup
removeIfExists() and the aiPrevDir restore can fail with only a log
(SessionChat.cpp:4421-4434) -- leaving a half-extracted pai/bin that the
existence check accepts, so asset requests answer from it for the rest of
the session instead of falling back to a system-wide or bundled copy.

Test the pin with verifyPositAiInstallation(), the same definition the
resolver requires of a tier before it will rank it. Four stats per request
rather than one, against the twelve stats and six JSON reads this issue
started from.

The test removes only dist/client/index.html and leaves the requested asset
in place, so the half-extracted installation would still serve it: with the
existence check the assertion fails on the served body, which is what gives
it teeth.

Addresses #18819

* Say what a failed chat backend start still publishes

The comment above the static file handler setters said every failure path in startChatBackend() returns having told the handler nothing, and that pinning the installation first makes the CSP cache read dist/csp.json from it. The lock and launch failures call clearChatBackendPort(), which resets the handler's port and token and rebuilds the CSP header; the pin-first order only matters when this start makes the session's first rebuild.

This branch was previously deployed

1 inactive deployment
e2e-playwright — 81cbe2eb Deployed Sep 14, 2026 by gtritchie via windows / e2e-desktop-windows (5) #1009
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.

Posit Assistant discovery should pick the highest version, and prefer bundled/admin installs when user installs are disabled

1 participant