Repository navigation
Show when Posit Assistant's code waits on a busy Console, and let the user stop it - #19836
Conversation
While R runs the user's code (a Shiny app, or anything else), a
runtime/executeCode request waits in the queue, which drained only when
R was idle. RStudio never answered it, so the Assistant's own timer gave
up with a generic timeout and the chat pane showed nothing.
Background processing, which runs while R is busy, now checks the queue
when no agent code is running:
- After a request has waited 3 s, a chat_console_wait event shows a bar
in the chat pane with a button that interrupts R ("Stop App" when a
Shiny app has launched since the last console prompt, "Interrupt R"
otherwise). It is announced to screen readers.
- Shortly before the timeout the request sent (timeout - min(5 s,
timeout / 5)), the request is answered unrun with an error saying the
Console is busy and what to ask the user, and removed from the queue.
This uses the sent timeout for silent requests too, since the
Assistant's setup request is silent and its timer runs regardless.
Later requests during the same user code are answered at once, so the
Assistant's setup-failure fallback doesn't wait out two more timeouts.
- Canceled requests are answered then rather than at the next idle.
Addresses #19834.
A client that connects while a request waits on the user's code (e.g. after a browser reload) never got the notice: the session sent the chat_console_wait event only when its state changed. Client init now resets the last-sent state, so the next background check sends it. A queued request is now also skipped at drain time once the timeout it sent has passed, not only RStudio's run limit, which is 0 for silent and Run in Console requests. Before, such a request read while R polled and then held past its timeout by code that stopped polling (e.g. native code) still ran at the next idle, after the backend had given up on it. Addresses #19834.
The chat pane loads on demand and drops events that arrive before it does, so the client-init resend from fd844ff could still be lost after a reload. The presenter now fetches the current state with chat_get_console_wait once its event handler is registered, which replaces the client-init reset. fd844ff also expired every queued request by the timeout it sent, which discarded the Assistant's silent teardown when it queued behind agent code that outran its limit, leaving the setup's sink installed. Only requests that waited on the user's code now expire by the sent timeout; others keep the run limit as before. Addresses #19834.
With Posit Assistant in its own window, the notice that its code waits on the user's code appeared only in the main window's pane, which may be hidden. ChatConsoleWaitEvent is now a cross-window event: the presenter forwards each state to the popped-out window, which shows the same bar below its toolbar (pushing the chat down rather than covering it) and announces it through a status region. The window asks for the current state when it opens, so popping out during a wait shows it too. Its button sends an "interrupt-r" action to the main window, which runs interruptR there. Addresses #19834.
A suspended session runs no user code, and a forced suspend can drop the event that would clear the notice, leaving it (and the state sent to the popped-out window) stale after resume. Clear it on suspend, as the readline notice already is. Addresses #19834.
A silent request queued behind the user's code was answered "Not run" and removed, so a teardown that arrived just after the user's code started never ran and left the setup's sink installed, diverting the user's console output. Silent requests are now answered the same way but kept, and run without a response once the console frees, so a teardown never misses the setup it undoes. Drain-time expiry by the sent timeout no longer applies to them either. The queue decision moves into blockedRequestAction(), with tests. Also: count agent executions with a scope guard, wrap two long lines, and shorten the comments the review flagged; the s_agentExecutionsRunning comment no longer claims every busy console is the user's code. Addresses #19834.
The flag that picks the Shiny wording was cleared only by a reported console prompt. A tutorial opened from the Tutorial pane sets it with no prompt after, and prompts restored after idle-loop code aren't reported, so the next long command was described as a Shiny app. Input starts new code, so clear the flag then too. Addresses #19834.
- Don't replace a connection-lost error (and its Restart button) with the notice; hiding the notice later removed the error for good. - In the popped-out window, give the notice its place below the toolbar when it is added, so it never paints over the whole window. - Move the new presenter methods off the readline comment they had split from onConsoleReadCompleted, and wrap a long dispatcher line. Addresses #19834.
A null request id meant "already answered", but the backend's messages may carry a null id on a real request, which then got no response. Pass an explicit respond flag to executeCodeImpl instead. Kept requests also counted toward the 10-request queue limit, so enough retries during one stretch of user code could keep a setup and reject the teardown after it, leaving the setup's sink installed once it ran. The limit now counts only requests not yet answered. Addresses #19834.
From PR review: - The 60 s queue cap rejected a request that had waited on the user's code, after the notice offered to let it run (e.g. no timeout, or a model-chosen 120 s one). Waits on user code are now exempt: a request with a timeout is answered before it runs out, and one without waits. The drain decision moves into drainAction() and queueTimeout(), with tests. - The busy-console check treated any non-idle R as the user's code, including RStudio's own R work for an RPC, where the client isn't busy and the notice's interrupt button does nothing. It now requires console_input::isRunningCode(): console input or an idle-loop handler. - A kept request, already answered, no longer streams its output to the backend, which has closed it. - Correct the comment on where queued cancellations are answered. Addresses #19834.
The notice was appended after the chat frame, so keyboard users had to tab through the whole chat to reach its button. Insert it before the frame, as the pane does. Addresses #19834.
LayoutPanel.insert orders its widgets but appends the new widget's DOM layer, so 1c8be1b left the notice's button after the chat iframe in tab order. Move the notice's layer before the frame's, as ApplicationWindow.showWorkbenchView does; the frame stays put, since moving an iframe reloads it. Addresses #19834.
|
Second look at the three new commits (5120863, 1c8be1b, 3025736). Read only; not built or run. Fixed
No change needed
Left as is
One new nit, not blocking
|
|
On the Reaching it needs two agent requests queued at once behind the user's code (a background task or a second conversation, since the Assistant sends one at a time), the first then running past 60 s once the user's code ends (agent code with the default 30 s limit is interrupted before that), and the second having no timeout or being a silent setup/teardown. The outcome is benign: a request with a timeout still expires by it, because it waited on the user's code; a silent teardown running late keeps it paired with its setup, which is the point of keeping those; and a request without a timeout set no limit, so running once the console frees matches what its sender asked. Clearing the flag would also drop the sent-timeout expiry, so a proper fix would mean tracking time waited behind user code separately from time behind agent code, which isn't worth it for this case. |
RStudio E2E - all platformsAll tests passed!
All platforms - commit |
Fixes #19834.
While R runs the user's code (a Shiny app, or anything else), a
runtime/executeCoderequest from Posit Assistant waits in the queue, which drains only when R is idle. RStudio never answered it, so the Assistant's own timer gave up with a generic timeout and the chat pane showed nothing.What changes
Background processing, which runs while R is busy, now checks the queue whenever R is running the user's code (console input, or an idle-loop handler such as a
later::laterapp) and no agent code:chat_get_console_wait, or a request from the popped-out window).Requests queued behind the agent's own code wait as before. A Run in Console request queued behind the user's code is now answered and dropped like the agent's code, where it previously ran if the console freed within 60 s.
Testing
ChatExecutionDeadlineTests.cpp:busyAnswerDue,waitNoticeDue,blockedRequestAction,queueTimeout,drainAction).Sys.sleep(60): generic wording, Interrupt R, and the generic error.Sys.sleep(2): no bar; the code runs.sink.number()is 0) and the agent's next run uses its normal setup.Review findings not addressed
Automated reviews raised these; each was judged unlikely or low-impact enough to leave as is. Reviewers may disagree.
chat_get_console_waitcould sample "not waiting" just before the 3 s notice becomes due, and if its response arrived after the newerchat_console_waitevent, the bar would stay hidden for that wait. This needs the pane to load (only on page load or first opening) within about one 50 ms background tick of the 3 s mark, and the immediately sent RPC response to be overtaken by an event enqueued a tick later. The agent is still answered and the Console's Stop button still works; a revision counter shared by the fetch and the events wasn't worth it.BusyHandoffstate. Requests removed by the busy-console scan don't go throughBusyHandoff::finished, so a handoff could stay marked held. Reaching that needs the user's code paused inreadline()while a queued agent request runs inside it and another waits, the user's code resuming before the second runs, and later a cancellation duringfile.choose().s_busyAnswerSentis cleared only at idle or while agent code runs, so with Run All or pasted multi-line input, a busy answer during one command makes later requests during the following commands answer at once, without waiting or a notice. The answer is still accurate: the Console is busy with the user's code.Screenshots