Skip to content

sess integration lost when VS Code restores an R terminal #1799

Open

Description

@grcatlin

After reopening VS Code with an R terminal still present, sess may fail to reconnect. View() and plots then open in native windows instead of VS Code. This reproduces on macOS as described below.

  1. Open a directory in VS Code - be sure there are no active terminals.
  2. Create an R terminal r.createRTerm. [sess] Connected to VS Code should be printed. View() and plot() should work as expected.
Image
  1. Quit VS Code without closing the active R terminal. Or swap to a different directory workbench.action.openRecent (ctrl + r) without closing the active R terminal.
  2. Open VS Code again or ctrl + r back to the original directory, sess shows an IPC error.
Image
  1. Run the same commands as earlier. Now, XQuartz pops up instead.
Image

Originally posted by @grcatlin in #1794

As I mentioned earlier, I can fix it by killing the old terminal and then making a new R terminal. Oddly, I cannot reproduce this on Windows. The same error occurs using both arf (above) and the base R console.

Activity

  1. Fred-Wu commented on Sep 29, 2026

    @Fred-Wu
    Contributor

    How does you R process survive after closing VS Code?

    Cannot speak for arf, but I don't think R's native console can survive from VS Code shutdown and reopen. The behaviour is expected because the sess connection is gone completely in this case.

    At the moment, I think sess reconnection is only for VS Code reload, not VS Code completely restart.

  2. grcatlin commented on Sep 29, 2026

    @grcatlin
    ContributorAuthor

    You're right: R does not survive a full VS Code shutdown. VS Code restores the terminal, not the R process itself.

    VS Code distinguishes process reconnection on window reload from process revive on application restart. With persistent terminal sessions enabled, revival relaunches the terminal process using its saved environment. In this case that starts a new R process, whose profile calls sess::connect() with the old SESS_DISCOVERY_FILE. The file may still name the previous extension host's IPC endpoint, or the new endpoint may not be listening yet. The one-shot startup connection fails, leaving View() and plots outside VS Code. So this is a startup/recovery problem as well as the existing live-process reconnection case.

  3. Fred-Wu commented on Oct 3, 2026

    @Fred-Wu
    Contributor

    So the fix is to connect to a new R session automatically without emitting the message.

  4. renkun-ken commented on Oct 4, 2026

    @renkun-ken
    Member

    #1805 implements a native vscode Interactive window for R that survives full vscode reload and restart.

  5. renkun-ken commented on Oct 6, 2026

    @renkun-ken
    Member

    #1805 / #1830 now provide persistent arf Interactive sessions that retain their R process and history across full VS Code exit/reopen. That is available for workflows needing process persistence.

    The original terminal-revival problem here remains distinct: VS Code starts a new R process with saved environment/discovery metadata. In current sess::connect(), an initial socket connection failure still returns without starting the reconnect loop. The reconnect tests cover a previously connected process losing its endpoint; they do not establish recovery from this initial revival failure.

    Keeping this open for automatic recovery of an ordinary restored R/arf terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions