Four binaries derived the default with os.UserConfigDir while the daemon
resolved it from its own config home. The two agree on Linux with an
absolute XDG_CONFIG_HOME and diverge everywhere else, so one deployment
booted from a different config file depending on which binary started.
Move the rule into the package that owns configuration resolution
(internal/infrastructure/configuration, which already owns xdgDataHome and
DefaultWorkDir) as DefaultConfigDir/DefaultConfigPath, and have every
-config default take it from there: archie-gateway, archie-messaging,
archie-state-store (serve and recovery) and archie-ui, plus the daemon's
own parseArgs, setup generator and drain-marker path.
Fence the claim at the source, since the resolved value is only observable
by starting a process: no source under cmd/ or internal/app/archied may
call os.UserConfigDir, and every -config registration must default to the
helper.
Both gRPC listeners took their bind address from a -listen flag default alone,
with no config key. The port a service binds and the port its clients dial were
therefore two separate facts -- the flag default, and [services.<name>].target --
with nothing keeping them in step.
On a host that already owned the default the effect read as a code fault rather
than a port collision: the store died with "bind: address already in use" while
every client reported "state store: connection error ... error reading server
preface: EOF". Cockpit binds 9090 by default, so this is not hypothetical.
Verifying the dashboard on such a host needed a hand-written overlay plus a
matching -listen, two things to keep in step by hand.
- [services.state].listen and [services.gateway].listen now name the bind
address. Precedence is -listen, then config, then a default applied by the
loader. An empty result is a startup ERROR, never a fallback: net.Listen reads
"" as "any free port", so defaulting there would bind the service somewhere no
client looks and still report success.
- Both flag defaults become "" so configuration can win, mirroring how archie-ui
already prefers [web].listen over its flag.
- Gateway listen defaults to the same constant as the gateway target, so a
default deployment's client and server cannot drift onto different ports.
[services.state].target still has no default: an empty target stays a startup
error in the daemon and gateway, which no longer serve a local store.
- ServiceConnection gains the field. Its doc now says clients read only Target
and TargetToken, and Listen belongs to the process that owns the service --
the previous wording claimed the struct starts no listeners while carrying one.
- deployments/dev.toml states each port once, beside the target it must match, so
`task dev` is retargetable on a host that owns 9090 by editing one overlay.
Tests. Unit: config defaults, explicit values, and precedence. Process: the
existing real-process smoke test now takes its listen from configuration instead
of -listen, so the end-to-end wiring is proven by the test that already starts
the binary, with no extra process. Both were verified load-bearing by mutation --
inverting the precedence fails the unit test, and making the app layer ignore
config fails the process test with "state: no listen address".
Verified: task check exit 0. Also documented in config.example.toml, the
configuration architecture table, and the `task dev` summary.
The Gateway had no transport boundary: RunGateway refused any non-loopback
listen address and serveGateway registered no interceptor, so archie-ui was
colocation-only while the State Store already had a token-authenticated
equivalent.
gatewayrpc gains a gateway-token metadata credential with constant-time
comparison and both unary and stream interceptors on each side. Stream
coverage is required here and not in staterpc: the Gateway's Stream RPC is
server-streaming. Dial fails closed on a non-loopback target with no token,
mirroring staterpc.Dial. gatewayServerOpts applies the same rule server-side:
loopback stays insecure, non-loopback requires a token, malformed errors.
The daemon resolves [services.gateway].target_token then GATEWAY_TOKEN;
archie-ui passes the token its config projection already carried, so a
distributed dashboard is now possible.
Closes: archie-core-juqx
Phase 1 (extract the Gateway Service), first stage. Repairs the
half-migrated working tree so the default (inproc) daemon path works
again while keeping the WIP's direction:
- chatTaskActorAdapter is contract-only (no HTTP detour); nil contract
returns ErrChatCapabilityUnavailable instead of panicking.
- openStores opens the conversation store for both processes again;
the standalone gateway no longer owns it exclusively. Phase 1 keeps
the daemon's Telegram/email routers and session-memory curator
reading the same SQLite file; remote conversations arrive when a
process that cannot open the file needs them.
- setupLLMAndChat composes the local gateway (setupGatewayChat) in
default mode and a remote gRPC client in mode=remote; the returned
contract is never nil, and Run handles the error.
- taskactions.Service is now the single task-mutation implementation
shared by the dashboard (webui TaskActionService), the daemon's local
gateway actor, and the NATS responder. The daemon registers
taskactions.Register so the standalone Gateway's client can forward
actions; transport follows the repo's natsrpc pattern.
- uncommitted sessions.proto / SessionStoreService gRPC contract
deferred: it has no wired consumers (scope creep for this stage).
- task_action_adapter_test.go rewritten against the contract chain.
task check passes; archied and archie-gateway both build.