@sleep2agi/commhub-server 0.9.0-preview.172 → 0.9.0-preview.173
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 +1 -1
- package/src/retention.ts +21 -4
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.173",
|
|
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",
|
package/src/retention.ts
CHANGED
|
@@ -131,6 +131,14 @@ const DEFAULT_CHUNK_ROWS = 2000;
|
|
|
131
131
|
const INCREMENTAL_VACUUM_PAGES = 200;
|
|
132
132
|
const MAX_TABLE_MS = 10 * 60 * 1000;
|
|
133
133
|
|
|
134
|
+
/** 启动后第一次 sweep 的延迟;默认 60 秒(见 startRetentionSweeper 里的实测)。 */
|
|
135
|
+
function readFirstSweepDelayMs(): number {
|
|
136
|
+
const raw = process.env.COMMHUB_RETENTION_FIRST_DELAY_MS;
|
|
137
|
+
if (raw === undefined || raw.trim() === "") return 60_000;
|
|
138
|
+
const n = Number(raw);
|
|
139
|
+
return Number.isFinite(n) && n >= 0 ? Math.floor(n) : 60_000;
|
|
140
|
+
}
|
|
141
|
+
|
|
134
142
|
function readChunkRows(): number {
|
|
135
143
|
const raw = process.env.COMMHUB_RETENTION_CHUNK_ROWS;
|
|
136
144
|
const n = Number(raw);
|
|
@@ -462,6 +470,7 @@ export async function sweepRetention(cfg: RetentionConfig = readRetentionConfig(
|
|
|
462
470
|
export function startRetentionSweeper(
|
|
463
471
|
intervalMs = 60 * 60 * 1000, // 1 hour
|
|
464
472
|
cfg?: RetentionConfig,
|
|
473
|
+
firstDelayMs = readFirstSweepDelayMs(),
|
|
465
474
|
): ReturnType<typeof setInterval> {
|
|
466
475
|
// 防重入:一轮 sweep 现在会跨多个 tick(每批之间让出事件循环)。若上一轮还没
|
|
467
476
|
// 跑完就再来一轮,两轮会同时删同一批行 —— 白做功,还会把写锁争用放大。
|
|
@@ -498,9 +507,17 @@ export function startRetentionSweeper(
|
|
|
498
507
|
running = false;
|
|
499
508
|
}
|
|
500
509
|
};
|
|
501
|
-
// Fire once
|
|
502
|
-
//
|
|
503
|
-
//
|
|
504
|
-
|
|
510
|
+
// Fire once after startup so a long-running hub eventually catches up.
|
|
511
|
+
//
|
|
512
|
+
// #2614(第二轮)—— 不再 setImmediate。2026-10-27 18:11 的启动实测:
|
|
513
|
+
// ```
|
|
514
|
+
// [commhub stall] loop idle ~14085ms (served 614) ← 重连风暴 + 启动工作
|
|
515
|
+
// [commhub retention] swept in 15693ms (max 957ms) — telemetry=3320 行/13928ms
|
|
516
|
+
// ```
|
|
517
|
+
// 同一批删除在稳态是 0.24ms/行,在启动那一分钟是 4.2ms/行(慢 17 倍)——
|
|
518
|
+
// 不是删除变慢了,是它在和重连风暴抢 CPU/WAL。而这一分钟的阻塞最容易被误记成
|
|
519
|
+
// “retention 又卡了”。默认延后 60 秒(可用 COMMHUB_RETENTION_FIRST_DELAY_MS 覆盖,0=立即)。
|
|
520
|
+
if (firstDelayMs > 0) setTimeout(() => { void sweep(); }, firstDelayMs);
|
|
521
|
+
else setImmediate(() => { void sweep(); });
|
|
505
522
|
return setInterval(() => { void sweep(); }, intervalMs);
|
|
506
523
|
}
|