posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.82k stars 91 forks source link

Positron Workbench: Going back into a session starts new interpreter env #5267

Open jonvanausdeln opened 2 weeks ago

jonvanausdeln commented 2 weeks ago

System details:

Positron and OS details:

Ubuntu 24 Positron 2024.11.0-140 Workbench 2024.11.0-338.pro1

Interpreter details:

R 4.4.1 Python 3.10.10

Describe the issue:

Going back into an existing Positron session starts a new interpreter environment. This does not happen when just refreshing the tab, only when re-enter the session from Workbench launcher screen.

https://github.com/user-attachments/assets/497e55c6-8e69-4ce0-a1b7-b7af22a699c5

Steps to reproduce the issue:

  1. Start a new Positron Session
  2. Start the R console & create a variable. eg. x <-1
  3. Return to Workbench launcher screen and re-enter session

A new R env is created, losing old data.

Expected or desired behavior:

The session would persist and the R data would still be present

Note.. the terminal pane seems to persist

Were there any error messages in the UI, Output panel, or Developer Tools console?

jmcphers commented 1 week ago
sharon-wang commented 1 week ago

I built Workbench locally from main with the latest state changes and ran with Positron 2024.11.1 build 4.

  • Do recent Workbench state changes fix this? (probably not but worth testing)

Nope :( didn't fix this.

  • Does this reproduce when a folder is open? (the no-folder state is a special case for workbench state)

Yes, this issue still occurs when a folder is open.


If I copy the url of the Positron tab and paste the url in a new tab, the same issue occurs. So there's some state being lost or not getting reloaded properly when we open up an existing Positron session in a new tab.

Will be investigating further.

sharon-wang commented 1 week ago

If I copy the url of the Positron tab and paste the url in a new tab, the same issue occurs.

This is reproducible in Positron Server Web. Pasting the url in a new tab should be more or less equivalent to clicking the session from the Workbench launcher screen.


When running VS Code in Workbench, Jupyter Interactive Console sessions are also lost when re-opening the session from the Workbench launcher screen. Reloading the tab or opening the url in a new tab causes the Jupyter console variables to be lost as well.

Steps:

jmcphers commented 1 week ago

This is happening due to this code:

https://github.com/posit-dev/positron/blob/909d8b64874b46195c29e97177c1b4b249a0d77a/src/vs/workbench/services/runtimeStartup/common/runtimeStartup.ts#L698-L704

It turns out that for Positron on Workbench, it is considered a "new window" whenever we reconnect (probably not a bug), so we're removing all the persisted R and Python sessions when we enter the codepath above, causing Positron to orphan the existing sessions and boot new ones.

We do need some variant of this behavior however! Without it, Positron tries to reconnect to old sessions if e.g. you end your Positron session and start a new one in the same workspace. That's a problem in both Desktop and Server spins of the system.

So the key problem is that we need to save the set of active R and Python sessions that persists within a Positron session but not across Positron sessions in the same workspace. The underlying storage service doesn't have any session scope, so we may need to consult other sources or change the way these are read/written.

jmcphers commented 1 week ago

I took a look at how the Terminal tab handles this, since it solves an almost identical problem, and discovered (to my dismay) that ultimately it works by querying the PtyHost from the front end, e.g. here:

https://github.com/posit-dev/positron/blob/909d8b64874b46195c29e97177c1b4b249a0d77a/src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts#L369

We can't take this approach in Positron (as it stands) since we have insulated the supervisor from the front end too well -- there is no way for the front end to talk to it.

Here are some possible ways around this problem: