@sleep2agi/commhub-server 0.9.0-preview.184 → 0.9.0-preview.185
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.
|
|
3
|
+
"version": "0.9.0-preview.185",
|
|
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",
|
|
@@ -256,6 +256,19 @@ describe("GET /api/networks/:id/node-permission-report", () => {
|
|
|
256
256
|
// #2823 —— 调用面计数:拒绝日志给不了分母。
|
|
257
257
|
// 生产 30 天 `node_permission_log` 0 行,分不清「没人越界」和「没人碰过这些工具」,
|
|
258
258
|
// 而 #525 要切 enforce,恰恰需要一个分母。
|
|
259
|
+
describe("#2823 计数表的上限必须覆盖整个保留期", () => {
|
|
260
|
+
// 撞上限的后果是**静默归零**(callLogFull 只给已有行加次数、不插新行),
|
|
261
|
+
// 而这正是 #525 用来判「要不要切 enforce」的判据 —— 读到归零会把「没人调用」当结论。
|
|
262
|
+
// 生产实测 75 行/小时(.184 上线首小时);这里按 100 行/小时留余量。
|
|
263
|
+
test("TOOL_CALL_MAX_ROWS 覆盖 LOG_RETENTION_DAYS × 100 行/小时,否则会在保留期内静默停表", async () => {
|
|
264
|
+
const { TOOL_CALL_MAX_ROWS, LOG_RETENTION_DAYS } = await import("./node-permissions.js");
|
|
265
|
+
const worstCasePerHour = 100;
|
|
266
|
+
expect(TOOL_CALL_MAX_ROWS).toBeGreaterThanOrEqual(LOG_RETENTION_DAYS * 24 * worstCasePerHour);
|
|
267
|
+
// 反向验证这条测试有判别力:旧的 20 000 必须不满足
|
|
268
|
+
expect(20_000).toBeLessThan(LOG_RETENTION_DAYS * 24 * worstCasePerHour);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
259
272
|
describe("#2823 调用面计数(node_tool_calls)", () => {
|
|
260
273
|
const callHits = (nodeId: string, tool: string) => Number(
|
|
261
274
|
db.get<{ h: number | string | null }>(
|
package/src/node-permissions.ts
CHANGED
|
@@ -73,7 +73,21 @@ db.exec(`
|
|
|
73
73
|
`);
|
|
74
74
|
|
|
75
75
|
let callLogFull = false;
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* 行数上限。**刻意比 `LOG_MAX_ROWS`(20 000) 高一个数量级**。
|
|
78
|
+
*
|
|
79
|
+
* 为什么不能沿用 20 000:这张表的键是 `(network, node, tool, hour)` —— 每过一个小时
|
|
80
|
+
* 就是一整批新键。生产实测(.184 上线 1 小时):75 行/小时 ⇒ 1 800 行/天,
|
|
81
|
+
* 20 000 ÷ 1 800 ≈ **11 天**,而保留期是 30 天。
|
|
82
|
+
*
|
|
83
|
+
* 撞上限的后果不是「变慢」,而是 `callLogFull` 只给已有行加次数、**不再插新行**,
|
|
84
|
+
* 于是新的一小时一行都写不进去 —— 计数**静默归零**,不报错、不告警。
|
|
85
|
+
* 而这张表正是 #525「要不要切 enforce」的判据,读到归零会把「没人调用」当成结论。
|
|
86
|
+
*
|
|
87
|
+
* 200 000 行 ≈ 26 MB(实测 91 行 = 12 KB),对这张表完全可接受;
|
|
88
|
+
* 按当前速率可覆盖 30 天保留期且留 2 倍余量。
|
|
89
|
+
*/
|
|
90
|
+
export const TOOL_CALL_MAX_ROWS = 200_000;
|
|
77
91
|
|
|
78
92
|
/** 计一次「到达权限闸」的工具调用。绝不影响请求本身 —— 出错只写日志。 */
|
|
79
93
|
export function recordNodeToolCall(id: NodeIdentity, tool: string): void {
|