agent: only bind the sidecar health port when PORT is set (#184)
The bot sidecar is a pure outbound WebSocket client — under systemd nothing health-checks or routes to it, so it needs no inbound listener. The health endpoint (for container platforms like Miren that health-check over HTTP) now binds only when PORT is explicitly set; otherwise the sidecar runs portless, so several sidecars can share one host without colliding on :8080.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 file changed,
+14
−9
agent/agent.mjs+14 −9
diff --git a/agent/agent.mjs b/agent/agent.mjs| index bba2970..1ba7061 100644 |
| --- a/agent/agent.mjs |
| +++ b/agent/agent.mjs |
| @@ -40,15 +40,20 @@ log(`boot: sidecar starting, base=${BASE}`); |
| requireBase(); |
| -// Health endpoint first (bind 0.0.0.0 explicitly for the platform health |
| -// check), so the container is healthy while it provisions/connects. |
| -const PORT = Number(process.env.PORT) || 8080; |
| -http |
| - .createServer((_req, res) => { |
| - res.writeHead(200, { "content-type": "text/plain" }); |
| - res.end("ok\n"); |
| - }) |
| - .listen(PORT, "0.0.0.0", () => log(`health listening on :${PORT}`)); |
| +// Optional health endpoint for container platforms that health-check over HTTP |
| +// (e.g. Miren). Only bind it when PORT is explicitly set: the sidecar is a pure |
| +// outbound WebSocket client, so under systemd nothing health-checks or routes to |
| +// it — it needs no inbound listener, and binding a fixed port would collide when |
| +// several sidecars share a host. |
| +if (process.env.PORT) { |
| + const PORT = Number(process.env.PORT); |
| + http |
| + .createServer((_req, res) => { |
| + res.writeHead(200, { "content-type": "text/plain" }); |
| + res.end("ok\n"); |
| + }) |
| + .listen(PORT, "0.0.0.0", () => log(`health listening on :${PORT}`)); |
| +} |
| // --- Claude: the plain assistant (the original sidecar bot) ---------------- |
| let claudeSession = loadSession(); |