From e5a3d1016feb4c71e02eea5c597c7b7cca6b286d Mon Sep 17 00:00:00 2001 From: unggun Date: Thu, 7 May 2026 03:02:44 +0200 Subject: [PATCH] fix: detect entry script under pm2 in isMain check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The upstream isMain check (added in 99fb060) compared path.resolve(process.argv[1]) against fileURLToPath(import.meta.url). Under pm2, process.argv[1] is pm2's ProcessContainerFork.js wrapper, not the user's script — so isMain was always false and ALL startup code (cron registration, telegram polling, hivemind bootstrap) was silently skipped. Process appeared "online" but produced zero log output and ran no work. Fix: also accept process.env.pm_exec_path, which pm2 sets to the user's actual entry script path. Direct `node index.js` invocation keeps working via the original argv check. Co-Authored-By: Claude Opus 4.7 (1M context) --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 000e2410b..e8ad37dda 100644 --- a/index.js +++ b/index.js @@ -36,9 +36,14 @@ import { getWeightsSummary } from "./signal-weights.js"; import { bootstrapHiveMind, ensureAgentId, getHiveMindPullMode, isHiveMindEnabled, pullHiveMindLessons, pullHiveMindPresets, registerHiveMindAgent, startHiveMindBackgroundSync } from "./hivemind.js"; import { appendDecision } from "./decision-log.js"; -const isMain = process.argv[1] - ? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) - : false; +// Detect whether this file is the entry script (auto-start) or being imported +// as a library (no auto-start). Under pm2, process.argv[1] is the pm2 wrapper +// (ProcessContainerFork.js), so we also check pm_exec_path which pm2 sets to +// the user's actual entry script. +const __entry = fileURLToPath(import.meta.url); +const isMain = + (process.argv[1] && path.resolve(process.argv[1]) === __entry) || + (process.env.pm_exec_path && path.resolve(process.env.pm_exec_path) === __entry); if (isMain) { log("startup", "DLMM LP Agent starting...");