Skip to content

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

Closed

Description

@gtritchie

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

  1. In a build where GitHub Copilot is available, set Tools -> Global Options -> Assistant -> Use code assistant to GitHub Copilot (so copilot_enabled is true).
  2. Reopen Global Options and switch Use code assistant to Posit AI Next Edit Suggestions.
  3. Before the install/update check resolves and the "Install/Update Posit Assistant" prompt appears, do either:
  4. 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:

  1. 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 with assistant = "posit" already persisted and nothing installed.
  2. Declining the install prompt is a no-op revert. checkPositAssistantInstallation captures previousAssistantValue = prefs_.assistant().getGlobalValue() after disableCopilot already set it to "posit". On decline, revertPositAiPreference computes revertTo == "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 restore copilot_enabled = true (which disableCopilot set to false), so revertPositAiPreference (or its caller) needs to handle re-enabling Copilot, not just the assistant pref.
  • And/or defer the eager assistant write in disableCopilot until the install check resolves (or until onApply), 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

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions