Skip to content

[Bug]: daemon steals daemon.sock on start and unlinks it on exit, stranding a live daemon #9840

Closed

Description

@JordanTheJet

Affected component

runtime/daemon

Severity

S1 - workflow blocked

Current behavior

Two unguarded operations in crates/zeroclaw-runtime/src/rpc/local.rs let any second daemon break the first, and then break the socket for everyone:

  1. Start steals the path. platform::remove_stale(&path) (line 136) deletes an existing daemon.sock before binding, with no liveness check. A second daemon silently takes the path from a running first one, which stays alive but becomes unreachable.
  2. Exit unlinks a path it may no longer own. platform::cleanup(&path) (line 224) calls remove_file unconditionally on shutdown, without checking the path still resolves to this listener's socket. An exiting daemon deletes a socket a different process bound since.

Combined: daemon B starts and steals A's path; A is alive but unreachable. Later B exits and cleanup removes the path — now nothing is reachable, even though A is still running and looks healthy in ps. Recovery requires noticing and restarting, because both ps and the service manager report a healthy daemon.

Observed three times while debugging an unrelated change.

Expected behavior

A daemon should not take a socket that a live daemon is serving — it should detect the live peer and refuse to start (or bind elsewhere) rather than silently stealing it.

A daemon should not unlink a socket path it no longer owns.

Steps to reproduce

# 1. Start a daemon and confirm it serves the socket.
zeroclaw daemon &
lsof ~/.zeroclaw/data/daemon.sock        # -> PID A

# 2. Start a second daemon against the same config dir.
zeroclaw daemon &
lsof ~/.zeroclaw/data/daemon.sock        # -> PID B; A is now unreachable

# 3. Stop the second one.
kill <PID B>

# 4. The path is gone, though A is still running.
ls ~/.zeroclaw/data/daemon.sock          # No such file or directory
ps -p <PID A>                            # still alive, still "healthy"

Impact

Every local client breaks while the daemon appears healthy, so the failure is silent until someone tries to use it. ps shows a running daemon and the launch agent reports the service as loaded, which sends you looking in the wrong place.

Two paths make this reachable in a stock install rather than only under manual use:

  • The desktop app spawns its own daemon when its health probe finds nothing. That probe uses a hardcoded port (const GATEWAY_PORT: u16 = 42617 in apps/tauri/src/lib.rs) and never reads the configured gateway.port, so any user on a different port gets a probe that cannot succeed and a duplicate daemon on every launch. The probe window is also 3 x 700ms, shorter than observed daemon readiness.
  • A launch agent plus any manual zeroclaw daemon produces the same collision.

Running additional daemons under their own ZEROCLAW_CONFIG_DIR isolates them correctly and is a sound workaround for development.

Logs / stack traces

zerocode: zerocode connected to the daemon, but initialization did not finish within 10s. Restart the daemon and try again.

No such file or directory (os error 2)

ZeroClaw version

0.8.4 (release binary; code paths confirmed on master 0c8c92e)

Rust version

rustc 1.96.1

Operating system

macOS 26.5.2

Regression?

Unknown

Pre-flight checks

  • I reproduced this on the latest master branch or latest release.
  • I redacted secrets, tokens, and personal data from all submitted content.

Activity

  1. added
    bug
    on Aug 7, 2026
  2. added
    daemon
    desktop
    on Aug 8, 2026
  3. added this to the v0.8.5 milestone on Aug 8, 2026
  4. added
    runtime
    service
    zerocode
    priority:p1
    status:accepted
    risk:high
    on Aug 8, 2026
  5. moved this from Backlog to In Progress in ZeroClaw Project Boardon Aug 8, 2026
  6. vyahhi commented on Aug 9, 2026

    @vyahhi
    Collaborator

    [AUTO] Related: #9846 is the focused implementation for this daemon socket-ownership bug. Both preserve the live incumbent daemon endpoint and still allow genuine stale-socket recovery. Difference: this issue records the process-level failure, while #9846 probes an existing listener and tracks device/inode ownership so startup and shutdown cannot steal or unlink another listener socket.

  7. added
    status:in-progress
    on Aug 9, 2026
  8. removed
    status:in-progress
    on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdaemondesktoppriority:p1risk:highruntimeservicestatus:acceptedzerocode

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions