Skip to content

fix multiline expressions hanging in notebook chunks - #17352

Merged
kevinushey merged 5 commits into
mainfrom
bugfix/multiline-chunk-execution
Apr 7, 2026
Merged

kevinushey merged 5 commits into
mainfrom
bugfix/multiline-chunk-execution

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Addresses #17350.

Summary

  • The isAtTopLevel() replacement for globalContext().nextcontext() in f016ddb returns false during continuation prompts (+ != > ), causing the notebook queue to defer indefinitely instead of sending the next line of a multiline expression.
  • Skip the deferral guard in NotebookQueue::process() when in continuation mode, since R is waiting for input, not executing code.
  • Add automation test for multiline chunk execution with both incomplete-expression (1 +\n2) and open-paren (sum(1,\n2)) cases.

Test plan

  • Open an Rmd or Quarto document with a multiline chunk (e.g. 1 +\n2) and run the chunk — should complete without hanging
  • Verify single-line chunks still execute normally
  • Verify chunks with errors still halt as expected
  • Run BRAT test-automation-rmarkdown.R — new "multiline expressions in chunks execute without hanging" test passes

The isAtTopLevel() replacement for globalContext().nextcontext() in
f016ddb returns false during continuation prompts (the prompt is "+ ",
not "> "), causing the notebook queue to defer indefinitely instead of
sending the next line.

Skip the deferral guard when in continuation mode, since R is waiting
for input to complete the expression, not executing code.

Addresses #17350
@kevinushey kevinushey added this to the Globemaster Allium milestone Apr 6, 2026
@posit-snyk-bot

posit-snyk-bot commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

The ternary mapping RExecutionReady/RExecutionBusy was backwards in the
original code (nextcontext() truthy mapped to Ready, meaning "R is
executing" → "Ready"). The refactor in f016ddb faithfully preserved
this inversion. Fix the condition so isAtTopLevel() → Ready and
!isAtTopLevel() → Busy, matching the enum semantics.

The client currently ignores this value, so no behavioral change.
The underlying issue is that atDefaultPrompt() only matched the default
"> " prompt, treating continuation prompts ("+ ") as non-top-level.
Both are part of R's main REPL loop (hist == 1) where R is waiting for
input, not executing code.

Widen the check from `prompt == defaultPrompt` to `!browsing` (any
non-browse REPL prompt), and rename atDefaultPrompt → atTopLevelPrompt
to reflect the broader semantics. This fixes isAtTopLevel() for all
callers (NotebookQueue, isBusy, EOF handling) without inspecting
R_GlobalContext.
@kevinushey
kevinushey merged commit fabf52b into main Apr 7, 2026
8 checks passed
@kevinushey
kevinushey deleted the bugfix/multiline-chunk-execution branch April 7, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants