Skip to content

Revert the assistant selection when a Posit Assistant install is declined - #18629

Merged
gtritchie merged 7 commits into
mainfrom
bugfix/assistant-copilot-posit-revert
Aug 26, 2026
Merged

gtritchie merged 7 commits into
mainfrom
bugfix/assistant-copilot-posit-revert

Conversation

@gtritchie

Copy link
Copy Markdown
Member

Fixes #18356.

Switching the code assistant away from GitHub Copilot persists the new selection immediately: disableCopilot() stops the Copilot agent by writing the assistant preference, because the backend picks the agent to run from that preference and not from copilot_enabled (isAssistantEnabled() in SessionAssistant.cpp). That write lands before OK or Cancel, so anything that backs the switch out has to undo it.

checkPositAssistantInstallation() read its revert target after that write had already replaced it with "posit". Declining the Posit Assistant install prompt therefore reverted to "posit" and early-returned, leaving the assistant pointing at an addon that was never installed and code suggestions reporting "Posit AI: No completions available." Cancelling the Options dialog did not undo it either.

What changed

A RevertTarget, captured when the check starts, carries the two values the check may have to put back:

  • the selection the user had, restored to the selector. It is not the preference: a choice made earlier in the same dialog is not written until OK, so from (None) a Copilot pick followed by Posit AI has to fall back to Copilot.
  • the preference saved behind it, restored only when it actually changed. Writing unconditionally would persist a selection the user never confirmed, which Cancel could then no longer discard.

The revert also restores copilot_enabled alongside the preference it mirrors, as onApply() derives it. Nothing gates the agent on that preference, but disableCopilot() gates its own write on it: left false under a reverted Copilot selection, the next switch away from Copilot would not persist.

Threading one object replaced the three previous* parameters that ran through the check, prompt, install, and revert path, so those signatures got shorter.

Tests

e2e/rstudio/tests/preferences/assistant_provider_switch.test.ts drives Global Options and forces the install prompt through the chat_set_update_check_override automation RPC, so it needs no credentials, no network, and no particular addon state. Each case was confirmed to fail on the commit preceding its fix:

Case Failure without the fix
Copilot -> Posit AI -> decline selector left at posit
(None) -> unsaved Copilot -> Posit AI -> decline selector reverted to none
saved Posit AI -> unsaved Copilot -> Posit AI -> decline assistant persisted as copilot

Tagged @desktop_only: GitHub Copilot is offered in the selector only when the copilot-enabled session option is set, which defaults on in Desktop mode alone.

All 30 tests in tests/preferences/ pass on a desktop-dev build.

Known gap, not addressed here

The assistantVerifyInstalled error path (AssistantPreferencesPane.java:598) still leaves "posit" persisted when that RPC fails: it logs and sets a status label without reverting. It predates this change and is a different trigger from the one the issue describes, and closing it means deciding what the user sees -- every other revert path pairs the revert with an error dialog, whereas reverting there would swap panels and overwrite the status label, so the selector would snap back with no explanation. Worth a follow-up issue.

Switching the code assistant from GitHub Copilot to Posit AI writes the
assistant preference straight away -- disableCopilot() stops the Copilot
agent by writing it, since the backend picks the agent to run from that
preference and not from copilot_enabled. checkPositAssistantInstallation
then read the value to revert to *after* that write had replaced it with
"posit", so declining the install prompt reverted to "posit" and
early-returned, leaving the assistant pointing at an addon that was never
installed and code suggestions reporting "No completions available".

Callers now capture the outgoing selection before disableCopilot() runs
and pass it to the check, and the revert restores copilot_enabled
alongside the assistant it mirrors -- reverting to Copilot without it
would name an agent the backend keeps stopped. The revert's
nothing-to-undo guard also consults the persisted preference, which
disableCopilot() can have moved out from under the selector.

Covered by a Playwright regression test that forces the update check to
offer a fresh install (chat_set_update_check_override), declines the
prompt, and asserts both preferences return to Copilot. It fails on the
previous behavior with the selector left at "posit".

Addresses #18356
The revert introduced in the previous commit read the assistant preference
for its target, so a selection made earlier in the same dialog -- which is
not persisted until OK -- was lost. Starting from (None), picking GitHub
Copilot and then Posit AI and declining the install dropped back to (None)
rather than Copilot.

The selector's prior value is now tracked across changes and used as the
revert target. Undoing the preference is gated separately, on the
preference actually holding "posit": that is true exactly when the switch
persisted it (disableCopilot, or the write before an install), and writing
unconditionally would otherwise persist a selection the user never
confirmed.

Addresses #18356
The revert wrote the preference whenever it held "posit", on the assumption
that only this switch could have put it there. It could equally have been
the saved setting: with Posit AI saved, selecting Copilot without applying
and then Posit AI again and declining the install persisted Copilot, so
cancelling the dialog no longer restored Posit AI.

The selection and the preference are now both carried by a RevertTarget
captured at the start of the check, and each is restored to its own prior
value -- the preference only when it actually changed. That replaces the
three "previous" parameters threaded through the check, prompt, install,
and revert path, so those signatures get shorter rather than longer.

Adds the matching Playwright case; it fails on 6f38919 with the preference
persisted as "copilot".

Addresses #18356
The comment on the copilot_enabled write claimed a revert to Copilot would
otherwise leave the agent disabled. It would not: nothing gates the agent on
that preference -- isAssistantEnabled() picks the agent from
userPrefs().assistant() and checks the admin's copilot-enabled session
option, and no session module reads the pref at all. The write is still
needed, because disableCopilot() gates its own write on it: left false under
a reverted Copilot selection, the next switch away from Copilot would not
persist. Both the Java comment and its copy in the test now say that.

Also drops the redundant previousAssistantSelection_ initialiser (initDisplay
assigns it before any user change can reach the handler, and initialize() can
move the selector past it) and dismisses leftover modals in the spec's
afterEach, as the two sibling preference specs do -- a mid-test failure
otherwise leaves the options dialog up for the next test.

Addresses #18356
@gtritchie gtritchie added this to the 2026.09 (Autumn Hawkbit) milestone Aug 24, 2026
@gtritchie
gtritchie requested a review from kevinushey August 24, 2026 20:06
@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
2435 1 152 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
❌ desktop-linux 605 1 31 0
✅ desktop-macos 611 0 26 1
✅ desktop-windows 612 0 31 0
✅ server-linux 579 0 44 1
✅ setup 26 0 10 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 082814487114edd67fe1b645e63f70f24c2915db - Run #700

@gtritchie
gtritchie merged commit 0b263ea into main Aug 26, 2026
28 of 29 checks passed
@gtritchie
gtritchie deleted the bugfix/assistant-copilot-posit-revert branch August 26, 2026 15:37

This branch was previously deployed

1 inactive deployment
e2e-playwright — 08281448 Deployed Aug 26, 2026 by gtritchie via windows / e2e-desktop-windows (1) #700
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.

Copilot->Posit code-assistant switch persists "posit" before install, leaving it uninstalled if cancelled/declined

1 participant