How to use remote python debugging

Hello,

I have a HA green and cloud. I am trying to debug a custom integration. I am following this guide:
Remote Python Debugger - Home Assistant. My issue is that I am not able to connect to my HA instance using ssh from visual studio code. I am using Mac M1 and able to connect to HA via ssh from mac terminal. However I get the following error in vscode.

[12:15:08.839] stderr> ps: unrecognized option: p
[12:15:08.853] > Exec server process not found

Here is the full log.

[12:15:08.713] > ready: b46f9139005b
[12:15:08.724] > Linux 6.6.20-haos #1 SMP PREEMPT Wed Mar 13 13:09:44 UTC 2024
[12:15:08.724] Platform: linux
[12:15:08.732] > /bin/zsh
[12:15:08.733] Shell: zsh
[12:15:08.733] Creating bash subshell inside "zsh"
[12:15:08.755] > bash version:  5.2.21(1)-release
[12:15:08.778] > b46f9139005b: running
[12:15:08.808] > Found existing installation at /root/.vscode-server...
> Starting VS Code CLI... "/root/.vscode-server/code-903b1e9d8990623e3d7da1df3d33db3e42d80eda" command-shell --cli-data-dir "/root/.vscode-server/cli" --on-port --parent-process-id 386 &> "/root/.vscode-server/.cli.903b1e9d8990623e3d7da1df3d33db3e42d80eda.log" < /dev/null
[12:15:08.810] > printenv:
[12:15:08.816] >     SHELL=/bin/zsh
>     SUDO_GID=1000
>     CHARSET=UTF-8
>     SUDO_COMMAND=/bin/zsh
>     SUDO_USER=hassio
>     PWD=/root
>     LOGNAME=root
>     TZ=America/Chicago
>     HOME=/root
>     LANG=C.UTF-8
>     VSCODE_AGENT_FOLDER=/root/.vscode-server
>     TERM=unknown
>     USER=root
>     SUPERVISOR_TOKEN=46f4effa61b7fee58e13eddd59b0ca2ad6f9e9b081625127277478aabead648d5860c4af10e21ca71f08b734db18742bc10c9c3ed82e12ea
>     SHLVL=2
>     PAGER=less
>     LC_COLLATE=C
>     PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
>     SUDO_UID=1000
>     MAIL=/var/mail/root
>     OLDPWD=/root
>     _=/bin/printenv
[12:15:08.820] > Removing old logfile at /root/.vscode-server/.cli.903b1e9d8990623e3d7da1df3d33db3e42d80eda.log
[12:15:08.823] > Spawned remote CLI: 406
**[12:15:08.839] stderr> ps: unrecognized option: p**
**[12:15:08.853] > Exec server process not found**
[12:15:08.854] stderr> BusyBox v1.36.1 (2023-11-07 18:53:09 UTC) multi-call binary.
[12:15:08.854] stderr> 
[12:15:08.854] stderr> Usage: ps [-o COL1,COL2=HEADER] [-T]
[12:15:08.854] stderr> 
[12:15:08.854] stderr> Show list of processes
[12:15:08.854] stderr> 
[12:15:08.854] stderr> 	-o COL1,COL2=HEADER	Select columns for display
[12:15:08.854] stderr> 	-T			Show threads
[12:15:08.864] > b46f9139005b: start
> SSH_AUTH_SOCK====
> DISPLAY====
> listeningOn====
> osReleaseId==alpine==
> arch==aarch64==
> vscodeArch==arm64==
> bitness==64==
> tmpDir==/tmp==
> platform==linux==
[12:15:08.872] > unpackResult====
> didLocalDownload==0==
> downloadTime====
> installTime====
> serverStartTime==0==
> execServerToken==1a1a1111-11a1-1aaa-11aa-11aaa1a1a1a1==
> b46f9139005b: end
[12:15:08.872] Received install output: 
SSH_AUTH_SOCK====
DISPLAY====
listeningOn====
osReleaseId==alpine==
arch==aarch64==
vscodeArch==arm64==
bitness==64==
tmpDir==/tmp==
platform==linux==unpackResult====
didLocalDownload==0==
downloadTime====
installTime====
serverStartTime==0==
execServerToken==1a1a1111-11a1-1aaa-11aa-11aaa1a1a1a1==

[12:15:08.873] Failed to parse remote port from server output
[12:15:08.873] Terminating local server
[12:15:08.875] Resolver error: Error: 
	at g.Create (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:460245)
	at t.handleInstallOutput (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:457567)
	at e (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:518696)
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
	at async /Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:540605
	at async t.withShowDetailsEvent (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:544264)
	at async /Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:515401
	at async T (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:513452)
	at async t.resolveWithLocalServer (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:514941)
	at async k (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:537822)
	at async t.resolve (/Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:541635)
	at async /Users/vgoya2/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:807794
[12:15:08.879] ------

Here is the error in my “Advanced SSH and web terminal” add-on (which works fine)

Accepted password for hassio from 192.168.4.20 port 65386 ssh2
User child is on pid 435
Starting session: shell for hassio from 192.168.4.20 port 65386 id 0
Received disconnect from 192.168.4.20 port 65386:11: disconnected by user
Disconnected from user hassio 192.168.4.20 port 65386

Please help me understand how to fix this.
Thank you.

1 Like

I’ve had the same issue with VS Code Server.
Looks like it’s trying to use ps -p which isn’t available with the BusyBox version of ps.
I just installed a different version with apk --no-cache add procps and it now works.

Edit: added procps to the Advanced SSH & Web Terminal packages config instead so it automatically installs on startup.

Edit 2: this is no longer an issue - procps is included by default:

2 Likes

Thanks so much! This worked perfectly.

1 Like

Adding the package manually works for me, thanks! Nevertheless, I can’t add it through the package config like this:

packages:
  - procps

Any ideas?

I’m using the Terminal & SSH add-on, and for me I use apks instead of packages. I was running into the same issue as OP and adding procps this way worked for me.

apks:
  - gcompat
  - libstdc++
  - curl
  - procps