From eff5619a519a660e7ebe764470bf93ba970a12b4 Mon Sep 17 00:00:00 2001 From: "pascal.tremblin" Date: Wed, 2 Dec 2026 12:13:01 +0100 Subject: [PATCH] studio: the server of VS Code Remote-SSH is not code-server On Adastra, in a VS Code Remote-SSH window, the canoP icon opened http://localhost:62863/proxy/8090/... instead of the port of the studio that VS Code forwards. The server that VS Code Remote-SSH runs on the node is started by a script named code-server (~/.vscode-server/cli/servers//server/bin/code-server): the studio took it for code-server and gave an address of its port proxy, which that server does not have. - code_server_proxy (canop_app.py): a process whose program is in the directory of the VS Code server (canop_launch.vscode_server_program) is not code-server, and VSCODE_PROXY_URI counts only when a code-server of the user runs on the node. - VS Code extension (0.1.3): in a Remote-SSH window (vscode.env.remoteName "ssh-remote") it always lets VS Code forward the port of the studio (asExternalUri), whatever code-server address the studio gives. - MCP bridge: no code-server address in a Remote-SSH window. Tested: on ruche with a running code-server, the same address as before; with only a process of the VS Code server (simulated from the processes seen on Adastra), the former detection gives localhost:62863/proxy/..., the new one no address, also with VSCODE_PROXY_URI set. The studio computes its addresses at start: restart it (canop-studio --stop, then the canoP icon) and reinstall the extension (canop-studio --install-vscode). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ tools/trame/canop_app.py | 18 ++++++++++++------ tools/trame/canop_launch.py | 11 ++++++++++- tools/trame/canop_mcp_bridge.py | 2 +- tools/vscode/extension.js | 5 +++-- tools/vscode/package.json | 2 +- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd8d3c2..eaee7cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ The user-visible changes of canoP, by version (see `CONTRIBUTING.md` for the ver OpenMP and HIP. - canoP studio: GPUs can also be requested with `--gpus-per-node` (Slurm request `gpus-per-node`), as Adastra requires. +- canoP studio in VS Code Remote-SSH: the studio no longer takes the server of VS Code + (`~/.vscode-server/.../bin/code-server`) for code-server, whose address the canoP icon opened instead + of the port of the studio that VS Code forwards (extension 0.1.3). - canoP studio in English or in French: a FR/EN switch in the top bar, saved in the settings. New installations start in English; studios set up before keep French. - Tutorial of canoP studio in the documentation: the build, a run of the blast example, and a diff --git a/tools/trame/canop_app.py b/tools/trame/canop_app.py index 8bccf06..8a41625 100644 --- a/tools/trame/canop_app.py +++ b/tools/trame/canop_app.py @@ -47,7 +47,7 @@ from vtkmodules.vtkFiltersParallel import vtkMergeBlocks # noqa: E402 from vtkmodules.vtkIOXdmf2 import vtkXdmfReader # noqa: E402 -from canop_launch import CONFIG_DIR # noqa: E402 (in the clone or for the account) +from canop_launch import CONFIG_DIR, vscode_server_program # noqa: E402 (CONFIG_DIR: in the clone or for the account) SETTINGS_FILE = os.path.join(CONFIG_DIR, "settings.json") # arrays written by kalypsso for debugging the mesh, hidden from the field list @@ -1524,12 +1524,11 @@ def code_server_proxy(): """URL pattern of the code-server port proxy ('.../proxy/{{port}}/'), or None. None when no code-server of this user runs on this node: its proxy only reaches ports of the node - it runs on. + it runs on. The server of VS Code Remote-SSH (~/.vscode-server/.../bin/code-server) is not one: it + has no proxy, and VS Code forwards the port of the studio instead. """ - uri = os.environ.get("VSCODE_PROXY_URI", "") - if "{{port}}" in uri and uri.startswith("http"): - return uri bind = None + found = False # a running code-server of this user, given --bind-addr on its command line for pid in os.listdir("/proc") if os.path.isdir("/proc") else []: if not pid.isdigit(): @@ -1541,8 +1540,9 @@ def code_server_proxy(): argv = fd.read().decode(errors="replace").split("\0") except OSError: continue - if not any("code-server" in a for a in argv[:2]): + if not any("code-server" in a for a in argv[:2]) or any(vscode_server_program(a) for a in argv[:2]): continue + found = True for i, a in enumerate(argv): if a == "--bind-addr" and i + 1 < len(argv): bind = argv[i + 1] @@ -1550,6 +1550,12 @@ def code_server_proxy(): bind = a.split("=", 1)[1] if bind: break + if not found: + return None + # the address of code-server as the browser sees it, given by code-server to its terminals + uri = os.environ.get("VSCODE_PROXY_URI", "") + if "{{port}}" in uri and uri.startswith("http"): + return uri if not bind: return None return "http://%s/proxy/{{port}}/" % bind diff --git a/tools/trame/canop_launch.py b/tools/trame/canop_launch.py index eb43059..04fdc2f 100644 --- a/tools/trame/canop_launch.py +++ b/tools/trame/canop_launch.py @@ -33,6 +33,15 @@ _REMOTE_SERVER = re.compile(r"/\.(vscode-server|vscode-server-insiders|cursor-server|windsurf-server)/") +def vscode_server_program(path): + """True when path is in the directory of the server that VS Code Remote-SSH (or a fork) runs on the node. + + That server is not code-server, though its launcher is also named code-server + (~/.vscode-server/cli/servers//server/bin/code-server): it has no port proxy. + """ + return bool(_REMOTE_SERVER.search(path)) + + def vscode_remote(pid=None): """True when the process runs under the server of VS Code Remote-SSH: the program of one of its ancestors is in ~/.vscode-server/ (or that of a fork of VS Code), as the node of the server and of its extension @@ -48,7 +57,7 @@ def vscode_remote(pid=None): ppid = int(fd.read().rsplit(")", 1)[1].split()[1]) except (OSError, ValueError, IndexError): # no /proc (macOS), or the process is gone return False - if _REMOTE_SERVER.search(program): + if vscode_server_program(program): return True if ppid <= 1: return False diff --git a/tools/trame/canop_mcp_bridge.py b/tools/trame/canop_mcp_bridge.py index 005c56f..2df142d 100644 --- a/tools/trame/canop_mcp_bridge.py +++ b/tools/trame/canop_mcp_bridge.py @@ -43,7 +43,7 @@ def _addresses(info, remote=None): """ remote = vscode_remote() if remote is None else remote lines = [] - if info.get("url_code_server"): + if info.get("url_code_server") and not remote: lines.append("via code-server (à ouvrir dans VS Code : Ctrl+Shift+P > Simple Browser: Show) : " + info["url_code_server"]) if remote: diff --git a/tools/vscode/extension.js b/tools/vscode/extension.js index b7d9894..6cc1c51 100644 --- a/tools/vscode/extension.js +++ b/tools/vscode/extension.js @@ -114,8 +114,9 @@ class Panel { } async function browserUrl(info) { - if (info.url_code_server) return info.url_code_server; - // VS Code (remote SSH or local): let it forward the port + // code-server: its port proxy; VS Code (Remote-SSH or local): let VS Code forward the port of the + // studio, even when the studio found a code-server address + if (info.url_code_server && vscode.env.remoteName !== "ssh-remote") return info.url_code_server; const uri = await vscode.env.asExternalUri(vscode.Uri.parse(info.url_direct)); return uri.toString(true); } diff --git a/tools/vscode/package.json b/tools/vscode/package.json index b7bb791..3627204 100644 --- a/tools/vscode/package.json +++ b/tools/vscode/package.json @@ -2,7 +2,7 @@ "name": "canop-studio", "displayName": "canoP studio", "description": "Start canoP studio on the node and open it in the Simple Browser.", - "version": "0.1.2", + "version": "0.1.3", "publisher": "canop", "icon": "media/canop.png", "license": "Apache-2.0 WITH LLVM-exception",