fix(daemon-client): match a spawned daemon's server mode to an explicit http transport

Merged
TH
5d ago
+426-9

Summary

A client that asked for --daemon-transport http with no --daemon-server-mode started a daemon in the socket-only default. That daemon opens no HTTP listener and publishes no httpPort, so the client never observed it as ready, retired it, and failed every call with daemon_endpoint_unavailable.

resolveTransportClientSettings now derives the spawn server mode from an explicitly requested transport, as it already did for dual: http starts its daemon in http mode. An explicit --daemon-server-mode or AGENT_DEVICE_DAEMON_SERVER_MODE still wins; auto and socket keep the socket-only default.

Where the mode opens no listener the client will call, in either direction, the pair is refused before anything is started, retired or quiesced. serverModeAnswersTransport decides it once, in the module owning both vocabularies; each route asks it where a daemon would next be changed — before a takeover retires what it found, and before the first launch. A daemon already serving that endpoint is reused.

Before / after

$ agent-device session list --daemon-transport http        # fresh state dir
base: Error (COMMAND_FAILED): Daemon HTTP endpoint is unavailable.
head: { "sessions": [] }                  # daemon.json: httpPort 54096

$ agent-device session list --daemon-transport socket --daemon-server-mode http
base: Error (COMMAND_FAILED): Daemon HTTP endpoint is unavailable.
head: Error (INVALID_ARGS): ...server mode "http" serves no socket endpoint...  [state dir empty]

Validation

Head 279a05e722. daemon-client-lifecycle-server-mode.test.ts (18 cases) covers the derivation per transport and source, explicit-mode precedence, socket/auto unchanged, a remote base URL, both refusal directions with no spawn, the refusal before a takeover on both routes, reuse of a reachable daemon, the hint's wording, and a control proving a usable pair reaches the counted launch mock. Each guard was checked by removing it and reading the failure.

vitest run --project unit-core packages/daemon-client/src/__tests__: 43 files, 434 passed. src/host, daemon-entrypoint, daemon-contracts, reason-tables passed. typecheck, build, oxfmt and oxlint clean.

Reason renamed daemon_server_mode_serves_no_client_transport; error-reasons.md regenerated. No changeset: unreleased. CI owns the remaining gates.