Skip to content

Keep a remembered R following your default R after interpreter discovery - #16579

Merged
juliasilge merged 1 commit into
mainfrom
r-affiliation-keep-current-flag
Oct 9, 2026
Merged

juliasilge merged 1 commit into
mainfrom
r-affiliation-keep-current-flag

Conversation

@juliasilge

Copy link
Copy Markdown
Member

Fixes #15992

This PR fixes one of two causes that make new windows start an older R version instead of the default R. The work in #16505, which merged today, fixes the other cause. Thank you so much, @dhruvisompura! 🎉

Background

Positron remembers the R version that you used in each workspace. Windows with no folder open share one stored R for the profile. For R, the stored record includes a current flag. When this flag is true, positron-r starts the default R at launch instead of the stored binary. Thus the stored R changes when you change the default R, for example with rig default.

What #16505 fixed

The interpreter discovery cache sometimes dropped interpreters, frequently both R entries. The cache reloaded its own saves as if a different window wrote them. Because of this, a new R 4.6 installation did not show in the session picker. Users then started the older R, and Positron stored it. #16505 stops the cache from reloading its own saves. It also fixes expired cache entries that did not recover.

What this PR fixes

When an interpreter registers during discovery, onDidRegisterRuntime refreshes the stored record with the new metadata. #14813 added this step to remove stored ~/ paths but it turns out the step also replaced extraRuntimeData, which belongs to the language extension.

The R runtime ID uses only the binary path and the version, so the older R keeps the same ID after the default R changes. Discovery then reports the older R with current: false, and the refresh writes that value into the stored record. After that, all new windows start the older R.

This PR keeps the stored extraRuntimeData when it refreshes the record. The other fields refresh as before, so the ~/ path fix continues to work. When a session starts, Positron continues to save the full metadata of that session.

The refresh occurs only when no R console starts at launch, for example when the R startup behavior is manual. A launch that starts R does not change the flag. I believe this is why the problem was so difficult to reproduce!

This PR does not repair a record that already has current: false. Positron cannot tell this record from a user choice of a non-default R. To reset the record, folks will need to start the R version that they want one time.

Release Notes

New Features

  • N/A

Bug Fixes

Validation Steps

@:interpreter @:sessions

A new unit test in runtimeStartup.vitest.ts covers the fix. To test manually on macOS, you need rig and two R versions:

  1. Quit Positron totally. Run rig default 4.4-arm64 (or a different older R that you have).
  2. Open a window with no folder (the "no workspace" state). Start R 4.4.
  3. Run 1 + 1 in the console, then quit Positron.
  4. Run rig default 4.6.
  5. In your user settings.json, set "interpreters.startupBehavior": "manual" in the [r] and [python] blocks. (Probably ask your favorite AI agent to do this, so you don't have to open Positron.)
  6. Open a window with no folder. Do not start a session.
  7. Wait until the session picker shows your R versions, then quit Positron.
  8. Remove the settings from step 5 (again, probably via your favorite AI agent rather than from within Positron). Open a window with no folder.
  9. Make sure that R 4.6 starts. Before this fix, R 4.4 starts.

You can see the stored record after step 7. Quit Positron, then run this command. With the fix, the output shows current= True:

sqlite3 ~/Library/Application\ Support/Positron/User/globalStorage/state.vscdb \
  "select value from ItemTable where key='positron.affiliatedRuntimeMetadata.v2.r'" \
  | python3 -c "import sys,json; a=json.load(sys.stdin); m=a['metadata']; e=m['extraRuntimeData']; print(m['runtimeName'], 'current=', e.get('current'))"

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:interpreter @:sessions @:console

Why these tags?
Tag Source
@:critical Always runs (required)
@:interpreter PR description
@:sessions PR description
@:console Changed files

More on automatic tags from changed files.

readme  valid tags

@juliasilge
juliasilge marked this pull request as ready for review October 9, 2026 21:46

@dhruvisompura dhruvisompura left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good and the repro steps worked for me! 🚀

I wanted to check that I understand what current is doing since its new to me.

When you start an R session, the affiliated runtime record saves whether that R was the system default at that moment (current). positron-r then uses that flag to decide what to start next time:

  • current: true -> you started the default R, so start whatever the default R is now. If I started 4.5 while it was my default and then run rig default 4.6, the next window starts 4.6.
  • current: false -> you started an R that wasn't the default, so assume you chose it on purpose and start that exact R again, even if the default changes.

So the bug was discovery overwriting a record that should have had current: true with [false](current:). This caused the default R to not start when it should have.

Am I understanding this correctly?

@juliasilge

Copy link
Copy Markdown
Member Author

@dhruvisompura, yep, that is correct!

The idea here is that for R users, they are most often going to want whatever is "current" to start, even if they ran a different version of R before in any given workspace. This is a different behavior than Python takes, since the ecosystem is so different in terms of whether you just work with latest vs. pinning versions.

@juliasilge
juliasilge merged commit 34d5646 into main Oct 9, 2026
34 checks passed
@juliasilge
juliasilge deleted the r-affiliation-keep-current-flag branch October 9, 2026 23:55
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

R interpreter discovery bug

2 participants