Repository navigation
Done
Feature
Copy link
Description
Problem Statement
Reported in posit-dev/assistant-feedback#114: while a Shiny app is running in the Console, Posit Assistant appears to hang. The agent's runtime/executeCode request waits for a Console that won't free up, and nothing tells the user why.
What happens now:
runtime/executeCodequeues the request until R is idle (Prevent chat code execution when R console is busy #16875). The user's code is not interrupted.- The queue is drained by idle-only delayed work (
processPendingExecution()inSessionChat.cpp), and the request's timeout and the 60 s queue cap are checked only when that work runs. Whileshiny::runApp()blocks, it never runs, so RStudio never answers the request. - The Assistant stops waiting when its own request timer fires (30 s by default), and the model gets a generic
Request runtime/executeCode (id: N) timed out after 30000ms. It has no way to tell that the Console is busy, so it may retry and wait again. - The chat pane shows nothing. Unless the user notices the app is still running, the Assistant just looks stuck.
Proposed Behaviour
Changes in RStudio only, so they work with current Posit Assistant releases:
- Show a notification in the chat pane. When an agent request has been queued behind the user's code for a few seconds (so a short
Sys.sleep(2)doesn't flash it), show a notification bar in the chat pane, using the existingChatPanenotification panel. For example: "Posit Assistant is waiting for the R console, which is running a Shiny app." When RStudio can't tell that a Shiny app is running, use generic wording ("busy running your code"). Remove the bar when the request starts, is answered, or is canceled. - Add a Stop button. The bar has a Stop App (or Interrupt R) button that interrupts the Console, as the Console's Stop button does. After the interrupt, the queued request runs and the agent continues without seeing an error. The Console is interrupted only when the user clicks the button.
- Answer the request before the Assistant's timer runs out. If the Console is still busy as the request's
timeoutnears, RStudio answers it with an error that says why it didn't run and what to do next. For example: "Not run: the R console is busy running a Shiny app the user started. Ask the user to stop it, then try again." The request is removed from the queue, so it doesn't run later when the Console frees up. This needs a check that runs while R is busy, not only from the idle-only drain.
QA Notes
- Run a Shiny app in the Console, then ask Posit Assistant to run some R code. The bar appears after a few seconds, and clicking Stop App stops the app and lets the agent's code run.
- Leave the app running instead. The agent receives the busy-Console error before its request times out, the bar goes away, and the agent's code doesn't run when the app is later stopped.
- Run
Sys.sleep(2)and ask the agent to run code. The request waits and runs without the bar appearing. - Run
Sys.sleep(60)and ask the agent to run code. You see the generic wording, not the Shiny wording.
Activity
Spare waits on user code from the queue cap; detect user code directly
Put the popped-out notice before the chat in focus order
Move the popped-out notice's DOM layer before the chat frame
Show when Posit Assistant's code waits on a busy Console, and let the…