@sleep2agi/commhub-server 0.9.0-preview.180 → 0.9.0-preview.182
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.182",
|
|
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",
|
|
@@ -324,11 +324,18 @@ export function applyNoProgressBackoff(scheduleId: string, now = new Date()): {
|
|
|
324
324
|
const effective = Math.min(cap, base * 2 ** Math.min(streak - from + 1, 5));
|
|
325
325
|
const previous = row.backoff_effective_seconds ?? base;
|
|
326
326
|
let next = row.next_run_at;
|
|
327
|
-
|
|
327
|
+
// 🔴 生产实测(2026-10-28,`.181` 的两行日志):
|
|
328
|
+
// offline-backoff effective=5760s next_before=+180s ← 退避值没推进去
|
|
329
|
+
// offline-backoff-final next_after=+360s ← 二次 advance 又加了一个 base
|
|
330
|
+
// 根因就在这里:原来用 `effective !== previous` 做守卫,退避一旦进入**稳态**(例如已是 5760),
|
|
331
|
+
// 这个条件恒为 false ⇒ 不再推 next_run_at;而调用方在此之前刚 `advance()` 把 next 重置成 +base。
|
|
332
|
+
// 于是「退避值写着 5760,实际每 360s 跳一次」,且永远不会自愈。
|
|
333
|
+
// 正确语义:只要这一步是「同因跳过」,next_run_at 至少要 ≥ now + effective(只能往后推,不往前拉)。
|
|
334
|
+
if (next) {
|
|
328
335
|
const candidate = now.getTime() + effective * 1000;
|
|
329
336
|
const existing = parseHubTimestamp(next);
|
|
330
337
|
if (existing !== null) {
|
|
331
|
-
next = new Date(
|
|
338
|
+
next = new Date(Math.max(existing, candidate)).toISOString();
|
|
332
339
|
}
|
|
333
340
|
}
|
|
334
341
|
db.run(
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// 探针:target_offline 连续跳过后,next_run_at 到底被推到哪里?
|
|
2
|
+
// 生产现象(2026-10-28 08:45):backoff_effective_seconds=5760,但实际间隔 360s。
|
|
3
|
+
// 这里用真实调度入口 dispatchScheduledOccurrence 复现,看 next_run_at 与实际 cadence。
|
|
4
|
+
// Run: COMMHUB_DB=/tmp/target-offline-backoff.db bun test src/scheduled-offline-backoff-probe.test.ts
|
|
5
|
+
import { describe, expect, test, beforeAll } from 'bun:test';
|
|
6
|
+
import { register } from './auth.js';
|
|
7
|
+
import { db } from './db.js';
|
|
8
|
+
import { dispatchScheduledOccurrence, getScheduleRow } from './scheduled-tasks.js';
|
|
9
|
+
|
|
10
|
+
const stamp = Date.now();
|
|
11
|
+
const TARGET_ID = `n_offb_${stamp}`, TARGET = `offb-${stamp}`;
|
|
12
|
+
let NET = '', USER = '';
|
|
13
|
+
|
|
14
|
+
function seed() {
|
|
15
|
+
const id = `sched_offb_${crypto.randomUUID()}`;
|
|
16
|
+
db.run(`INSERT INTO scheduled_tasks (schedule_id, network_id, created_by, name, target_node_id, target_alias,
|
|
17
|
+
task_content, priority, schedule_type, schedule_json, timezone, status, next_run_at, overlap_policy)
|
|
18
|
+
VALUES (?1,?2,?3,'offb',?4,?5,'x','normal','interval','{"type":"interval","every_seconds":180}','Asia/Shanghai','active',datetime('now','+3 minutes'),'skip')`,
|
|
19
|
+
[id, NET, USER, TARGET_ID, TARGET]);
|
|
20
|
+
return getScheduleRow(id)!;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
const owner = register(`offb_owner_${stamp}`, 'OffbOwnerPassw0rd!', undefined, 'seed');
|
|
25
|
+
expect(owner.ok).toBe(true);
|
|
26
|
+
NET = owner.network_id!; USER = owner.user!.user_id;
|
|
27
|
+
db.run("INSERT INTO nodes (node_id, node_name, alias, runtime, network_id, owner_user_id) VALUES (?1,?2,?2,'codex',?3,?4)", [TARGET_ID, TARGET, NET, USER]);
|
|
28
|
+
// 目标会话:10 分钟没心跳 ⇒ offline
|
|
29
|
+
db.run("INSERT INTO sessions (resume_id, alias, status, node_id, network_id, last_seen_at) VALUES (?1,?2,'idle',?3,?4,datetime('now','-10 minutes'))",
|
|
30
|
+
[`r_offb_${stamp}`, TARGET, TARGET_ID, NET]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('target_offline backoff 是否真的推后 next_run_at', () => {
|
|
34
|
+
// 稳态回归(2026-10-28 生产实测):退避值已经等于 effective 时,原来 `effective !== previous`
|
|
35
|
+
// 的守卫恒假 ⇒ 不再推 next_run_at ⇒ 实际每 360s 跳一次。这里连打 6 次(eff 已进稳态)验证仍推。
|
|
36
|
+
test('连续 4 次离线跳过后,next_run_at 应 ≈ now + effective(而不是 base 的倍数)', () => {
|
|
37
|
+
const s = seed();
|
|
38
|
+
const rows: any[] = [];
|
|
39
|
+
for (let i = 0; i < 9; i++) { // 9 次 ⇒ streak 到 10 ⇒ eff 进入稳态 5760,覆盖「第二次起不推」的坑
|
|
40
|
+
const at = new Date(Date.now() + i * 10).toISOString();
|
|
41
|
+
const r = dispatchScheduledOccurrence(getScheduleRow(s.schedule_id)!, at, true, new Date());
|
|
42
|
+
const after = db.get<any>("SELECT backoff_effective_seconds, backoff_streak, next_run_at FROM scheduled_tasks WHERE schedule_id = ?1", s.schedule_id);
|
|
43
|
+
const nextMs = after.next_run_at ? Date.parse(String(after.next_run_at).replace(' ', 'T') + (String(after.next_run_at).endsWith('Z') ? '' : 'Z')) : NaN;
|
|
44
|
+
rows.push({ i, status: r.status, eff: after.backoff_effective_seconds, streak: after.backoff_streak, next_raw: after.next_run_at, gap_s: Number.isFinite(nextMs) ? Math.round((nextMs - Date.parse(at))/1000) : 'NaN' });
|
|
45
|
+
}
|
|
46
|
+
console.log('每次 fire 后:', JSON.stringify(rows));
|
|
47
|
+
const last = rows[rows.length - 1];
|
|
48
|
+
// 断言:最后一次的 next_run_at 与 effective 同量级(允许 ±2 个 base 的容差)
|
|
49
|
+
if (!last.eff) throw new Error('backoff_effective_seconds 始终为空:退避没有生效');
|
|
50
|
+
if (last.gap_s < last.eff) throw new Error(`next_run_at 只推后 ${last.gap_s}s,但 effective=${last.eff}s`);
|
|
51
|
+
// 稳态:所有 fire 的 gap 都必须 ≥ 当次的 effective(没有「第二次起就不推」)
|
|
52
|
+
for (const row of rows) {
|
|
53
|
+
if (row.eff && row.gap_s < row.eff) throw new Error(`第 ${row.i} 次:gap=${row.gap_s}s < effective=${row.eff}s(稳态没推)`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
package/src/scheduled-tasks.ts
CHANGED
|
@@ -456,7 +456,13 @@ export function dispatchScheduledOccurrence(row: ScheduledRow, scheduledFor: str
|
|
|
456
456
|
if (bo && bo.effective_seconds) {
|
|
457
457
|
const sched = db.get<{ next_run_at: string | null }>("SELECT next_run_at FROM scheduled_tasks WHERE schedule_id = ?1", row.schedule_id);
|
|
458
458
|
const at = parseHubTimestamp(sched?.next_run_at);
|
|
459
|
+
// 可观测性(不是装饰):生产出现「backoff_effective_seconds=5760 但实际每 6 分钟跳一次」,
|
|
460
|
+
// 只看列分不清是哪一步把 next_run_at 写回去了。这行把「算出的 eff」与「此刻落库的 next」
|
|
461
|
+
// 打在一起;再配上本函数返回前的最终值,就能对上账。
|
|
462
|
+
console.error(`[commhub scheduled-tasks] offline-backoff schedule=${row.schedule_id} cause=${bo.cause} streak=${bo.streak} effective=${bo.effective_seconds}s next_before=${sched?.next_run_at ?? 'null'}`);
|
|
459
463
|
if (at !== null) advance({ ...row, target_alias: targetNode.alias }, scheduledFor, new Date(at));
|
|
464
|
+
const after = db.get<{ next_run_at: string | null }>("SELECT next_run_at FROM scheduled_tasks WHERE schedule_id = ?1", row.schedule_id);
|
|
465
|
+
console.error(`[commhub scheduled-tasks] offline-backoff-final schedule=${row.schedule_id} next_after=${after?.next_run_at ?? 'null'}`);
|
|
460
466
|
}
|
|
461
467
|
} catch (e: any) {
|
|
462
468
|
console.error(`[scheduled-tasks] no-progress backoff failed schedule=${row.schedule_id}: ${e?.message || e}`);
|