Repository navigation
Description
Summary
Inside the Codex CLI Linux sandbox, agmsg reports a running agmsgd as stopped:
agmsgd (Codex notices) is stopped while enabled (reason: executor missing or boot/start evidence does not match (executor unavailable)). Run agmsg daemon start (recommended), ...
agmsgd is in fact running and delivering. The Codex sandbox runs commands in a separate PID namespace, so the executor PID recorded in install.db is not visible from inside it, and agmsg_daemon_read_state reads "not visible" as "dead".
Environment
- agmsg 1.6.1 (
a5339b4f);scripts/lib/daemon-state.shis unchanged on current main - Linux 7.0.0, agmsgd running as a systemd user service
- codex-cli 0.163.0,
sandbox_mode = workspace-write(agmsgdb/ teams/ run/ ext-tools/inwritable_roots,network_access = false)
Reproduction
With agmsgd running on the host (executor PID 615065 in this example):
# host
readlink /proc/self/ns/pid # pid:[4026531836]
test -e /proc/615065 && echo visible # visible
# inside the Codex sandbox (same result with -P :read-only)
codex sandbox -P :workspace -C <project> -- bash -c \
'readlink /proc/self/ns/pid; test -e /proc/615065 && echo visible || echo "not visible"'
# pid:[4026532693]
# not visibleAny agmsg command that reaches agmsg_daemon_warn_if_stopped (e.g. identities.sh, inbox.sh via storage.sh:42) inside the sandbox prints the warning above. In the same session, a message sent to that Codex seat was accepted by agmsgd and answered about 20 seconds later, so delivery itself works.
Inside vs. outside the sandbox:
| check | host | sandbox |
|---|---|---|
| processes visible | 374 | 5 |
/proc/stat btime |
matches recorded boot | matches recorded boot |
/proc/<executor>/stat |
readable | missing |
kill -0 <executor> |
0 | ESRCH |
install.db state |
ready / pid | ready / pid (readable) |
agmsg_daemon_read_state |
ready |
stopped |
Where it goes wrong (scripts/lib/daemon-state.sh)
- L37:
/proc/$pid/statdoes not exist, sostarted_epochstays empty. - L103:
_agmsg_pid_signal_presencereturnsgone. It already treats EPERM as alive (fix(liveness): a process you cannot signal is not a process that is gone #505), but a PID namespace returns ESRCH, which is indistinguishable from a dead process. - L112: with
started_epochempty, the state becomesstoppedwith the reason above.
pidfile, socket existence and SQLite reads all succeed. Connecting to the agmsgd socket from inside the sandbox is refused (EPERM), so a socket-based liveness check would not help here either.
Impact
- A false warning on agmsg commands run in the sandbox (rate-limited to once per 10 minutes), recommending
agmsg daemon start, which is the wrong recovery. run/agmsgd-warning-atis shared with the host, so a false warning from the sandbox also suppresses a genuine host-side warning for up to 10 minutes.- Delivery is not affected.
Possible fix
Minimal: on Linux, when /proc/<pid> is not visible and the caller's PID namespace is not the initial one (readlink /proc/self/ns/pid != pid:[4026531836], i.e. PROC_PID_INIT_INO), return unchecked instead of stopped. Ordinary commands already stay silent on unchecked, which removes both the false warning and the marker side effect. Trade-off: inside a container, a daemon that really died would also be unchecked.
More precise: have the executor record its own PID namespace in the daemon owner record at startup, and return unchecked only when the caller's namespace differs. This needs a schema change.
Related but different causes: #1631 (WSL2 btime drift), #505 (EPERM), #1690 (Git Bash).
Activity
fix(daemon): do not call an executor stopped when it runs in another …
fix(daemon): do not call an executor stopped when it runs in another …