fix(daemon-client): name a sandbox-denied connect and leave that daemon alone

Merged
TH
2d ago
+1493-193

Summary

A reachability probe answered a boolean, so a loopback connect the host refused (EPERM or EACCES under a Codex workspace-write sandbox around the client) read exactly like a daemon that answers nothing. The client judged a healthy daemon dead, tried to replace it, and failed with "Daemon replacement could not be confirmed." That attempt killed the daemon this client could not reach.

Probes now answer a verdict, and a refusal by EPERM or EACCES is a denial rather than evidence about the daemon. The takeover ladder answers a new connectDenied decision; each client hearing it fails with details.reason: daemon-connect-denied, the errno, transport, port, daemon identity, and the host-access hint the denied listen already used. Nothing is spawned, retired, or signaled on that answer. The probe layer moves to daemon-client-loopback-probe.ts, which owns the denial set.

Before / after

$ codex sandbox -- agent-device devices   # healthy daemon, pid 67030, port 58269
Base: Daemon replacement could not be confirmed.
      --json: reason startup-exited, startError EPERM .../daemon.log,
              cleanup retirement-unconfirmed on EPERM .../daemon.reclaim.lock
      ps: pid 67030 gone — the healthy daemon was killed
Head: The host denied this client a connect to the daemon's loopback endpoint
      on 127.0.0.1:58269.  details.reason daemon-connect-denied, errno EPERM,
      hint naming the sandbox and host access
      ps: pid 67030 alive; the next unsandboxed devices reused it

Validation

Head 19fccace43. typecheck, lint, format, gate fallow, check:layering, check:doc-prose, check:command-docs clean. packages/daemon-client 385 tests pass, plus packages/daemon 4779 and test/repo-guards 181. Suppressing the classifier or the ladder branch fails the new cases. Reproduced with the Codex sandbox CLI, no device. CI owes the full lane. Risk: a denial errno besides EPERM/EACCES still reads as unreachable.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.