Cross-session inbox goes permanently deaf when the /tmp/cc-socks-<uid> fallback directory is removed (systemd-tmpfiles boot sweep race)
Version: 2.1.283 (Linux, WSL2 with systemd; VS Code extension and CLI)
What happens. When $XDG_RUNTIME_DIR/cc-socks can't be used at startup, Claude Code falls back to /tmp/cc-socks-<uid>/<pid>.sock (added in 2.1.248). If that directory is later unlinked, the session keeps listening on a pathless socket. Its ~/.claude/sessions/<pid>.json keeps advertising the dead messagingSocketPath, so:
- other sessions'
ListAgentsomit it, andSendMessageto it fails with "not reachable"; - its own outbound messages carry
from="uds:/tmp/cc-socks-<uid>/<pid>.sock", so replies fail; - nothing re-binds or warns, and the session is one-way until restarted.
How it happens in practice. On WSL2 with systemd, VS Code reconnects and the extension spawns sessions during boot. At that point /run/user/<uid> doesn't exist yet (user-runtime-dir@ starts late), so the fallback is taken. Meanwhile systemd-tmpfiles-setup.service is still running the D /tmp boot sweep, which deletes /tmp/cc-socks-<uid>. The journal shows the sweep running 08:24:29–08:29:40, the sessions starting at 08:25:12 and 08:26:57, and /run/user/1000 appearing at 08:29:41.
Repro (without a reboot).
XDG_RUNTIME_DIR=/nonexistent claude(session A binds/tmp/cc-socks-$UID/…).rm -rf /tmp/cc-socks-$UID.- From session B,
ListAgents: A is missing, andSendMessageto A fails. A's/statusstill reports messaging as active.
Expected.
- (a) Periodically verify that the bound socket path still refers to our listener (inode check). If it doesn't, re-bind, preferring the primary
$XDG_RUNTIME_DIRdirectory once it exists, and updatesessions/<pid>.json. - (b) Or retry the primary directory for a short window at startup before falling back.
- (c) At minimum, surface a visible warning /
/statusdegraded cause when the inbox path disappears.
Workaround. Restart the session after boot, or add x /tmp/cc-socks-* to /etc/tmpfiles.d/.
Related (different failure modes): #85497 (session never binds its socket), #91223 (socket directory squatting).
Agree — once the fallback directory is unlinked the listener can stay open on a pathless inode while sessions/<pid>.json still advertises the dead path, so peer inbox looks permanently deaf until restart.
Validating "listener still open" is not enough. The check that matches the failure mode is:
- Path ↔ fd identity.
lstat(advertisedPath)vsfstat(listener_fd)(dev/ino). Treat mismatch orENOENTas dead advertisement. - Atomic rebind before registry rewrite. Prefer
$XDG_RUNTIME_DIR/cc-socksonce it exists; otherwise recreate the/tmp/cc-socks-<uid>fallback. Only after the new bind succeeds, updatemessagingSocketPathin the session registry (and any outboundfrom=identity). - Regression. With a live session: delete the bound directory, create
$XDG_RUNTIME_DIR, then assert inboundListAgents/SendMessagerecover without restart and the registry points at the new socket. Optional: short startup retry of the primary runtime dir before falling back (OP's (b)) so boot races take the stable path more often.
That also covers the WSL2 systemd-tmpfiles D /tmp sweep race in the report. Happy to trim to the inode check + rebind if maintainers want a narrower first patch.
Still reproducible on 2.1.322 (Linux, Debian in a Proxmox LXC; about 30 Claude Code sessions hosted by Claude Desktop's Code tab, all run by one uid). It affects the primary directory too, not only the /tmp fallback.
What happened. A buggy user script ran rm -rf $D with D empty-prefixed (D=$2/run, no $2), so it deleted /run, including /run/user/1000/cc-socks/. Linger=yes and the user manager kept running; no reboot happened.
Result. All ~30 sessions kept running but went one-way at once. Each still listened on a pathless socket while ~/.claude/sessions/<pid>.json advertised the dead messagingSocketPath.
SendMessageto them failed ("no sign of starting within 20s" / not reachable).- Their own outbound messages carried a
fromthat nobody could answer. - Nothing in
/statusor the UI showed degraded messaging. We only noticed hours later, when peers' replies were missing.
Recovery (current workaround). Stop the idle session process; the next message wakes it, it binds a new socket and keeps its history. Side effect: stopping the process kills its background jobs (in our case, file-lock renewal loops), so every session needs a manual check afterwards.
Detection we added locally. A 5-minute timer compares each sessions/<pid>.json messagingSocketPath with the live listener (lstat of the path vs the socket inode in /proc/<pid>/fd), and flags the sessions whose path is gone.
+1 for proposal (a): periodic path↔fd identity check, re-bind on mismatch, and update sessions/<pid>.json. At minimum, proposal (c): a visible warning when the inbox path disappears. With many concurrent sessions, one directory deletion silently cuts all of them off.