Repository navigation
Description
Summary
Follow-up to #18350. That fix blocks the Global Options OK/Apply button while a Posit Assistant install/update check is in flight, so the fresh-profile / None -> Posit and Posit chat-provider paths can no longer persist a selected-but-uninstalled provider.
However, switching the code assistant from GitHub Copilot to Posit AI takes a different path that bypasses that guard. disableCopilot() eagerly persists assistant = "posit" the moment the selection changes -- independent of OK/Cancel and before the install check resolves. Two user actions then leave the exact state #18350 describes: provider selected, addon never installed, completions silently unavailable ("Posit AI: No completions available.").
This affects only the Copilot -> Posit code-assistant transition; it requires copilot_enabled to be true at the time of the switch. None -> Posit and the Posit chat provider are already handled by the #18350 fix.
Steps to reproduce
- In a build where GitHub Copilot is available, set Tools -> Global Options -> Assistant -> Use code assistant to GitHub Copilot (so
copilot_enabledis true). - Reopen Global Options and switch Use code assistant to Posit AI Next Edit Suggestions.
- Before the install/update check resolves and the "Install/Update Posit Assistant" prompt appears, do either:
- (a) click OK (which, after Selecting a code assistant that needs an addon update can leave it uninstalled with no error shown #18350, is blocked with a "Checking for Updates" warning) and then click Cancel; or
- (b) wait for the install prompt and decline it (Cancel/No).
- Reopen Global Options, or type in an R file.
Expected: the assistant reverts to the previous selection (Copilot), or the addon is installed before "posit" is persisted.
Actual: assistant is persisted as "posit" with the addon never installed; completions show "Posit AI: No completions available."
Root cause
In src/gwt/src/org/rstudio/studio/client/workbench/prefs/views/AssistantPreferencesPane.java, when the code-assistant selector changes to Posit the change handler calls disableCopilot(ASSISTANT_POSIT), which eagerly writes the pref:
private void disableCopilot(String newAssistant)
{
// Eagerly disable Copilot so the agent stops immediately
if (prefs_.copilotEnabled().getValue())
{
prefs_.copilotEnabled().setGlobalValue(false);
prefs_.assistant().setGlobalValue(newAssistant); // <-- persists "posit"
prefs_.writeUserPrefs((completed) -> {}); // <-- independent of OK/Cancel
}
}writeUserPrefs sends setUserPrefs immediately, so assistant = "posit" is committed as soon as the user picks Posit -- before the install check and regardless of how the dialog is later dismissed. Two concrete outcomes:
- Cancel after a blocked OK. The Selecting a code assistant that needs an addon update can leave it uninstalled with no error shown #18350 guard blocks OK (via
validate()), but Cancel is not gated. The dialog closes withassistant = "posit"already persisted and nothing installed. - Declining the install prompt is a no-op revert.
checkPositAssistantInstallationcapturespreviousAssistantValue = prefs_.assistant().getGlobalValue()afterdisableCopilotalready set it to"posit". On decline,revertPositAiPreferencecomputesrevertTo == "posit" == selAssistant_.getValue()and early-returns without reverting, so it stays"posit".
(Method/line references are relative to the #18350 fix branch: disableCopilot ~L1031, its ASSISTANT_POSIT call ~L497, the previousAssistantValue capture ~L1080, and the revert early-return ~L1344.)
Suggested fix
Some combination of:
- Capture the pre-switch assistant value before
disableCopilot()mutates the pref, and thread it through so the revert restores the prior selection. Note: a correct revert to Copilot must also restorecopilot_enabled = true(whichdisableCopilotset to false), sorevertPositAiPreference(or its caller) needs to handle re-enabling Copilot, not just theassistantpref. - And/or defer the eager
assistantwrite indisableCopilotuntil the install check resolves (or untilonApply), so the Copilot -> Posit transition also respects the OK /validate()gate instead of committing immediately.
Cover the fix with a test -- ideally the same @ai E2E scenario proposed for #18350, but starting from Copilot rather than None.
Notes
- Found during code review of the Selecting a code assistant that needs an addon update can leave it uninstalled with no error shown #18350 fix.
- The eager write in
disableCopilotpredates Selecting a code assistant that needs an addon update can leave it uninstalled with no error shown #18350; this is a coverage gap of that fix rather than a regression it introduced.
Activity
Revert the assistant selection when a Posit Assistant install is decl…
merge main into codex/minimize-news-entries