vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

Inability to Attach active R terminal on Compute Nodes in HPC Environment

Open XZhangGit opened this issue 1 year ago • 10 comments

Describe the bug When launching an active R terminal on a compute node within an HPC environment and attempting to attach it using .vsc.attach(), the terminal remains detached with the message "R: (not attached)" displayed. Clicking to attach does not initiate the attachment process. However, on the login node, the active R terminal automatically attaches as expected, likely due to the configuration in ~/.Rprofile. I found a similar issue reported by another user (https://stackoverflow.com/questions/73087813/how-do-i-make-sure-my-r-session-attached-is-using-the-compute-node-instead-of-th), where he mentioned "my data viewer wouldn't be attached and I couldn't view my data in the 'workspace'.", and there hasn't been a solution provided yet.

To Reproduce Steps to reproduce the behavior:

  1. Launch an interactive R on the compute node on HPC.
  2. Run .vsc.attach() in R.
  3. Observe the terminal displaying "R: (not attached)" without successfully attaching.

**Can you fix this issue by yourself? ** No

Please attach setting.json

"r.alwaysUseActiveTerminal": true,
"r.bracketedPaste": true,
"r.sessionWatcher": true,
"r.rterm.option": [],
"r.rterm.linux": "/path/to/radian",

Expected behavior The terminal should attach successfully to the interactive R session on the compute node when .vsc.attach() is called, similar to the behavior observed on the login node where it attaches automatically.

Screenshots Terminal showing "R: (not attached)" when attempting to attach after running .vsc.attach():

Screenshot 2024-06-28 at 23 16 16

Screenshot 2024-06-28 at 23 20 33

Terminal automatically attached on the login node due to ~/.Rprofile configuration:

Screenshot 2024-06-28 at 23 24 46

Environment (please complete the following information):

  • OS: [Linux]
  • VSCode Version: [1.90.2]
  • R Version: [4.3.1]
  • REditorSupport version: [2.8.4]

Thank you!

XZhangGit avatar Jun 29 '24 06:06 XZhangGit

Can also confirm that I encountered the same bug, thanks for raising the issue!

hariesramdhani avatar Jul 01 '24 14:07 hariesramdhani

I am experiencing the same bug and would love a solution. I have no problem attaching an R-session from a login node, but can't attach an R session from an interactive compute node. The option to start an R Terminal works as well, but it uses a login node by default. I haven't been able to figure out why exactly the compute nodes are unable to see/use rlanguageserver options, nor how to modify the R Terminal to be initiated with a non-login node.

krferrier avatar Aug 15 '24 23:08 krferrier

I also report the same problem here. I would appreciate a guide or fix

Alkhawaja95 avatar Nov 28 '24 00:11 Alkhawaja95

I'm also running into the same problem!

I think this is related to these isssues: https://github.com/REditorSupport/vscode-R/issues/469, https://github.com/REditorSupport/vscode-R/issues/552

I guess the tmp folders are different on the login vs. compute nodes, and that's maybe part of the problem.

I've tried to SSH directly into a compute node (and then maybe the paths would be set up correctly), but I haven't been able to get the SSH connection to work.

c-brendel avatar Feb 05 '25 09:02 c-brendel

@c-brendel not directly related to the issue but my current getaway for running R interactively on the compute node is to use jupyter-server, more here https://www.morganlab.co.uk/wiki/working-with-hpc/running-a-jupyter-server

hariesramdhani avatar Feb 05 '25 10:02 hariesramdhani

@c-brendel not directly related to the issue but my current getaway for running R interactively on the compute node is to use jupyter-server, more here https://www.morganlab.co.uk/wiki/working-with-hpc/running-a-jupyter-server

Others seem to use Podman on HPC nodes to run images from the JupyterLab R docker stack[^1] in rootless mode.

[^1]: These images includes code-server, aka Code - OSS.

Cross reference:

  • https://github.com/b-data/jupyterlab-r-docker-stack/issues/5

benz0li avatar Feb 05 '25 10:02 benz0li

@c-brendel not directly related to the issue but my current getaway for running R interactively on the compute node is to use jupyter-server, more here https://www.morganlab.co.uk/wiki/working-with-hpc/running-a-jupyter-server

I was able to follow these instructions to run R interactively on my compute node! Thanks!

c-brendel avatar Feb 05 '25 14:02 c-brendel

I am also facing the same issue here. Using the login node, I created a conda env, installed r-base, and managed packages using renv (used install.packages("renv"), then all subsequent packages installed via renv::install(), including languageserver). I created a settings.json file with the following:

{
    "r.rterm.linux": "/home/lgna/software/miniforge3/envs/scrna_jun2025/bin/R",
    "r.rpath.linux": "/home/lgna/software/miniforge3/envs/scrna_jun2025/bin/R",
    "r.rterm.option": [
        "--no-save",
        "--no-restore"
    ],
    "r.sessionWatcher": true,
    "r.alwaysUseActiveTerminal": true
}

When launching an interactive session via salloc, I must launch R in the active terminal to keep myself inside the job. This leads to R "not attached" and I've had no success attaching it. Interestingly, if I manually click to launch an "R Interactive" or press F1 followed by "R: Create R Terminal", then R successfully attaches, and everything works great BUT the terminal is launched at the login node, which I am not supposed to do.

Lastly, I also tried the following in my .Rprofile:

source(file.path(Sys.getenv(
   if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"
), ".vscode-R", "init.R"))

When using this code on the profile, R does not attach. I click on the R: (not attached) it runs the .vsc.attach() but nothing happens.

Not sure if this is related, but I get the same issue in my WSL/Ubuntu installation. There, all R packages are managed by my conda env. Things work beautifully if "r.alwaysUseActiveTerminal": false, but whenever I set "r.alwaysUseActiveTerminal": true, then R cannot be attached.

Happy to provide more info as needed!

lgn-almeida avatar Jun 04 '25 17:06 lgn-almeida

I wrote a script to force Reditorsupport to launch its interactive terminal in a new job session, with the goal of avoiding the login node. It didn't solve the issue. Not sure if I am missing something on my script, but this could be further evidence that .vsc.attach is having a hard time launching in interactive job sessions?

Here is my code:

#!/bin/bash

# Adjust with your conda env name
ENV_NAME=conda_R

# Load modules or conda init if needed
source ~/software/init-mamba  # or wherever your conda is

# Activate environment
mamba activate "$ENV_NAME"

# Start SLURM interactive session and launch R
srun --time=01:00:00 --mem=4G --ntasks=1 --pty R

My settings.json:

{
    "r.rterm.linux": "/home/lgna/projects/test_r/launch_r_vscode.sh",
    "r.rpath.linux": "/home/lgna/software/miniforge3/envs/conda_R/bin/R",
    "terminal.integrated.env.linux": {
        "R_HOME": "/home/lgna/software/miniforge3/envs/conda_R/lib/R"
    },
    "r.alwaysUseActiveTerminal": false,
    "r.sessionWatcher": true
}

Of note, this time around, I didn't mix conda and renv. Thus, conda is managing all R packages.

lgn-almeida avatar Jun 06 '25 14:06 lgn-almeida

Same issue even now, no matter how I get on the compute nodes, the only R session it would attach to is on the login node.

bio-info-guy avatar Jun 06 '25 21:06 bio-info-guy