NemoClaw icon indicating copy to clipboard operation
NemoClaw copied to clipboard

[All Platforms][CLI&UX] tunnel start says cloudflared is already running when its PID belongs to another process

Open PicoNVIDIA opened this issue 2 months ago • 0 comments

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

  1. Use an isolated HOME, NEMOCLAW_SANDBOX_NAME=verify3tun, stub openshell and docker, and a stub cloudflared on PATH that logs each call and prints a trycloudflare URL.
  2. Start an unrelated process (/bin/sleep 300). Write its PID to /tmp/nemoclaw-services-verify3tun/cloudflared.pid and an old URL to cloudflared.log in the same directory.
  3. Run nemoclaw tunnel status, then nemoclaw tunnel start.
  4. Kill the sleep and run nemoclaw tunnel start again.

Environment

  • macOS 26.5.2 (arm64), Node.js v22.22.3
  • NemoClaw main at 4c44f7cc8; src/lib/tunnel is unchanged on 5f6eb3232
  • 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

PicoNVIDIA avatar Sep 28 '26 20:09 PicoNVIDIA