[All Platforms][CLI&UX] tunnel start says cloudflared is already running when its PID belongs to another process
Description
After cloudflared exits and the OS hands its PID to another process, nemoclaw tunnel status and nemoclaw tunnel start disagree. Status sees the stale PID and tells you to run nemoclaw tunnel start. Start then says cloudflared is already running, doesn't launch it, and prints the dead tunnel's URL from the old log.
Status and doctor go through readCloudflaredState() (src/lib/tunnel/services.ts:278), which checks that the process command line names cloudflared. startService() (line 336) and the URL wait in startAll() (lines 701 and 714) use isRunning() instead, which only does process.kill(pid, 0). #7643 added the identity check to the stop path; start never got it. getServiceStatuses() (line 753) also uses isRunning().
Reproduction Steps
- Use an isolated HOME,
NEMOCLAW_SANDBOX_NAME=verify3tun, stubopenshellanddocker, and a stubcloudflaredon PATH that logs each call and prints a trycloudflare URL. - Start an unrelated process (
/bin/sleep 300). Write its PID to/tmp/nemoclaw-services-verify3tun/cloudflared.pidand an old URL tocloudflared.login the same directory. - Run
nemoclaw tunnel status, thennemoclaw tunnel start. - Kill the sleep and run
nemoclaw tunnel startagain.
Environment
- macOS 26.5.2 (arm64), Node.js v22.22.3
- NemoClaw
mainat4c44f7cc8;src/lib/tunnelis unchanged on5f6eb3232 - Real CLI (
node bin/nemoclaw.js). OpenShell, Docker, and cloudflared were stubs, so no real tunnel was created.
Debug Output
nemoclaw tunnel status, with PID 81145 held by /bin/sleep 300:
● cloudflared (stale PID 81145)
no cloudflared process (PID 81145 is dead or not cloudflared); run `nemoclaw tunnel start` to restart it
nemoclaw tunnel start right after:
[services] cloudflared already running (PID 81145)
[services] Waiting for tunnel URL...
│ Public URL: https://old-dead-tunnel.trycloudflare.com/ │
The stub cloudflared was never called.
Logs
After the sleep exits, nemoclaw tunnel start works:
[services] cloudflared started (PID 81249)
[services] Waiting for tunnel URL...
│ Public URL: https://fresh-tunnel.trycloudflare.com/ │
I trimmed the banner and a tunnel-origin warning that came from the stubbed OpenShell.
Switching startService(), startAll(), and getServiceStatuses() to readCloudflaredState() should fix this. When the recorded PID isn't cloudflared, start should overwrite the PID file without signaling that process.
Checklist
- [x] I confirmed this bug is reproducible
- [x] I searched existing issues and this is not a duplicate