@sleep2agi/commhub-server 0.9.0-preview.248 → 0.9.0-preview.249
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/build-info.json +2 -2
- package/package.json +1 -1
- package/src/expiry-counters.test.ts +42 -0
- package/src/expiry-counters.ts +42 -0
- package/src/tools.ts +12 -0
package/build-info.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/commhub-server",
|
|
3
|
-
"version": "0.9.0-preview.
|
|
3
|
+
"version": "0.9.0-preview.249",
|
|
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",
|
|
@@ -67,3 +67,45 @@ describe("#3271 从未取走过的过期计数", () => {
|
|
|
67
67
|
expect(Object.keys(c.by_node)).toEqual(["a-node", "z-node"]);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
|
+
|
|
71
|
+
// ---- 派单侧硬闸(#3271)----
|
|
72
|
+
import { neverConsumeGate, NEVER_CONSUME_LIMIT } from "./expiry-counters.js";
|
|
73
|
+
|
|
74
|
+
describe("#3271 派单侧硬闸:从未取走过的目标", () => {
|
|
75
|
+
const counters = (n: number, alias = "ghost") => ({
|
|
76
|
+
since: "2026-10-31T00:00:00.000Z",
|
|
77
|
+
total: n,
|
|
78
|
+
by_node: n > 0 ? { [alias]: n } : {},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("窗口内 0–2 次 ⇒ 放行(一次两次可能是宿主重启,三次才是形态)", () => {
|
|
82
|
+
for (const n of [0, 1, 2]) {
|
|
83
|
+
expect(neverConsumeGate({ alias: "ghost", counters: counters(n), force: false, forceAllowed: true }).ok).toBe(true);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("🔴 达到阈值 ⇒ 拒绝,且拒绝体给全(alias / expiries / window_since / 下一步)", () => {
|
|
88
|
+
const r = neverConsumeGate({ alias: "ghost", counters: counters(NEVER_CONSUME_LIMIT), force: false, forceAllowed: true });
|
|
89
|
+
expect(r.ok).toBe(false);
|
|
90
|
+
if (r.ok) throw new Error("unreachable");
|
|
91
|
+
expect(r.error).toBe("target_never_consumes");
|
|
92
|
+
expect(r.alias).toBe("ghost");
|
|
93
|
+
expect(r.expiries).toBe(NEVER_CONSUME_LIMIT);
|
|
94
|
+
expect(r.window_since).toBe("2026-10-31T00:00:00.000Z");
|
|
95
|
+
expect(r.message).toContain("force:true");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("人令牌 + force ⇒ 放行(出口存在,但必须显式)", () => {
|
|
99
|
+
expect(neverConsumeGate({ alias: "ghost", counters: counters(9), force: true, forceAllowed: true }).ok).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("🔴 节点令牌不能自己放行:force 传了也不算(forceAllowed=false)", () => {
|
|
103
|
+
const r = neverConsumeGate({ alias: "ghost", counters: counters(9), force: true, forceAllowed: false });
|
|
104
|
+
expect(r.ok).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("别的节点的计数不影响本目标(分桶不是总数)", () => {
|
|
108
|
+
const c = { since: "s", total: 9, by_node: { other: 9 } };
|
|
109
|
+
expect(neverConsumeGate({ alias: "ghost", counters: c, force: false, forceAllowed: true }).ok).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
});
|
package/src/expiry-counters.ts
CHANGED
|
@@ -49,3 +49,45 @@ export function resetNeverConsumedExpiryCountersForTest(now = new Date()): void
|
|
|
49
49
|
counters.clear();
|
|
50
50
|
since = now.toISOString();
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* #3271 —— 派单侧的**硬闸**判据(纯函数,便于单测)。
|
|
55
|
+
*
|
|
56
|
+
* 起因:一台节点连续 9 次「等满 60 分钟未取走」,而每一次都只是「又过期了一条」的通知。
|
|
57
|
+
* 派单方只能靠人记住。⇒ 这里把它变成一个**在派单那一刻就拒绝**的判据,并留一个显式出口。
|
|
58
|
+
*
|
|
59
|
+
* 三条设计选择:
|
|
60
|
+
* ① 阈值取「本进程窗口内 ≥3 次」——一次两次可能是宿主重启,三次已经是形态。
|
|
61
|
+
* ② 出口是 `force`,且**只有人**能用(节点令牌不能自己给自己放行)——与既有的
|
|
62
|
+
* `assertNodeHealthy(force, forceAllowed)` 同一条规矩。
|
|
63
|
+
* ③ 拒绝体给全:alias / expiries / window_since / 下一步。只说 "refused" 会让调用方去猜。
|
|
64
|
+
*/
|
|
65
|
+
export const NEVER_CONSUME_LIMIT = 3;
|
|
66
|
+
|
|
67
|
+
export type NeverConsumeGate =
|
|
68
|
+
| { ok: true }
|
|
69
|
+
| { ok: false; error: "target_never_consumes"; alias: string; expiries: number; window_since: string; message: string };
|
|
70
|
+
|
|
71
|
+
export function neverConsumeGate(input: {
|
|
72
|
+
alias: string;
|
|
73
|
+
counters: NeverConsumedExpiryCounters;
|
|
74
|
+
force: boolean;
|
|
75
|
+
/** 人令牌才能用 force;节点令牌传 false。 */
|
|
76
|
+
forceAllowed: boolean;
|
|
77
|
+
limit?: number;
|
|
78
|
+
}): NeverConsumeGate {
|
|
79
|
+
const limit = input.limit ?? NEVER_CONSUME_LIMIT;
|
|
80
|
+
const expiries = input.counters.by_node[input.alias] ?? 0;
|
|
81
|
+
if (expiries < limit) return { ok: true };
|
|
82
|
+
if (input.force && input.forceAllowed) return { ok: true };
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
error: "target_never_consumes",
|
|
86
|
+
alias: input.alias,
|
|
87
|
+
expiries,
|
|
88
|
+
window_since: input.counters.since,
|
|
89
|
+
message:
|
|
90
|
+
`this target has expired ${expiries} task(s) without ever taking one (window since ${input.counters.since}); `
|
|
91
|
+
+ `nothing will queue correctly here until it consumes again — pass force:true (user tokens) if you know it recovered`,
|
|
92
|
+
};
|
|
93
|
+
}
|
package/src/tools.ts
CHANGED
|
@@ -112,6 +112,7 @@ import { parseHubTimestamp } from "./hub-timestamp";
|
|
|
112
112
|
import { noteTerminalResultRead, purgeLogsResultNow, sweepNodeRequestContent } from "./node-request-retention.js";
|
|
113
113
|
import { listTaskLateReplies } from "./task-late-replies.js";
|
|
114
114
|
import { pollPacer } from "./poll-pacing.js";
|
|
115
|
+
import { neverConsumedExpiryCounters, neverConsumeGate } from "./expiry-counters.js";
|
|
115
116
|
import { auditDepartment, createDepartment, deleteDepartment, listDepartments, setAgentDepartment, updateDepartment } from "./departments.js";
|
|
116
117
|
|
|
117
118
|
function ts(): string {
|
|
@@ -2259,6 +2260,17 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2259
2260
|
const hg = assertNodeHealthy(targetAlias, effectiveNetId ?? null, { force, forceAllowed: !callerTokenIsNetwork });
|
|
2260
2261
|
if (!hg.ok) return { content: [{ type: "text" as const, text: JSON.stringify(hg) }] };
|
|
2261
2262
|
}
|
|
2263
|
+
// #3271 —— 同一形状的第二道闸:**这台节点从未取走过任务**(本进程窗口内 ≥3 次过期且 consumed_at 全空)。
|
|
2264
|
+
// 原来这里什么都没有:每次只是「又过期了一条」的通知,派单方只能靠人记住。
|
|
2265
|
+
{
|
|
2266
|
+
const gate = neverConsumeGate({
|
|
2267
|
+
alias: targetAlias,
|
|
2268
|
+
counters: neverConsumedExpiryCounters(),
|
|
2269
|
+
force: force === true,
|
|
2270
|
+
forceAllowed: !callerTokenIsNetwork,
|
|
2271
|
+
});
|
|
2272
|
+
if (!gate.ok) return { content: [{ type: "text" as const, text: JSON.stringify(gate) }] };
|
|
2273
|
+
}
|
|
2262
2274
|
|
|
2263
2275
|
console.log(`[${ts()}] ${from_session} → send_task → ${targetAlias}: ${task.slice(0, 60)}${priority === "high" ? " [HIGH]" : ""}${canonical.renamed ? ` [renamed from ${alias}]` : ""}`);
|
|
2264
2276
|
const senderIdentity = callerTokenIsNetwork ? resolveNodeCaller(callerTokenId) : null;
|