Initialize the foreground-daemon process. Commits the XDG layout pin (and
drains a residual ~/.lean-ctx) before the daemon writes anything, so this
long-running, possibly launchd/systemd-autostarted writer can never
re-collapse config/data/state/cache onto a stray legacy dir (GL #623). The
MCP server pins on its own start; the daemon is the other independent entry
point (e.g. serve --_foreground-daemon), so it must heal too. heal() is
idempotent and cheap — a no-op once pinned and when no residual dir exists.
Fast check on the hot path (every MCP request): the recorded PID is
alive and, when the daemon recorded its identity, still that process. A
PID file of an earlier release has no identity; verified_daemon also
checks the command line.
The line serve --stop and daemon stop print, and exit 1 after, when no
daemon runs for the active data dir. Names the dir so that a caller with
a scratch LEAN_CTX_DATA_DIR sees which instance it asked about.
PIDs of the background services this instance (data dir) recorded: the
daemon PID file, the proxy that answers /health on the configured port,
and the Cockpit launch record. Nothing else is ever a stop candidate —
MCP stdio servers, lean-ctx -c runners, hooks and other instances’
services have no record here (#2176).
The PID in daemon.pid. Empty, garbage, 0, negative or overflowing
content is warned about and the stale file removed; it never becomes a
signal target (ipc::process::read_pid_file).
The recorded daemon: the PID from daemon.pid and, when the identity
file names the same PID, the identity recorded at start. A PID file of an
earlier release has no identity; it is gated by command line only.
Start a proxy that restart/config apply stopped again when no
autostart service brought it back (#2176 review #4): detached, with the
arguments it ran with, by the installed binary. None when there was
nothing to restore; otherwise the PID or the spawn error.
The PID of the running daemon as daemon status reports it: this process
when it is the foreground daemon daemon.pid names, otherwise
verified_daemon. The process sweep behind verified_daemon excludes
its own PID, so the daemon answering its own /v1/local/daemon found no
daemon (running: false) while lean-ctx daemon status saw it.
Stop the daemon of the active data dir (LEAN_CTX_DATA_DIR, else the
default under HOME), resolved only through that dir’s PID file, identity
file and socket — never through a default path, a process name or a
service name. The autostart service is stopped too, but only when it runs
exactly this daemon’s PID (5 Nov 2026: systemctl --user stop by unit
name stopped the user’s real daemon from a scratch data dir).
Stop this instance’s recorded background services that sweep includes
(see owned_service_pids); every PID is gated again by command line,
user and process identity in ipc::process::stop_services.
lean-ctx background services of this user that this instance has no
record of. Listed by stop, uninstall and doctor, never stopped
(owner decision 02.11.).
The PID of the recorded daemon when it really is this user’s lean-ctx
daemon: command line serve --_foreground-daemon, lean-ctx executable,
same user, and the recorded identity where there is one. Slower than
is_daemon_running (reads the command line); for doctor and stop.