Skip to content

RStudio Desktop drops command-line flags when restarting itself in Playwright tests #17519

Description

@ronblum

System details

RStudio Edition : Desktop
RStudio Version : 2026.05.0
OS Version      : Windows 11, but applies to all platforms
R Version       : N/A

Steps to reproduce the problem

  1. Launch RStudio Desktop from the command line with any flag.

    Windows (PowerShell):

    & 'C:\Program Files\RStudio\rstudio.exe' --remote-debugging-port=9254

    macOS:

    /Applications/RStudio.app/Contents/MacOS/RStudio --remote-debugging-port=9254
    

    Linux:

    /usr/bin/rstudio --remote-debugging-port=9254
    
  2. Confirm the flag took effect. For --remote-debugging-port=9254, open a browser and visit http://localhost:9254/json/version.

    • The Chrome DevTools Protocol endpoint responds.
  3. Trigger an RStudio restart by invoking a command that restarts the IDE -- for example, install Posit Assistant, then invoke "Uninstall Posit Assistant" from the command palette and confirm.

  4. After RStudio comes back up, check the same endpoint at http://localhost:9254/json/version.

    • The endpoint no longer responds. The flag was not carried over to the restarted process.

Describe the problem in detail

When RStudio Desktop restarts itself, the new process is spawned with a freshly built argv, not by inheriting the original command-line flags. The relevant code is in src/node/desktop/src/main/application-launch.ts, where launchRStudio() constructs:

const argv = app.isPackaged ? [] : [process.argv[1]];

This drops all flags from the original launch. Any flag passed at startup -- --remote-debugging-port, --enable-logging, --user-data-dir, etc. -- is lost across a restart.

This affects test infrastructure. The Playwright test suite at e2e/rstudio launches RStudio with --remote-debugging-port=<N> so Playwright can attach over CDP. Tests that exercise an IDE restart (e.g. the Uninstall Posit Assistant flow) lose their CDP endpoint mid-test. The fixture works around this by snapshotting RStudio process IDs, killing the non-CDP self-respawn, and launching a new CDP-enabled instance.

Other flags exist that a developer might pass at startup -- e.g. --enable-logging, --user-data-dir -- and these are similarly lost on restart.

There is no observable effect on users who launch RStudio by clicking the icon, because they don't pass flags to begin with.

Describe the behavior you expected

Flags from the original launch would carry over to the restarted process, so that anything configured at first launch (debugging endpoint, log destination, user data dir) stays in effect across restarts.

Implementation note: Possibly forward CLI flags (anything starting with -) but continue to resolve positional arguments (working directory, project file) from the restart options as today.

Activity

  1. added
    new
    and removed
    new
    on May 4, 2026
  2. self-assigned this
    on May 4, 2026
  3. added theissue type on May 4, 2026
  4. removed their assignment
    on Aug 13, 2026
  5. added this to the Backlog milestone on Aug 13, 2026
  6. gtritchie commented on Oct 27, 2026

    @gtritchie
    Member

    Evaluation against main at 6775de7.

    Still true

    launchRStudio() builds a fresh argv and forwards only --automation-agent.

    launchRStudio() serves both restarts and new concurrent instances:

    • Restart: doRestart() quits, then fires OpenProjectNewWindowEvent → Projects.onOpenProjectNewWindow → desktop_open_project_in_new_window → launchRStudio().
    • New instance alongside the current one: Open Project in New Session, New Session, the macOS dock's "New RStudio Window", and opening a .Rproj while RStudio is running.

    Out of date

    Proposed fix

    Forward the switches from process.argv, skipping the executable, the dev-mode ., and positional arguments. Project and working directory keep coming from options and the environment, as today.

    • Stop at a bare --: Chromium treats everything after it as plain arguments. planOzoneRelaunch already handles this and is the pattern to follow.
    • Exclude one-shot switches:
      • --run-diagnostics would rerun diagnostics in every new window.
      • --session-exit, --startup-delay and --session-delay are debugging aids.
      • --version, --version-json and --help exit before any relaunch, so they need no handling.
    • Delete the explicit --automation-agent push: generic forwarding covers it. The electron-flags config can also add that switch, but the relaunched instance reads that config itself. The existing test at application-launch.test.ts:85 enables automation with app.commandLine.appendSwitch, so it needs rewriting to stub process.argv.
    • Side effects:
      • --user-data-dir would also reach new-window launches. Today, Open Project in New Session during a test starts an instance on the default Electron user data.
      • Dev builds would stop losing --no-sandbox on relaunch.

    Caveat: --remote-debugging-port

    Forwarding this flag may not keep the CDP endpoint up:

    app.relaunch() + app.exit() would avoid the race, since Electron starts the new instance only after the current one exits. It isn't a drop-in, though:

    • It needs a dedicated restart IPC instead of the open-in-new-window path.
    • It doesn't work in dev builds: electron-forge stops its dev server when the first process exits (electron-flags.ts:194).

    The plain forwarding change looks like the right first step. Whether the CDP port survives a restart needs testing, on Windows in particular.

    Unrelated, not investigated

    With no project open, doRestart() passes Projects.NONE ("none") as a project file path. launchRStudio() then sets RS_INITIAL_WD to path.dirname("none"), which is ..

  7. self-assigned this
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions