@sleep2agi/commhub-server 0.9.0-preview.201 → 0.9.0-preview.202

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.9.0-preview.201",
3
+ "version": "0.9.0-preview.202",
4
4
  "description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and MCP tools (17 collaboration-core + node/provider ops tools; authoritative list: docs-site/docs/api/mcp-tools.md).",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -137,3 +137,24 @@ describe("db-adapter: 慢 SQL 日志", () => {
137
137
  expect(long.length).toBeLessThanOrEqual("[commhub slow-sql] 1200ms ".length + 160);
138
138
  });
139
139
  });
140
+
141
+ // #2721 —— 启动预热窗内的 gap 不算停顿。
142
+ //
143
+ // 实测:2026-10-29 进程 22:21:06 启动,14:21:09.835Z(= 启动后 3 秒)记到 gap 2972ms / stall 2722ms。
144
+ // 那是模块加载 + 打开 DB + 迁移,不是线上卡顿。不排除它的后果是:每次部署都会在 /health 留一条
145
+ // 与真实卡顿同形的记录,事后无法区分。
146
+ describe("#2721 启动预热不算停顿", () => {
147
+ test("预热窗内的 tick gap 不计入 stalls(窗口外照常计)", async () => {
148
+ const stalls: string[] = [];
149
+ const timer = startEventLoopLagMonitor({
150
+ intervalMs: 10,
151
+ thresholdMs: 1,
152
+ warmupMs: 120,
153
+ log: (m) => stalls.push(m),
154
+ });
155
+ await new Promise((r) => setTimeout(r, 300));
156
+ clearInterval(timer as unknown as ReturnType<typeof setInterval>);
157
+ // 预热窗内的模拟拖延不该产生 stall 日志;窗外的真实间隔是 ~10ms,也不该触发 threshold。
158
+ expect(stalls).toHaveLength(0);
159
+ });
160
+ });
@@ -123,12 +123,20 @@ export function startEventLoopLagMonitor(opts: {
123
123
  thresholdMs?: number;
124
124
  log?: (msg: string) => void;
125
125
  rssMb?: () => number;
126
+ /** #2721 —— 启动预热窗(毫秒),窗内的 tick gap 不计入停顿。默认读 COMMHUB_STALL_WARMUP_MS / 10000。 */
127
+ warmupMs?: number;
126
128
  } = {}): ReturnType<typeof setInterval> {
127
129
  const intervalMs = opts.intervalMs ?? Math.max(50, envMs("COMMHUB_STALL_TICK_MS", 250));
128
130
  const thresholdMs = opts.thresholdMs ?? envMs("COMMHUB_STALL_LOG_MS", 2000);
129
131
  const log = opts.log ?? ((m: string) => console.log(m));
130
132
  const rssMb = opts.rssMb ?? (() => Math.round(process.memoryUsage().rss / 1048576));
131
133
  let last = performance.now();
134
+ const startedAt = last;
135
+ // #2721 —— 启动预热不算停顿。
136
+ // 实测:2026-10-29 这次进程 22:21:06 起来,14:21:09.835Z 记到一次 gap 2972ms,
137
+ // 也就是**启动后 3 秒**。那段时间在做模块加载 / 打开 DB / 迁移,第一个 tick 必然偏大。
138
+ // 不排除它的后果是:每次部署都会在 `/health` 里留一条「停顿」,而它和线上真实卡顿长得一模一样。
139
+ const warmupMs = opts.warmupMs ?? envMs("COMMHUB_STALL_WARMUP_MS", 10_000);
132
140
  const timer = setInterval(() => {
133
141
  const now = performance.now();
134
142
  const gap = now - last;
@@ -136,6 +144,7 @@ export function startEventLoopLagMonitor(opts: {
136
144
  const rss = rssMb();
137
145
  const served = servedSinceTick;
138
146
  servedSinceTick = 0;
147
+ if (now - startedAt < warmupMs) return; // 预热窗内只更新 last,不记 gap/停顿
139
148
  const stall = recordGap(gap, { intervalMs, thresholdMs, rssMb: rss, served });
140
149
  if (thresholdMs > 0 && stall >= thresholdMs) {
141
150
  // 和 retention/slow-sql 的日志同一前缀,方便 grep。