From c372ae6bae21ce0832b1c0e713eb4ab7a4f48c3d Mon Sep 17 00:00:00 2001 From: Kilo Date: Wed, 6 May 2026 18:11:22 +0000 Subject: [PATCH] fix: move PortManager init after PORT/httpServer declaration --- src/bot/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bot/index.js b/src/bot/index.js index 1a40c96c..0fcc4178 100644 --- a/src/bot/index.js +++ b/src/bot/index.js @@ -1419,15 +1419,7 @@ export async function initBot(config, api, tools, skills, agents) { // ── (unhandled rejection handler registered below with gracefulShutdown) ── - // ── PortManager: smart port lifecycle (claim, retry, recover) ── - const PIDFILE = path.join(process.env.HOME || '/tmp', '.zcode-bot.pid'); - const portManager = new PortManager({ - port: PORT, - pidfile: PIDFILE, - maxAttempts: 5, - baseDelayMs: 500, - maxDelayMs: 5000, - }); + // ── Graceful shutdown is defined at end of initBot (requires full `svc`) ── // ── Express + WebSocket server (keep for webhook compatibility) ── const app = express(); @@ -1482,6 +1474,16 @@ export async function initBot(config, api, tools, skills, agents) { const PORT = process.env.ZCODE_PORT || 3000; + // ── PortManager: smart port lifecycle (claim, retry, recover) ── + const PIDFILE = path.join(process.env.HOME || '/tmp', '.zcode-bot.pid'); + const portManager = new PortManager({ + port: PORT, + pidfile: PIDFILE, + maxAttempts: 5, + baseDelayMs: 500, + maxDelayMs: 5000, + }); + // ── Claim port via PortManager (retry + stale recovery + backoff) ── try { await portManager.claim(httpServer);