Repository navigation
Description
Purpose
On macOS, agent-device identifies a process by its pid plus the ps -o lstart= start time, and compares the two start strings exactly. /bin/ps prints lstart in the language of LC_TIME. A daemon spawned under LANG=fr_FR.UTF-8 records mar. 17 nov. 19:42:27 2026. A client under LC_TIME=C reads Tue Nov 17 19:42:27 2026 for the same pid. daemon stop then answers stopped: false, mode: not-running, cleanupConfidence: known, deletes daemon.json and the lock, and leaves the daemon alive. daemon status then reports state: stopped while the process runs.
The Linux fix for the same comparison (#4437, #4438) reads /proc and does not cover macOS. On Windows the start time is already read with InvariantCulture (host-process.ts:478).
Environment
- agent-device 0.21.39 (npm). The code path is unchanged on
mainat655ede279. - macOS 27.2.1 (26B131), Apple Silicon, Node 24.21.0, Xcode 27.2 (27B52).
- No device is needed.
Reproduction
sd=$HOME/.agent-device-lanes/adr5-bug
# 1. Spawn a daemon under a French locale (any command that starts one).
env -u LC_ALL -u LC_TIME LANG=fr_FR.UTF-8 agent-device devices --state-dir "$sd" --json
grep processStartTime "$sd/daemon.json"
# "processStartTime": "mar. 17 nov. 19:42:27 2026"
# 2. Stop it from a client whose LC_TIME differs.
LC_TIME=C agent-device daemon stop --state-dir "$sd" --json
# {"success": true, "data": {"stopped": false, "mode": "not-running", "cleanupConfidence": "known", ...}}
ps -p <pid> -o pid=,lstart=,command=
# 72247 Tue Nov 17 19:42:27 2026 .../node .../agent-device/dist/src/internal/daemon.js
ls "$sd" # daemon.json and the lock are gone
LC_TIME=C agent-device daemon status --state-dir "$sd" --json
# {"success": true, "data": {"state": "stopped", ...}} (the process is still alive)The daemon log then shows daemon_metadata_lost (state: absent). With no session, the daemon exits at its idle window and logs daemon_shutdown_record_failed / daemon_registration_finish_failed ("Process lock acquisition is no longer held"). On 0.21.35 we saw the same orphan with two daemons that held sessions: they lived until their session idle expiry (AGENT_DEVICE_SESSION_IDLE_TIMEOUT_MS), about 1 h later. Without that expiry, a daemon that holds a session does not idle out.
Control: the same steps with the French locale on both sides answer stopped: true, mode: graceful, and the process is gone 2 s later.
Cause (source at v0.21.39)
host-process.ts:321-339: the identity read runs/bin/ps -p <pids> -o pid=,state=,lstart=with noenv. The single-field read (:395) and the async read (:199) are the same.host-process.ts:243-251:processStartTimesDifferreturnsleft !== rightfor two non-Linux strings, so two renderings of one start time "differ".daemon-client-startup.ts:658-659comparesinfo.processStartTime === identity.startTime.- Inferred, not measured: device claims (
ownerStartTime,device-claim-inspection.ts:200) and the runner lease (runner-lease.ts:530) compare the same strings, so a claim written under one locale can read asowner-process-reusedfrom another.
Required behavior
- The macOS (and BSD
ps) start-time read gives the same string whatever the caller'sLANG,LC_TIMEorLC_ALL. For example, runpswithenv: { ...process.env, LC_ALL: 'C' }(ExecOptions.env,exec.ts:21-23), or parselstartinto a locale-free token, like thelinux:token of fix(host-kit): keep Linux process identity stable across clock steps #4438. - A record written before the fix in another locale does not prove a different lifetime: compare it as "unknown", not as "differs", so an upgrade does not orphan the daemons that are already running.
Completion conditions
- The reproduction above answers
stopped: true,mode: graceful, and the process is gone. - A unit test pins the
psenvironment, or the parsed token, forlstart.
Dependencies
Blocked by: none. Sibling of #4437, whose fix #4438 covers Linux only.
Workaround
Export LC_TIME=C (and leave LC_ALL unset) in every shell that runs agent-device, so daemons and clients share one rendering.
Activity
thymikee commentedon Nov 18, 2026
Triage: bug; actionable without more input from you. The synchronous, batched and asynchronous ps identity reads on current main inherit the caller locale, while non-Linux start-time strings are compared verbatim. Fix that at the shared host-process owner and treat incompatible existing records as unknown evidence, never permission to reclaim a live process. #4659 changes shutdown transport; it does not remove this identity mismatch for daemon, claim and lease consumers.
thymikee commentedon Nov 18, 2026
I’m following up in #4682 to narrow the locale pin to start-time reads and check the shutdown path on macOS.