@sleep2agi/commhub-server 0.9.0-preview.229 → 0.9.0-preview.230

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.229",
3
+ "version": "0.9.0-preview.230",
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",
@@ -1148,6 +1148,26 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
1148
1148
  expect((src.match(/const shape = /g) || []).length).toBe(1);
1149
1149
  });
1150
1150
 
1151
+ // 2026-10-31 —— **同一 body 里的两个时钟源**(外部复核:
1152
+ // 「要解耦两个读数,必须证明它们来自不同的源,而不是来自不同的字段名」)。
1153
+ // 这条同时证明两件事:
1154
+ // ① uptime 的来源是 process.uptime()(单调时钟),不是 Date.now()-startedAt;
1155
+ // ② startedAt 与 uptime 互相自洽(startedAt = now - uptime),所以它是「同一对的另一侧」。
1156
+ // 若哪天有人把 uptime 改成 Date.now()-startedAt,① 会红 —— 那时两个字段会同源、判别力归零。
1157
+ test("uptime comes from the monotonic clock (a separate source from served_at)", async () => {
1158
+ const { readFileSync } = await import("node:fs");
1159
+ const src = readFileSync(new URL("./server.ts", import.meta.url), "utf8");
1160
+ expect(src).toContain("uptime: Math.floor(process.uptime())");
1161
+ expect(src).not.toMatch(/uptime:\s*Math\.floor\(\(Date\.now\(\)\s*-/);
1162
+
1163
+ const body = await (await fetch(`${BASE}/health`)).json() as any;
1164
+ expect(Number.isInteger(body.uptime)).toBe(true);
1165
+ expect(body.uptime).toBeGreaterThanOrEqual(0);
1166
+ // 自洽:now - startedAt ≈ uptime(±5s 容差,覆盖处理时间与秒级取整)
1167
+ const derived = (Date.now() - Date.parse(body.startedAt)) / 1000;
1168
+ expect(Math.abs(derived - body.uptime)).toBeLessThanOrEqual(5);
1169
+ });
1170
+
1151
1171
  test("no dead entries: every allow-listed key is actually served to anonymous callers", async () => {
1152
1172
  const { PUBLIC_HEALTH_KEYS } = await import("./server.js");
1153
1173
  const plain = await (await fetch(`${BASE}/health`)).json() as any;
package/src/server.ts CHANGED
@@ -1199,7 +1199,15 @@ export const HEALTH_FIELD_META: Readonly<Record<string, HealthFieldMeta>> = {
1199
1199
  },
1200
1200
  api_version: { class: "gauge", granularity: "label", constant_by_design: "本进程只实现 v3;若将来并存两代,这里才会出现第二个取值" },
1201
1201
  transport: { class: "gauge", granularity: "label", constant_by_design: "本进程只实现 streamable-http(另一支 SSE-only 是历史形态,已不接受配置)" },
1202
- uptime: { class: "gauge", granularity: "cumulative" },
1202
+ uptime: {
1203
+ class: "gauge",
1204
+ granularity: "cumulative",
1205
+ // 2026-10-31 —— 这一格是**同一 body 里的第二个时钟源**(外部复核:
1206
+ // 「time ← CLOCK_REALTIME(可被 NTP 拉、可冻结);uptime ← CLOCK_MONOTONIC(只走不跳)」)。
1207
+ // ⇒ 「served_at 不动而 uptime 在走」= 冻结的是墙钟,不是进程:**单次读数、零外部依赖、有方向**。
1208
+ // 前提必须成立:uptime 来自 process.uptime()(单调),**不是** Date.now()-startedAt(同源就没判别力)。
1209
+ why: "进程已运行秒数(process.uptime(),单调时钟)。与 served_at/startedAt 不同源:墙钟被 NTP 冻结时它仍在走 ⇒ 可判「是钟停了还是进程停了」",
1210
+ },
1203
1211
  startedAt: { frozen_at_boot: true, class: "gauge", granularity: "instant", why: "窗口起点;去掉它,event_loop 里的 stall 计数就没有分母时刻戳" },
1204
1212
  sessions_count: { class: "gauge", granularity: "level" },
1205
1213
  sse_connections: { class: "gauge", granularity: "level" },