#6061·rushstack

[rush] rush-cli-client: daemon recovery and management gaps (stale artifacts permanently disable the daemon; daemon stop/restart are not idempotent)

Author: TheLarkInnCreated Sep 24, 2026Updated Sep 24, 2026

Summary

The daemon's fail-closed ownership checks are deliberately conservative. However, some states that are provably safe to recover from still disable the daemon permanently for a workspace, and there is no documented recovery command. The management commands are also not idempotent.

  1. Stale or foreign artifacts permanently disable the daemon (after kill -9 of the daemon plus partial cleanup or PID reuse):
    • a socket with no pid.json gives Socket ... has no ownership record; refusing automatic reclaim. Using in-process Rush. on every build (+2 s), and daemon start refuses too;
    • a corrupt pid.json gives a permanent fallback (Cannot safely read ...pid.json; refusing automatic reclaim.);
    • a pid.json naming a reused live, unrelated PID costs 16.5 s per command (PID ... still exists but the daemon is not ready. It may be a reused PID; refusing to kill it...) until that unrelated process exits.
  2. daemon stop and daemon restart fail when no daemon is running. Both exit 1 with Could not connect ..., and restart does not start a daemon. Scripts and agents must special-case "not running" for the common stop; ...; start and "restart to pick up config" flows.

Repro steps

# RUSH_DAEMON=1, rush-client from main @ 60007c9a8c
rush-client daemon stop; rush-client daemon stop; echo $?      # 1 "Could not connect"
rush-client daemon restart; echo $?                             # 1, no daemon started
rush-client build; kill -9 <daemon pid>; rm <runtime dir>/rushd-<key>.pid.json
rush-client build                                               # permanent in-process fallback + warning

Expected result: Self-heal whenever it is provably safe, and otherwise provide an explicit, documented escape hatch that the fail-closed messages point to. stop succeeds (exit 0, state: "notRunning") when nothing is running, and restart starts a daemon when none is running.

Actual result: A manual, undocumented cleanup of files in $XDG_RUNTIME_DIR/rushd-<uid>/ is required. The management commands exit 1.

Details

Root cause (main @ 60007c9a8c): assertNoLiveOwner / readDaemonOwnership in libraries/rush-client-core/src/connectOrStartDaemon.ts:282-323 fail closed in all three cases, and waitForHandoffAsync (:257-276) polls a live foreign PID until the 15 s deadline. The management commands are in apps/rush-cli-client/src/daemonCommands.ts.

Suggested fix:

  • PID reuse: compare pid.json startedAt with the process start time (LockFile in node-core-library already has getProcessStartTime). A mismatch means the owner is dead, so reclaim.
  • Socket without a record, or a corrupt record, combined with ECONNREFUSED while holding the start mutex (and no .starting reservation): no listener exists, so reclaim.
  • Add rush-client daemon stop --force (or daemon reset) that removes this workspace's artifacts after verifying that no process in the recorded session is alive, and mention it in every fail-closed message.
  • Make stop idempotent, and make restart start a daemon when none is running.

This was found during an automated performance/behavior analysis of rush-client/rushd on Linux and independently reproduced. Related: #6050 (durable .starting reservation).

Standard questions

Question Answer
@microsoft/rush globally installed version? built from main @ 60007c9a8c (5.179.0)
rushVersion from rush.json? 5.179.0
pnpmVersion, npmVersion, or yarnVersion from rush.json? [email protected]
(if pnpm) useWorkspaces from pnpm-config.json? true
Operating system? Linux (WSL2 Ubuntu 24.04)
Would you consider contributing a PR? Yes
Node.js version (node -v)? 22.23.2