@sleep2agi/commhub-server 0.9.0-preview.181 → 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.181",
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
- if (effective !== previous && next) {
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(effective > previous ? Math.max(existing, candidate) : Math.min(existing, candidate)).toISOString();
338
+ next = new Date(Math.max(existing, candidate)).toISOString();
332
339
  }
333
340
  }
334
341
  db.run(
@@ -31,10 +31,12 @@ beforeAll(() => {
31
31
  });
32
32
 
33
33
  describe('target_offline backoff 是否真的推后 next_run_at', () => {
34
+ // 稳态回归(2026-10-28 生产实测):退避值已经等于 effective 时,原来 `effective !== previous`
35
+ // 的守卫恒假 ⇒ 不再推 next_run_at ⇒ 实际每 360s 跳一次。这里连打 6 次(eff 已进稳态)验证仍推。
34
36
  test('连续 4 次离线跳过后,next_run_at 应 ≈ now + effective(而不是 base 的倍数)', () => {
35
37
  const s = seed();
36
38
  const rows: any[] = [];
37
- for (let i = 0; i < 4; i++) {
39
+ for (let i = 0; i < 9; i++) { // 9 次 ⇒ streak 到 10 ⇒ eff 进入稳态 5760,覆盖「第二次起不推」的坑
38
40
  const at = new Date(Date.now() + i * 10).toISOString();
39
41
  const r = dispatchScheduledOccurrence(getScheduleRow(s.schedule_id)!, at, true, new Date());
40
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);
@@ -46,5 +48,9 @@ describe('target_offline backoff 是否真的推后 next_run_at', () => {
46
48
  // 断言:最后一次的 next_run_at 与 effective 同量级(允许 ±2 个 base 的容差)
47
49
  if (!last.eff) throw new Error('backoff_effective_seconds 始终为空:退避没有生效');
48
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
+ }
49
55
  });
50
56
  });