Skip to main content

Module local_daemon

Module local_daemon 

Source
Expand description

Local-daemon auto-detection.

Every gRPC-using verb in the CLI checks this first. When the per-repo .heddle/sockets/grpc.sock exists and the pidfile points at a live process, callers can route their RPC over the UDS instead of opening an in-process [GrpcLocalService]. The latency win matters for tight agent loops.

Three layers:

  1. detect_local_daemon — file-stat probe (pidfile + liveness via kill(pid, 0) + same-executable identity). Cheap, syscall-only, used as the cheap negative case (“no daemon, fall through to in-process”).
  2. detect_local_daemon_with_connect_probe — same as (1) but actually opens a UnixStream and checks kernel-reported peer credentials to confirm the listener is owned by our uid. Catches the “stale socket file with a live unrelated PID” race.
  3. connect_local_daemon_channel — full path: build a tonic tonic::transport::Channel over the UDS, run the gRPC Health.Check handshake, and cache the working channel for the rest of the process. This is what the read-shaped CLI verbs route through.

All three caches are keyed by canonical heddle-dir path, so a CLI invocation that touches one repo pays the probe cost exactly once.

Structs§

LocalDaemonChannel
Connect-and-handshake outcome for connect_local_daemon_channel.
LocalDaemonProbe
UdsTarget
A reachable local daemon — the path of the UDS socket the caller can connect to. Returned by detect_local_daemon when the probe reports Running.

Enums§

LocalDaemonStatus

Functions§

connect_local_daemon_channel
Build a tonic tonic::transport::Channel over the per-repo UDS, perform the gRPC Health.Check handshake, and return both alongside the UdsTarget.
detect_local_daemon
Run the probe and, when the daemon is Running, return the UDS target a tonic client can dial. Cached for the process lifetime so hot agent loops don’t pay two stat-syscalls per RPC.
detect_local_daemon_with_connect_probe
Stronger variant of detect_local_daemon — runs the file-stat probe, then attempts a UDS connect to confirm the daemon is actually accepting connections (not just a stale pidfile that happens to point at a live unrelated process).
probe
Probe the per-repo daemon directory. Cheap (two file stats, kill(pid, 0), and same-executable identity for live pids).