Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize affiliated runtimes; ensure that after boot, primary runtime is active #1143

Open
Tracked by #3541
jmcphers opened this issue Aug 23, 2023 · 3 comments
Open
Tracked by #3541
Labels
area: core Issues related to Core category.

Comments

@jmcphers
Copy link
Collaborator

Currently, runtime affiliation with workspaces happens on a per-language level. That is, if you use R and Python in a workspace, we will separately affiliate an R interpreter and a Python interpreter with your workspace, and both will be started when you open the workspace.

However, we don't currently weight or prioritize the runtimes affiliated with the workspace. This means that even in workspaces that are primarily R based, if Python is also affiliated with the workspace, it will start up too, and take over the foreground (since Python currently registers runtimes after R).

We should remember the primary runtime that's affiliated with a workspace, and ensure that one is started first (see #1067), and that others are started in the background and don't take focus.

We don't currently ask users to identify the primary runtime; we could do that ourselves via a combination of heuristics (asking extensions to supply some kind of affinity rating derived from e.g. the project's files/type) and/or inference (noting what runtime typically has the foreground, and which one was active in the last session).

@nealrichardson
Copy link

We don't currently ask users to identify the primary runtime; we could do that ourselves via a combination of heuristics (asking extensions to supply some kind of affinity rating derived from e.g. the project's files/type)

I would think that some very simple heuristics would get you right most of the time. Certain files are always associated with one language, like DESCRIPTION, NAMESPACE, .Rbuildignore, etc. for R; requirements.txt, setup.py, etc. for Python. If you only have files from one list or another, you can assume it's that language.

Context from me: I opened an R package in Positron, no Python in it anywhere, and Positron started the Python console.

@jthomasmock
Copy link
Contributor

We don't currently ask users to identify the primary runtime; we could do that ourselves via a combination of heuristics (asking extensions to supply some kind of affinity rating derived from e.g. the project's files/type) and/or inference (noting what runtime typically has the foreground, and which one was active in the last session).

I think we should have a way for users to explicitly select a primary runtime at the project-level. This could be set by default when using the New Project flow and selecting a specific language. For "folders" or other existing projects, we could have a workspace-level option to set this manually and eventually incorporate it into the richer runtime selector tooling post RC.

The Python extension has a default interpreter and several additional manual fields for various language runtime managers:

Python: Default Interpreter Path

Path to default Python to use when extension loads up for the first time, no longer used once an interpreter is selected for the workspace. See here to understand when this is used

The R extension has a custom path setting, but not a default interpreter:

Positron › R: Custom Binaries

List of additional R binaries. If you want to use an R installation that is not automatically discovered, provide the path to its binary here. For example, on Windows this might look like C:/some/unusual/location/R-4.4.1/bin/x64/R.exe.

In addition to on-disk heuristics such as requirements.txt, lockfiles, renv, etc, it would be nice to eventually track frequency and duration of runtime use.

IE there could be two rich heuristics:

  1. After we have multi-session, how many runtime X are started, how many runtime Y are started, etc. These could be both language (R or Python) and version (4.4 or 3.12, etc)
  2. Duration, aggregate across language and version?

@jennybc
Copy link
Member

jennybc commented Jan 6, 2025

Related to #2659

jmcphers added a commit that referenced this issue Jan 13, 2025
This change eliminates the disorienting startup experience that can
occur when multiple affiliated runtimes exist (or multiple sessions are
running).

Prior to the change, every runtime start or reconnect resulted in the
new session taking over the Console and Variables panes and becoming the
active session. Practically speaking this meant that startup often
showed some flickering as different sessions booted and Positron
switched between them on its own, and the session you wound up with when
startup was finished might not be the one you wanted or expected.

After the change, sessions and affiliated runtimes are ordered, and only
one console session gets to become active. The other sessions are still
started -- they just start in the background. The result is (hopefully)
a calmer startup experience.

Right now, there is no explicit ordering -- we just go by whichever one
was last used. So if you were using Python when you exited, that's what
you should see when you open Positron again; same deal with R.

The implementation works as follows:

- plumb an `activate` flag everywhere we deal with session start events
to keep track of whether the session should be focused/activated after
it starts
- remember the last used time for both sessions (for reconnect/reload)
and affiliations (for new windows)
- start/reconnect to sessions in descending order of last use (i.e. most
recent first)
- at startup, only flag sessions to `activate` if they are the most
recently used

Addresses #1044 and part of
#1143.

### Release Notes

#### New Features

- When multiple languages are being used, prioritize the most recent one
at startup (#1044.)

#### Bug Fixes

- N/A


### QA Notes

- Both affiliations (for new windows) and sessions (for reloading
existing windows) should be checked.
- For a runtime to become the "last used runtime", you generally need to
make a gesture that you want to use the runtime, such as switching to it
in the Console or running some code in the Console

---------

Signed-off-by: Jonathan <[email protected]>
Co-authored-by: sharon <[email protected]>
Co-authored-by: positron-bot[bot] <173392469+positron-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to Core category.
Projects
None yet
Development

No branches or pull requests

6 participants