Repository navigation
Description
Summary
When the user interrupts R, the client drops its notebook chunk queue (NotebookQueueState.clear() from TextEditingTargetNotebook.onInterruptStatus), but nothing tells the server. NotebookQueueState.clear() only clears local state; the per-unit update_notebook_exec_queue delete RPC is sent only by dequeueChunk(). The server's NotebookQueue keeps its units, and module_context::events().onUserInterrupt -- which the server queue subscribes to in order to clear itself -- has no emitter anywhere in the codebase.
Today the server usually stops anyway because the running chunk's execution context records the interrupt as an error, and NotebookQueue::process() then clears the whole queue on the next prompt. That is the only cancellation path on the server. A chunk that is queued but not yet running has no context, so if nothing is running when the interrupt lands, the queued chunks survive on the server and execute at the next console prompt while the client shows them as cancelled.
How this shows up
With #19236 fixed (#19237), the client's execute_notebook_chunks request is served while R runs code from the idle event loop (e.g. shiny::runApp() scheduled with later::later()). NotebookQueue::process() defers because R is executing. Interrupting the callback then leaves the deferred chunk queued on the server; the client has dropped it. #19237 deliberately does not retry deferred work, so the chunk waits for the next console prompt and runs then, with its output appearing in the notebook.
Proposed fix
- Client:
NotebookQueueState.clear()sends a newclear_notebook_exec_queueRPC (or the per-unit deletesdequeueChunk()already sends). - Server: the RPC only marks the queue cancelled. The module-level entry points into the queue (the prompt hook, the after-response processing, any retry) check the flag before touching
s_queueand drop it there. The queue must not be deleted from inside its own code: chunk-option evaluation can open a console read, an incomplete chunk raises an R error (longjmp past any RAII guard), and asynchronous engines call back into it. An attempt to do the teardown from the server side alone inside keep serving requests while r runs code from the idle event loop #19237 ran into each of those and was withdrawn. - With cancellation reliable, the idle-only retry of deferred work that keep serving requests while r runs code from the idle event loop #19237 removed can come back, so a chunk queued behind an idle-loop callback runs as soon as the callback returns instead of at the next prompt.
Activity
a chunk deferred behind an idle-loop callback waits for the next prompt
keep serving requests while r runs code from the idle event loop (#19237