You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
English TL;DR — Under PM2, dsh never starts at all: PM2's fork container runs node <node_args> .../pm2/lib/ProcessContainerFork.js <args> and loads the app script with a dynamic import(), so import.meta.main is false inside apps/cli/src/bin.ts and runCli() is never called. The process stays alive on PM2's IPC channel, PM2 reports online with 0 restarts, out/err logs stay at 0 bytes, and nothing ever binds. This is the same entry guard as #6124 / #6115 / #5082, but triggered by the supervisor's loader instead of by Node < 24.2 — and the fix suggested in #6124 (process.argv[1] comparison) does not fix this case, because under PM2 argv[1] is the container, not bin.ts. Two verified workarounds are at the end.
// Require the real applicationif(process.env.pm_exec_path){if(ProcessUtils.isESModule(process.env.pm_exec_path)===true){import(url.pathToFileURL(process.env.pm_exec_path));}elserequire('module')._load(process.env.pm_exec_path,null,true);}elsethrownewError('Could not _load() the script');
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
English TL;DR — Under PM2,
dshnever starts at all: PM2's fork container runsnode <node_args> .../pm2/lib/ProcessContainerFork.js <args>and loads the app script with a dynamicimport(), soimport.meta.mainisfalseinsideapps/cli/src/bin.tsandrunCli()is never called. The process stays alive on PM2's IPC channel, PM2 reportsonlinewith 0 restarts, out/err logs stay at 0 bytes, and nothing ever binds. This is the same entry guard as #6124 / #6115 / #5082, but triggered by the supervisor's loader instead of by Node < 24.2 — and the fix suggested in #6124 (process.argv[1]comparison) does not fix this case, because under PM2argv[1]is the container, notbin.ts. Two verified workarounds are at the end.1. 环境
import.meta.main正常为true)pm2全局安装在%APPDATA%\npm\node_modules\pm2)c291e7961a(0.1.5-rc.2 之后 139 个提交);同一行为在dsh-v0.1.5-rc.1/rc.2上复现2. 最小复现
ecosystem.config.js(PM2 托管是社区常见的常驻方案,参见 #2749 / #4301 / #1102;仓库自身没有 PM2 文档):实际结果:PM2 报告
online、重启次数 0,进程存活数十秒以上,但不打印任何输出、不监听端口;人工pm2 stop dsh-web之后记录为exited with code [1] via signal [SIGINT]。预期结果:与手工执行完全相同的命令一样,打印 URL 行并监听 3080:
也就是说:同一个 argv、同一个 cwd、同一个 Node,只有经过 PM2 就完全不工作。
3. 观测证据
3.1 PM2 记录
进程既没有退出也没有报错——它是活着但不做事。这一点很重要:它排除了"端口占用"(后者会大声抛
EADDRINUSE并以非零码退出)、"tsx 缺失"、"Node 版本过低"(PM2 记录的是 v24.20.0)等假设。3.2 PM2 实际 spawn 的命令行(决定性证据)
apps/cli/src/bin.ts根本不在命令行里。 PM2 在 fork 模式下启动的是它自己的容器ProcessContainerFork.js,再由容器去加载应用脚本(脚本路径通过pm_exec_path环境变量传递),应用参数则被追加在容器路径之后。自查一行(复现本问题的用户可以直接确认自己是否命中):
如果在 PM2 托管的应用里看到
... pm2/lib/ProcessContainerFork.js <args>,那它的脚本就是被import()加载的,本文结论直接适用。该加载逻辑与平台无关(ProcessContainerFork.js在 Linux/macOS 上同样如此),但本文只在 Windows 11 上实测。3.3 PM2 容器如何加载脚本
pm2/lib/ProcessContainerFork.js(7.0.4):ProcessUtils.isESModule()对apps/cli/package.json("type": "module")返回true,所以走import()分支——动态 import 的模块不是进程入口。3.4 探针实测
把一个
.mjs探针(放在带"type": "module"的目录里)交给 PM2 托管,它报告:{ "argv": ["...\\fnm_multishells\\...\\node.exe", "C:\\Users\\<user>\\AppData\\Roaming\\npm\\node_modules\\pm2\\lib\\ProcessContainerFork.js"], "importMetaMain": false, "importMetaUrl": "file:///.../probe.mjs", "pmExecPath": "...\\probe.mjs", "cwd": "D:\\Dev\\deepseek-harness", "node": "v24.20.0" }即:PM2 下
import.meta.main === false,而且process.argv[1]是容器、不是应用脚本(应用参数在process.argv.slice(2)里,能正常取到)。3.5 结论
当前
apps/cli/src/bin.ts末尾:PM2 容器
import()它时import.meta.main为false→runCli()一次都不执行 → 模块加载完就结束;进程因为 PM2 的 IPC 通道而保持存活,于是出现"online 但静默"。4. 为什么其他所有启动方式都不受影响
只有"被 wrapper 用
import()加载"的形态会撞墙;"作为真入口被 node 执行"的形态全部正常(argv[1]就是bin.ts,import.meta.main === true):pnpm dsh(根package.json的scripts.dsh)、pnpm run demo:inspectorpackages/sdk/client/src/launch.ts(node --import tsx/esm <pkg>/src/bin.ts,产物存在时用lib/bin.js)packages/experimental/webworker-packer/src/repository.ts、scripts/demo-ptc.mjsapps/cli/tests/**、apps/web/tests/**、snapshots/**)仓库内已经有一条 wrapper 形态的正确做法:
python/sdk-runtime/runtime-bootstrap.mjs(Python 单文件运行时 / SEA 的入口,由scripts/build-exe-for-python-sdk.ts打包)import 构建产物后显式调用runCli():关键时间线证据:这个 bootstrap 文件与入口守卫是在同一个提交里引入的(
e5dbccce8c,git show --stat显示python/sdk-runtime/runtime-bootstrap.mjs为new file)。也就是说,守卫存在的原因正是"让 SEA bootstrap 能 importlib/bin.js而不自动执行 CLI";只是没有对外说明"外部进程管理器必须走同样的显式runCli()路径"。另有一条历史反证:#2749(0.1.0-rc.6,守卫引入之前)报告 PM2 注册的命令缺少
--profile web时,PM2 下确实打印了error: --profile <name> is required并以非零码退出——说明守卫出现之前,PM2 容器import()之后模块体是会执行的,与本文结论一致。5. 影响范围(按 tag)
apps/cli/src/bin.ts入口派发import.meta.mainimport.meta.mainimport.meta.main引入提交(2026-09-03):
e5dbccce8cfix(subprocess): move SEA bootstrap to runtime packaging—— 把顶层派发包成runCli(),并加上守卫if (import.meta.url === pathToFileURL(resolve(process.argv[1])).href)423412b7bffix(runtime): simplify executable entry dispatch—— 守卫改成if (import.meta.main)两个守卫形态在 PM2 下都失败:
argv[1]是ProcessContainerFork.js(不是bin.ts);import.meta.main在动态import()的模块里是false。换句话说,"改回argv[1]判断"并不能修复本场景(这一点是对 #6124 建议的补充)。6. 与既有讨论的关系(同守卫、不同触发面)
import.meta.main === undefined(Node < 24.2),机制相同(守卫为假 → 零输出 → exit 0),但修复建议不覆盖本文场景:它建议改回process.argv[1]判断,而 PM2 下argv[1]是容器路径,同样为假。ProcessContainerFork、ecosystem.config在 Discussions 中均无命中,因此本文这个具体机制此前没有被记录过。7. 已本地验证的两个 workaround
两个都在本机 PM2 7.0.4 + Windows + v24.20.0 上实测启动成功(打印 URL 行并监听端口)。
A. 让 tsx 的 CLI 当入口(无需新增文件)
tsx 的 CLI 会把
bin.ts作为真正的入口再执行一遍(import.meta.main === true),所以行为与手工tsx apps/cli/src/bin.ts ...完全一致。代价:进程树变成
PM2 容器 → tsx → dsh,max_memory_restart只观测到最外层的 tsx(很小),真正吃内存的是孙子进程,内存上限实际失效(pm2 stop/delete的 tree-kill 仍然正常)。B. 用一个显式调用
runCli()的 launcher(单进程,推荐)实测 PM2 上报的 PID 本身就是占用端口的进程(无额外子进程),因此
max_memory_restart、stop/kill 语义都正常。8. 建议的上游修复方向
runCli移到独立模块(例如apps/cli/src/cli.ts),bin.ts只保留无条件的顶层派发。这样既不需要任何入口守卫(PM2、systemd、Electron 等所有 wrapper 都能工作),也不影响 SEA 路径——只需把python/sdk-runtime/runtime-bootstrap.mjs的 import 目标从lib/bin.js改为该模块(它本来就是显式调用runCli(),改成 import 主体模块后不会产生双重执行)。runCli()"文档化,并提供官方 launcher 文件;同时在 README/安装指南的 PM2 章节直接给出上面 B 的写法。apps/cli/package.json补engines是同一方向的另一条线)。9. 附:复现用探针
本文所有结论均在本机实测取得:PM2 7.0.4 / Windows 11 / Node v24.20.0 / dsh master
c291e7961a;受影响 tag 范围由各 tag 的apps/cli/src/bin.ts内容比对得出。All reactions