@sleep2agi/commhub-server 0.9.0-preview.218 → 0.9.0-preview.219

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.218",
3
+ "version": "0.9.0-preview.219",
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",
@@ -13,6 +13,7 @@ import {
13
13
  isAllowedToChangeFlag,
14
14
  computeApplyMode,
15
15
  readOpencodeSnapshotFlags,
16
+ readConfigUpdateCapable,
16
17
  validatePatch,
17
18
  narrowChannelsPatch,
18
19
  } from "./config-apply-validate";
@@ -453,3 +454,18 @@ describe("Codex config flags (#815)", () => {
453
454
  .toBe("flags.modelReasoningEffort");
454
455
  });
455
456
  });
457
+
458
+ // 裸起节点(无 supervisor)收到 restart-tier 变更会安静地死掉:
459
+ // 写配置 → ack restarting → exit 75 → 没人拉起 → 更新判 timeout,
460
+ // 而调用方只看到「超时」。这里锁住「把后果说在前面」的读法。
461
+ describe("readConfigUpdateCapable", () => {
462
+ test("true / false / absent / junk", () => {
463
+ expect(readConfigUpdateCapable('{"config_update_capable":true}')).toBe(true);
464
+ expect(readConfigUpdateCapable('{"config_update_capable":false}')).toBe(false);
465
+ expect(readConfigUpdateCapable('{"model":"x"}')).toBeNull();
466
+ expect(readConfigUpdateCapable("not json")).toBeNull();
467
+ expect(readConfigUpdateCapable(null)).toBeNull();
468
+ // 非布尔一律 unknown,不能当成 false —— 否则会给没上报的节点发警告
469
+ expect(readConfigUpdateCapable('{"config_update_capable":"false"}')).toBeNull();
470
+ });
471
+ });
@@ -225,6 +225,33 @@ export function isHotModelSwitchSupported(
225
225
  return opencodeMode === "copresence";
226
226
  }
227
227
 
228
+ /**
229
+ * Read `config_update_capable` from `nodes.config_snapshot`.
230
+ *
231
+ * agent-node reports this as "this process runs under a supervisor wrapper that
232
+ * honours the sentinel-75 restart path" (agent-node/src/cli.ts report_status).
233
+ * A bare-spawn node (`nohup node cli.js …`, no pm2/anet wrapper) reports
234
+ * `false` — and a restart-tier patch on such a node writes the config, acks
235
+ * `restarting`, exits 75, and **nothing respawns it**. The update then sits in
236
+ * `pending`/`restarting` until the 60s reaper marks it `timeout`, so the caller
237
+ * only ever sees "timed out" and never learns that the node is now down.
238
+ *
239
+ * Absent/unparseable snapshot → `null` ("unknown"), never `false`: we must not
240
+ * warn on nodes that simply haven't reported it yet.
241
+ */
242
+ export function readConfigUpdateCapable(configSnapshot: unknown): boolean | null {
243
+ let parsed: any = null;
244
+ try {
245
+ parsed = typeof configSnapshot === "string"
246
+ ? (configSnapshot ? JSON.parse(configSnapshot) : null)
247
+ : configSnapshot;
248
+ } catch {
249
+ return null;
250
+ }
251
+ const value = parsed?.config_update_capable;
252
+ return typeof value === "boolean" ? value : null;
253
+ }
254
+
228
255
  /**
229
256
  * Classify the patch's required apply mode. Empty patch (model + flags
230
257
  * both empty, no channels) → "restart_only" (used by restart_node tool).
package/src/tools.ts CHANGED
@@ -99,6 +99,7 @@ import {
99
99
  EDITABLE_CHANNELS,
100
100
  computeApplyMode,
101
101
  readOpencodeSnapshotFlags,
102
+ readConfigUpdateCapable,
102
103
  validatePatch,
103
104
  narrowChannelsPatch,
104
105
  isAllowedToChangeFlag,
@@ -3759,10 +3760,29 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
3759
3760
 
3760
3761
  pushEvent(node.alias, { type: "config_update", update_id: updateId }, networkId);
3761
3762
 
3763
+ // 裸起节点(无 supervisor)收到 restart-tier 变更会 **安静地死掉**:
3764
+ // 它写配置 → ack restarting → exit 75,而没人拉起;
3765
+ // 更新停在 pending/restarting,60s 后被 reaper 判 timeout ——
3766
+ // 调用方看到的只有「超时」,永远学不到「这台节点现在是下线的」。
3767
+ // 不擅自拒绝(会破坏合法流程),但必须把后果说在前面。
3768
+ const configUpdateCapable = readConfigUpdateCapable(node.config_snapshot);
3769
+ const warnings = applyMode !== "hot" && configUpdateCapable === false
3770
+ ? [{
3771
+ code: "restart_requires_supervisor",
3772
+ message: "this node reports config_update_capable=false (bare spawn, no supervisor). "
3773
+ + "A restart-tier patch will make it exit 75 and nothing will respawn it — the update "
3774
+ + "will time out and the node will stay offline. Use Stop then Start, or a supervised "
3775
+ + "process (anet start / pm2) before sending restart-tier changes.",
3776
+ }]
3777
+ : undefined;
3778
+
3762
3779
  return {
3763
3780
  content: [{
3764
3781
  type: "text" as const,
3765
- text: JSON.stringify({ ok: true, update_id: updateId, apply_mode: applyMode }),
3782
+ text: JSON.stringify({
3783
+ ok: true, update_id: updateId, apply_mode: applyMode,
3784
+ ...(warnings ? { warnings } : {}),
3785
+ }),
3766
3786
  }],
3767
3787
  };
3768
3788
  },