Repository navigation
fix readr Import Dataset preview on Windows (escape generated R path) + console-wait reliability - #18048
Conversation
Addresses #17985. The readr Import Dataset preview e2e test soft-skips on Windows CI; the captured error is the preview subprocess reporting the CSV "does not exist", not a subprocess-start failure as the issue title implies. - ensureCsvWritten(): poll file.exists() after the writeLines and retry the write once, throwing a setup-level error rather than letting the preview time out after 45s when the CSV never landed. - awaitPreviewOrSkip(): probe getwd()/file.exists()/list.files() via a new ConsolePaneActions.evalRString() helper and fold the result into the fixme/throw reason, so a Windows CI run distinguishes a missing file from one present-but-invisible to the separate preview process. The test.fixme guard stays until a Windows CI run confirms the write-verify stabilizes it.
The writeLines used executeInConsole({wait:true}), whose waitForConsoleIdle
only polls for the absence of the busy class and can return in the
submit->busy gap before R has run the command -- so the write's completion
was never actually awaited. The preview subprocess could then open the CSV
before writeLines wrote it, yielding vroom's "<csv> does not exist" (the
suspected #17985 root cause).
Replace ensureCsvWritten with writeCsvConfirmed: run writeLines + file.exists
in one block via evalRLogical, which reads R's printed [1] TRUE/FALSE -- a
real post-execution completion signal. Retries once before throwing.
🍎 macOS Desktop E2E · ARM64❌ 6 test(s) failed
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · macos-26 ARM64 · commit |
waitForConsoleIdle only samples the rstudio-console-busy class, so it can observe a spuriously-idle console in the submit->busy gap and return before R runs the command -- the root-cause race behind #17985's intermittent "<csv> does not exist" preview failure (the writeLines hadn't run when the preview subprocess opened the file). Expose a race-free completion signal on the automation bridge: ApplicationAutomation now keeps window.rstudio.console.promptCount, a monotonic counter bumped on each ConsolePromptEvent (R returning to its top-level prompt). executeInConsole captures it before submitting and waits for it to advance, falling back to the busy-class wait only when the counter is absent (older binaries). This fixes every wait:true caller with no per-site change. - ApplicationAutomation.java: registerConsole() + promptCount JSNI surface - console_pane.page.ts: getConsolePromptCount / waitForConsoleCommandComplete; both executeInConsole paths capture-then-wait on the counter - commands.ts: type the new console bridge; add CommandEntry.isVisible() (the bridge already exposes it) and drop the now-needless command-lookup casts - import_dataset.test.ts: drop the writeCsvConfirmed workaround -- a plain executeInConsole({wait:true}) is now a sufficient gate; keep the failure diagnostics and fixme guard pending Windows CI confirmation
🪟 Windows Desktop E2E · Server 2025 x64❌ 6 test(s) failed
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · Windows Server 2025 x64 · commit |
The real Windows cause of the readr import-preview failure was not a wait
race: sandbox.dir comes back from R's tempfile() with backslashes, and the
test embedded it into R source as a raw "${csvPath}". R parses backslashes as
escape sequences, so \p (in "pw-sandbox") is a hard parse error and the
writeLines never runs -- the CSV is never written and the preview reports
"does not exist". Reproduced locally: '\p' is an unrecognized escape in
character string. macOS uses forward-slash sandbox paths, so it never hit it
(and neither did local validation).
- import_dataset.test.ts: build the writeLines path with rPathLiteral (the
existing helper other tests already use: normalizes to forward slashes,
which R accepts on Windows, and quotes safely). Normalize the file-chooser
fill path too. Drop the test.fixme guard and the fs-probe diagnostic that
were built around the earlier (incorrect) wait-race hypothesis.
- console_pane.actions.ts: remove the now-unused evalRString helper.
The prompt-count bridge work in the prior commit remains a separate, genuine
console-wait reliability improvement -- not the #17985 fix.
Verified: import_dataset 2/2 on the macOS dev build; tsc clean.
createSandbox passes tmpdir = PW_SANDBOX (a Node path) to R's tempfile(), so on Windows the returned workdir is a backslash path. Embedding that into generated R code breaks parsing (\p, \w are unrecognized escapes) -- the root cause of the import-preview failure. The import_dataset test now routes its path through rPathLiteral, but normalize at the source too so every test that interpolates sandbox.dir into R is protected: normalizePath(winslash = "/") returns forward slashes (which R accepts on all platforms) and matches R's own getwd() form. Note: setting TEMP/TMPDIR would not help here -- the sandbox path comes from PW_SANDBOX via an explicit tmpdir=, not R's default tempdir(). Verified: import_dataset 2/2 on the macOS dev build (workdir resolves to a forward-slash path); tsc clean.
Code review findingsActionable items from an automated multi-agent review (code, tests, comments, error handling). The path-escaping fix and the prompt-count counter are correct on the main path; the items below are the actionable residue. Several concerns raised during review were disproved and are omitted (the Important
Suggestions
|
gtritchie
left a comment
There was a problem hiding this comment.
LGTM! Some nit-picky low pri feedback on comments, etc.
|
Thanks for the thorough review -- all six items addressed in bb95c01. 1. Stale 2. Silent null-counter fallback -- added a one-time 3. Counter bumped on continuation/nested prompts -- went a step beyond the doc-only suggestion. The 4. Duplicated rationale -- trimmed the 5. Stale 6. Redundant Verified |
…8061) executeInConsole({wait:true}) waits for window.rstudio.console.promptCount to increase. The bump was gated on !prompt.getBusy(), so it only fired at the top-level prompt. A command that parks at an interactive sub-prompt (browser()/Browse[N]>, readline(), menu()) never returns to top level on its own, so the wait hung until timeout -- this broke the debugger e2e tests, whose commands hit a breakpoint and enter Browse mode. Bump on every ConsolePromptEvent instead. This is safe: a single submission's intermediate continuation (+) and inter-statement prompts are serviced from the server's buffered, line-split console input (SessionConsoleInput.cpp rConsoleRead -> popConsoleInput) without firing a client kConsolePrompt event, so a new prompt event is always a genuine "R is waiting for input again" point, never a mid-expression state. One-shot expressions still fire exactly one event at completion (the #18048 race stays fixed); interactive/debugger commands now resolve at their settle point instead of hanging.
Addresses #17985.
Root cause (corrected)
The readr Import Dataset preview e2e test failed on Windows CI. The real cause is not a subprocess-start failure (as the issue title implies) or a console wait race (an earlier hypothesis in this PR) -- it's an unescaped path in generated R code:
The test wrote the CSV via
writeLines(..., "${csvPath}"), wherecsvPathembedssandbox.dir. On Windows that path comes back from R'stempfile()with backslashes (D:\a\rstudio\rstudio\pw-sandbox\pw_sandbox_*\workdir_*). Embedded raw into R source, the backslashes are escape sequences --\r/\abecome control chars and\p(pw-sandbox) /\w(workdir) are a hard parse error:So
writeLinesnever runs, the CSV is never written, and vroom'scheck_pathreports the file "does not exist." macOS uses forward-slash sandbox paths, so it never reproduced (nor did local desktop-dev validation).Fix
Use the existing
rPathLiteralhelper (utils/r.ts-- normalizes\->/, which R accepts on Windows, then quotes), the same idiom other tests already use (project_id,project_editor_theme, ...). Dropped thetest.fixmeguard and the diagnostic scaffolding built around the earlier wait-race hypothesis.Also in this PR: console-wait reliability (independent improvement)
While investigating, I found a genuine latent race:
executeInConsole({wait:true})useswaitForConsoleIdle, which only samples therstudio-console-busyclass and can return in the submit->busy gap before R runs the command. This is not what broke #17985, but it's a real footgun for ~456 callers. Fixed by exposingwindow.rstudio.console.promptCounton the automation bridge (a monotonic counter bumped onConsolePromptEvent);executeInConsolenow waits for the count to advance, with a busy-class fallback for older binaries. Plus a small typing cleanup (CommandEntry.isVisible()).Verification
import_dataset2/2 on the macOS dev build;rs_value_contents4/4 (console-heavy, exercises the new wait path);tsc --noEmitandant javac/ant draftclean.