#3961·nanoclaw

[bug] /update-nanoclaw reports phase: complete without restarting the host when systemctl --user cannot reach the bus

Author: glifocatCreated Sep 28, 2026Updated Sep 28, 2026
Labelskind/bugarea/setup-installationtriage/unresolved

Affected NanoClaw version or commit

v2.4.0 (143db6c9) and main at 63082563.

Host platform

Linux

What happened?

/update-nanoclaw reported phase: complete while the pre-update host was still the one serving. The service was never stopped for cutover and never restarted at finish.

The controller decides whether the service is running with one call in scripts/update/service.ts:119:

typescript
active: env.runner.tryRun('systemctl', ['--user', 'is-active', '--quiet', name]).ok,

.ok conflates "the unit is inactive" with "I could not ask". With XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS unset (a service account entered with su, cron, a non-interactive SSH command, docker exec), systemctl --user cannot reach the user bus, exits 1, and the controller records active: false. Cutover then skips the stop, finish skips the restart, and the health check passes because the old process is still alive, still owns data/ncl.sock, and still answers bin/ncl groups list. Nothing checks that the running host is the one just built.

Why this is not a duplicate. The same probe conflation has come up before, and the project has a consistent answer: absorb the misdetection downstream instead of deriving the environment.

That works where it has been applied because the misdetection costs a lesser but working outcome: a nohup wrapper instead of a systemd unit, or verify reading the pid file. The update transaction is the one consumer that cannot absorb it, because its downstream is a success stamp. An unanswerable probe there must not be read as "stopped".

What did you expect?

Either the controller can tell whether the service is running and acts on the real answer, or it refuses to cut over and says why. It must not report complete with the old code still serving.

How can we reproduce it?

  1. A Linux install whose host runs under a systemd --user unit (linger enabled).
  2. Run the /update-nanoclaw transaction commands from a shell with XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS unset, for example su - <user> -c '...' or a plain non-interactive ssh host '...'.
  3. cutover reports service: { "mode": "systemd-user", "active": false } while systemctl --user show -p ActiveState (from a shell that has the bus) says active, with the same MainPID before and after finish.
$ systemctl --user is-active nanoclaw-v2-<slug>
Failed to connect to user scope bus via local transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined
$ echo $?
1
$ XDG_RUNTIME_DIR=/run/user/$(id -u) systemctl --user is-active nanoclaw-v2-<slug>
active

systemctl is-active exits 3 for a unit that is inactive or failed, 0 for active, and 1 when it cannot reach the bus, so the two cases are separable by exit code. Measured on systemd 255: a missing unit file exits 4, which the controller never hits because it checks the unit file first.

OS version and CPU architecture

Linux, systemd user instance, x86_64. Also reproduced on a fresh Ubuntu 24.04 VM (systemd 255).

Install or update path

Standard setup with nanoclaw.sh

Relevant redacted logs

Two transactions on one install, plus a control run.

Run 1, 2026-09-26, 2.3.0 to 2.4.0, transaction 20260926135143-431d4e1f-6e145f35:

controller: service: {"mode": "systemd-user", "name": "nanoclaw-v2-<slug>", "active": false}
unit:       ActiveState=active SubState=running MainPID=55635 ExecMainStartTimestamp=Wed 2026-09-23 12:51:21 CEST
dist/index.js rebuilt 2026-09-26 17:17:26
finish:     phase: "complete"

Net state: 2.4.0 source and a rebuilt agent image on disk, 2.3.0 code still serving, agent containers already stopped by cutover. A manual systemctl --user restart then started MainPID 1796718 at 17:27:59, which logged NanoClaw starting.

Control, 2026-09-28, transaction 20260928084702-e922e41d-7a147175, same install, only change XDG_RUNTIME_DIR=/run/user/$(id -u) exported: cutover reported active: true, finish restarted the unit (new MainPID 2751976 at 10:51:17, after the 10:51:05 rebuild). A third transaction that day behaved the same.

Last version that worked

None known. The probe has read this way since the update controller landed.

Proposed fix and follow-ups

Fix, in the update controller only (not a revisit of #2494's setup-wide approach):

  1. Distinguish the three outcomes by exit code: running, stopped (exit 3), probe failed (anything else). Treat a failed probe as unknown.
  2. Fail closed on unknown: refuse cutover and finish with the probe's error and what to set, the way stopService already refuses an unmanaged handle.
  3. Same shape elsewhere in the controller: launchctl print (exit 113 is "not loaded", other exits such as 112 "no such domain" are probe failures) and the pgrep fallback (exit 1 is "no match", a missing binary is not).

Follow-ups, separate from the fix above:

  • Finish health check cannot detect a stale host. Process alive + socket present + ncl groups list are all satisfied by the old process. Finish should assert the running host started after cutover (MainPID or start timestamp changed), or the host should report its stamped commit.
  • Uninstall has the same exposure. setup/uninstall/remove.ts:68-70 runs systemctl --user disable --now and daemon-reload through a runCommand that returns the exit status without throwing, and the status is not checked. With no user bus the unit stays enabled and running while its unit file and checkout are deleted.
  • setup/service.ts:294 (systemctl --user daemon-reload deciding user-systemd vs nohup) is the case #1981, #2482 and #3760 already cover. The fallback works, so no change is requested there.

Workaround

Export XDG_RUNTIME_DIR=/run/user/$(id -u) before running the transaction commands. Verified across three transactions.