@sleep2agi/commhub-server 0.9.0-preview.171 → 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/src/scheduled-failures.ts +105 -0
- package/src/scheduled-noprogress-backoff-2622.test.ts +117 -0
- package/src/scheduled-tasks.ts +20 -1
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
|
}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
import { db, setScheduledRunTerminalHook } from "./db.js";
|
|
21
21
|
import { sendAgentNotice } from "./agent-notice.js";
|
|
22
|
+
import { parseHubTimestamp } from "./hub-timestamp.js";
|
|
22
23
|
|
|
23
24
|
export const SCHEDULE_FAILING_NOTICE_KIND = "schedule_failing";
|
|
24
25
|
const ERROR_PREVIEW_CHARS = 300;
|
|
@@ -226,6 +227,110 @@ export function applyFailureBackoff(scheduleId: string, now = new Date()): { str
|
|
|
226
227
|
return { streak, effective_seconds: effective };
|
|
227
228
|
}
|
|
228
229
|
|
|
230
|
+
/**
|
|
231
|
+
* #2622(第二轮)—— 「跑不起来」的两类跳过也要退避。
|
|
232
|
+
*
|
|
233
|
+
* 生产 24h(2026-10-27):`previous_run_active` 2286 条、`target_offline` 1951 条,
|
|
234
|
+
* 而 `failureStreak()` 只数 `status='failed'`,**skipped 完全不计**,
|
|
235
|
+
* 于是一个 `every_seconds=180` 的排程可以在目标永久离线的状态下每 3 分钟写一行 skip,
|
|
236
|
+
* 一天 470 条,永不减速。
|
|
237
|
+
*
|
|
238
|
+
* 这里只做「放慢」,不改变派发语义:
|
|
239
|
+
* · 同一 error_code 连续出现 ≥ N(默认 3)⇒ 间隔按 2 倍放大,上限 1800 秒;
|
|
240
|
+
* · `target_offline` 的链用更长的上限(7200 秒 = 2 小时)——目标不在时没有理由每 3 分钟试一次;
|
|
241
|
+
* · 换链(原因变了)或出现成功 ⇒ 立刻回到原间隔;
|
|
242
|
+
* · 与 `no_change_backoff=1` 的排程互斥(那套逻辑自己拥有 backoff_* 三列)。
|
|
243
|
+
*/
|
|
244
|
+
const NO_PROGRESS_CODES = ["previous_run_active", "target_offline"] as const;
|
|
245
|
+
export type NoProgressCause = (typeof NO_PROGRESS_CODES)[number];
|
|
246
|
+
|
|
247
|
+
function noProgressFromRuns(runs: Array<{ status: string; error_code: string | null }>): { cause: NoProgressCause | null; streak: number } {
|
|
248
|
+
const first = runs[0];
|
|
249
|
+
if (!first) return { cause: null, streak: 0 };
|
|
250
|
+
let cause: NoProgressCause | null = null;
|
|
251
|
+
if (first.status === "failed") cause = null; // 由 applyFailureBackoff 负责,避免两套逻辑抢同一列
|
|
252
|
+
else if (first.status === "skipped" && (NO_PROGRESS_CODES as readonly string[]).includes(first.error_code ?? "")) {
|
|
253
|
+
cause = first.error_code as NoProgressCause;
|
|
254
|
+
}
|
|
255
|
+
if (!cause) return { cause: null, streak: 0 };
|
|
256
|
+
let streak = 0;
|
|
257
|
+
for (const r of runs) {
|
|
258
|
+
if (r.status !== "skipped" || r.error_code !== cause) break;
|
|
259
|
+
streak++;
|
|
260
|
+
}
|
|
261
|
+
return { cause, streak };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function noProgressBackoffRuns(): number {
|
|
265
|
+
return envInt("COMMHUB_SCHEDULE_NO_PROGRESS_BACKOFF_RUNS", 3, 1);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function applyNoProgressBackoff(scheduleId: string, now = new Date()): { streak: number; effective_seconds: number | null; cause: NoProgressCause } | null {
|
|
269
|
+
const from = noProgressBackoffRuns();
|
|
270
|
+
if (from <= 0) return null;
|
|
271
|
+
const row = db.get<any>(
|
|
272
|
+
`SELECT schedule_id, revision, status, schedule_type, schedule_json, no_change_backoff,
|
|
273
|
+
backoff_effective_seconds, next_run_at
|
|
274
|
+
FROM scheduled_tasks WHERE schedule_id = ?1`,
|
|
275
|
+
scheduleId,
|
|
276
|
+
);
|
|
277
|
+
if (!row || row.status !== "active" || row.no_change_backoff === 1) return null;
|
|
278
|
+
if (row.schedule_type !== "interval") return null;
|
|
279
|
+
let spec: any = null;
|
|
280
|
+
try { spec = JSON.parse(row.schedule_json || "{}"); } catch { spec = null; }
|
|
281
|
+
const base = spec && spec.type === "interval" ? Number(spec.every_seconds) : NaN;
|
|
282
|
+
if (!Number.isFinite(base) || base <= 0) return null;
|
|
283
|
+
|
|
284
|
+
const runs = db.all<{ status: string; error_code: string | null }>(
|
|
285
|
+
`SELECT status, error_code FROM scheduled_task_runs
|
|
286
|
+
WHERE schedule_id = ?1 ORDER BY scheduled_for DESC, created_at DESC LIMIT 12`,
|
|
287
|
+
scheduleId,
|
|
288
|
+
);
|
|
289
|
+
const { cause, streak } = noProgressFromRuns(runs);
|
|
290
|
+
|
|
291
|
+
// 回到原间隔(成功 / 换链 / 未达阈值都走这里;只在真的退避过时才写)
|
|
292
|
+
const restore = () => {
|
|
293
|
+
if ((row.backoff_streak ?? 0) === 0 && row.backoff_effective_seconds == null) return;
|
|
294
|
+
// next_run_at 是 hub 的 TEXT UTC(无时区标记),必须走 parseHubTimestamp
|
|
295
|
+
const cur = parseHubTimestamp(row.next_run_at);
|
|
296
|
+
const next = cur === null
|
|
297
|
+
? row.next_run_at
|
|
298
|
+
: new Date(Math.min(cur, now.getTime() + base * 1000)).toISOString();
|
|
299
|
+
db.run(
|
|
300
|
+
`UPDATE scheduled_tasks SET backoff_streak = 0, backoff_effective_seconds = NULL, next_run_at = ?1,
|
|
301
|
+
updated_at = datetime('now') WHERE schedule_id = ?2 AND revision = ?3 AND status = 'active'`,
|
|
302
|
+
[next, scheduleId, row.revision],
|
|
303
|
+
);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
if (!cause) { restore(); return null; }
|
|
307
|
+
|
|
308
|
+
// 上限按原因分开:
|
|
309
|
+
// previous_run_active —— 上一次还在跑,30 分钟足够等到它结束;
|
|
310
|
+
// target_offline —— 目标连续 6 次不在(按 180s 基底已是 18 分钟),
|
|
311
|
+
// 再用 3 分钟一次的节奏去敲没有意义;2 小时一次仍能及时接住它回来。
|
|
312
|
+
// 判据:#2622「同类原因日增量 ≤20」——180s 基底配 2 小时上限 ⇒ 12 次/天。
|
|
313
|
+
const cap = cause === "target_offline" ? 7200 : 1800;
|
|
314
|
+
if (streak < from) { restore(); return null; }
|
|
315
|
+
|
|
316
|
+
const effective = Math.min(cap, base * 2 ** Math.min(streak - from + 1, 5));
|
|
317
|
+
const previous = row.backoff_effective_seconds ?? base;
|
|
318
|
+
let next = row.next_run_at;
|
|
319
|
+
if (effective !== previous && next) {
|
|
320
|
+
const candidate = now.getTime() + effective * 1000;
|
|
321
|
+
const existing = parseHubTimestamp(next);
|
|
322
|
+
if (existing !== null) {
|
|
323
|
+
next = new Date(effective > previous ? Math.max(existing, candidate) : Math.min(existing, candidate)).toISOString();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
db.run(
|
|
327
|
+
`UPDATE scheduled_tasks SET backoff_streak = ?1, backoff_effective_seconds = ?2, next_run_at = ?3,
|
|
328
|
+
updated_at = datetime('now') WHERE schedule_id = ?4 AND revision = ?5 AND status = 'active'`,
|
|
329
|
+
[streak, effective, next, scheduleId, row.revision],
|
|
330
|
+
);
|
|
331
|
+
return { streak, effective_seconds: effective, cause };
|
|
332
|
+
}
|
|
333
|
+
|
|
229
334
|
/** GET /runs 的附加字段。 */
|
|
230
335
|
export function failureSummary(scheduleId: string): { consecutive_failures: number; failure_alert_threshold: number; last_failure_alert_at: string | null } {
|
|
231
336
|
const streak = failureStreak(scheduleId);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// #2622(第二轮)—— 「跑不起来」的两类跳过也要退避。
|
|
2
|
+
//
|
|
3
|
+
// 生产 24h(2026-10-27):previous_run_active 2286 条、target_offline 1951 条,
|
|
4
|
+
// 而 failureStreak 只数 status='failed',skipped 完全不计 ⇒ 永远按原速重试。
|
|
5
|
+
//
|
|
6
|
+
// 这个文件钉住四件事:
|
|
7
|
+
// 1. 同一 error_code 连续 ≥3 次 ⇒ 间隔放大(有上限:previous_run_active 1800s / target_offline 3600s);
|
|
8
|
+
// 2. 换链(原因变了)或出现成功 ⇒ 立刻回到原间隔;
|
|
9
|
+
// 3. no_change_backoff=1 的排程由另一套逻辑拥有 backoff 列,这里完全不介入;
|
|
10
|
+
// 4. 非 interval 排程不介入。
|
|
11
|
+
|
|
12
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
13
|
+
import { register } from "./auth.js";
|
|
14
|
+
import { db } from "./db.js";
|
|
15
|
+
import { applyNoProgressBackoff, noProgressBackoffRuns } from "./scheduled-failures.js";
|
|
16
|
+
|
|
17
|
+
const stamp = Date.now();
|
|
18
|
+
let NET = "";
|
|
19
|
+
let creatorId = "";
|
|
20
|
+
|
|
21
|
+
function seedSchedule(everySeconds = 180, extra: Record<string, unknown> = {}) {
|
|
22
|
+
const id = `sched_np_${crypto.randomUUID()}`;
|
|
23
|
+
db.run(
|
|
24
|
+
`INSERT INTO scheduled_tasks
|
|
25
|
+
(schedule_id, network_id, created_by, name, target_node_id, target_alias, task_content, priority,
|
|
26
|
+
schedule_type, schedule_json, timezone, status, next_run_at, overlap_policy)
|
|
27
|
+
VALUES (?1, ?2, ?3, 'np fixture', 'n_np', 'np-node', 'x', 'normal', 'interval', ?4,
|
|
28
|
+
'Asia/Shanghai', 'active', ?5, 'skip')`,
|
|
29
|
+
[id, NET, creatorId, JSON.stringify({ type: "interval", every_seconds: everySeconds }),
|
|
30
|
+
new Date(Date.now() + everySeconds * 1000).toISOString()],
|
|
31
|
+
);
|
|
32
|
+
for (const [k, v] of Object.entries(extra)) db.run(`UPDATE scheduled_tasks SET ${k} = ?1 WHERE schedule_id = ?2`, [v as any, id]);
|
|
33
|
+
return id;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let seq = 0;
|
|
37
|
+
function addRun(scheduleId: string, status: string, code: string | null) {
|
|
38
|
+
seq += 1;
|
|
39
|
+
const when = new Date(Date.now() + seq * 1000).toISOString();
|
|
40
|
+
db.run(
|
|
41
|
+
`INSERT INTO scheduled_task_runs (run_id, schedule_id, network_id, scheduled_for, status, error_code, created_at)
|
|
42
|
+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?4)`,
|
|
43
|
+
[`srun_np_${crypto.randomUUID()}`, scheduleId, NET, when, status, code],
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const reload = (id: string) => db.get<any>("SELECT * FROM scheduled_tasks WHERE schedule_id = ?1", id)!;
|
|
48
|
+
|
|
49
|
+
beforeAll(async () => {
|
|
50
|
+
const auth = register(`np_owner_${stamp}`, "Np-Owner-Strong-1!", undefined, "tester");
|
|
51
|
+
expect(auth.ok).toBe(true);
|
|
52
|
+
NET = auth.network_id!;
|
|
53
|
+
creatorId = auth.user_id!;
|
|
54
|
+
delete process.env.COMMHUB_SCHEDULE_NO_PROGRESS_BACKOFF_RUNS;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterAll(() => { delete process.env.COMMHUB_SCHEDULE_NO_PROGRESS_BACKOFF_RUNS; });
|
|
58
|
+
|
|
59
|
+
describe("applyNoProgressBackoff (#2622)", () => {
|
|
60
|
+
test("defaults to 3 consecutive same-cause skips", () => {
|
|
61
|
+
expect(noProgressBackoffRuns()).toBe(3);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("target_offline streak widens the interval (capped at 2h)", () => {
|
|
65
|
+
const id = seedSchedule(180);
|
|
66
|
+
for (let i = 0; i < 4; i++) addRun(id, "skipped", "target_offline");
|
|
67
|
+
const r = applyNoProgressBackoff(id)!;
|
|
68
|
+
expect(r.cause).toBe("target_offline");
|
|
69
|
+
expect(r.streak).toBe(4);
|
|
70
|
+
expect(r.effective_seconds).toBeGreaterThan(180);
|
|
71
|
+
expect(r.effective_seconds!).toBeLessThanOrEqual(7200);
|
|
72
|
+
expect(reload(id).backoff_effective_seconds).toBe(r.effective_seconds);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("previous_run_active uses a shorter cap (30min)", () => {
|
|
76
|
+
const id = seedSchedule(180);
|
|
77
|
+
for (let i = 0; i < 10; i++) addRun(id, "skipped", "previous_run_active");
|
|
78
|
+
const r = applyNoProgressBackoff(id)!;
|
|
79
|
+
expect(r.cause).toBe("previous_run_active");
|
|
80
|
+
expect(r.effective_seconds).toBe(1800);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("below the threshold it leaves the interval alone", () => {
|
|
84
|
+
const id = seedSchedule(180);
|
|
85
|
+
addRun(id, "skipped", "target_offline");
|
|
86
|
+
addRun(id, "skipped", "target_offline");
|
|
87
|
+
expect(applyNoProgressBackoff(id)).toBeNull();
|
|
88
|
+
expect(reload(id).backoff_effective_seconds).toBeNull();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("a success resets the streak and restores the base interval", () => {
|
|
92
|
+
const id = seedSchedule(180);
|
|
93
|
+
for (let i = 0; i < 5; i++) addRun(id, "skipped", "target_offline");
|
|
94
|
+
const widened = applyNoProgressBackoff(id)!;
|
|
95
|
+
expect(widened.effective_seconds!).toBeGreaterThan(180);
|
|
96
|
+
addRun(id, "replied", null); // 成功一次
|
|
97
|
+
expect(applyNoProgressBackoff(id)).toBeNull();
|
|
98
|
+
const row = reload(id);
|
|
99
|
+
expect(row.backoff_streak).toBe(0);
|
|
100
|
+
expect(row.backoff_effective_seconds).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("switching cause (different error_code) does not keep the streak", () => {
|
|
104
|
+
const id = seedSchedule(180);
|
|
105
|
+
addRun(id, "skipped", "target_offline");
|
|
106
|
+
addRun(id, "skipped", "target_offline");
|
|
107
|
+
addRun(id, "skipped", "previous_run_active"); // 最新一条换链 ⇒ streak=1
|
|
108
|
+
expect(applyNoProgressBackoff(id)).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("schedules that opt into no_change_backoff are left to the other mechanism", () => {
|
|
112
|
+
const id = seedSchedule(180, { no_change_backoff: 1 });
|
|
113
|
+
for (let i = 0; i < 5; i++) addRun(id, "skipped", "target_offline");
|
|
114
|
+
expect(applyNoProgressBackoff(id)).toBeNull();
|
|
115
|
+
expect(reload(id).backoff_effective_seconds).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
});
|
package/src/scheduled-tasks.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { dispatchVerdict } from "./node-permissions.js";
|
|
|
12
12
|
import { hasSubscribers, pushEvent, pushNetworkObserverEvent } from "./push.js";
|
|
13
13
|
import { SCHEDULED_TASK_STORAGE_SELECT } from "./rest-projections.js";
|
|
14
14
|
import { blockerTimedOut, blockerTimeoutClock, expireStuckBlocker, sendStuckNotice, skipsBlockedBy, stuckNoticeSkips, stuckTimeoutMs, type StuckNotice } from "./scheduled-stuck.js";
|
|
15
|
-
import { evaluateScheduleFailures, failureSummary } from "./scheduled-failures.js";
|
|
15
|
+
import { applyNoProgressBackoff, evaluateScheduleFailures, failureSummary } from "./scheduled-failures.js";
|
|
16
|
+
import { parseHubTimestamp } from "./hub-timestamp.js";
|
|
16
17
|
import { scheduledTargetOffline, sendOfflineNotice, type OfflineNotice } from "./scheduled-offline.js";
|
|
17
18
|
|
|
18
19
|
export type ScheduleSpec =
|
|
@@ -449,6 +450,17 @@ export function dispatchScheduledOccurrence(row: ScheduledRow, scheduledFor: str
|
|
|
449
450
|
targetAlias: targetNode.alias,
|
|
450
451
|
};
|
|
451
452
|
if (advanceSchedule) advance({ ...row, target_alias: targetNode.alias }, scheduledFor, advanceAfter);
|
|
453
|
+
// #2622 —— 目标长期离线时按同因链放慢(默认 3 次后 2 倍递增,上限 1 小时)。
|
|
454
|
+
try {
|
|
455
|
+
const bo = applyNoProgressBackoff(row.schedule_id);
|
|
456
|
+
if (bo && bo.effective_seconds) {
|
|
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
|
+
const at = parseHubTimestamp(sched?.next_run_at);
|
|
459
|
+
if (at !== null) advance({ ...row, target_alias: targetNode.alias }, scheduledFor, new Date(at));
|
|
460
|
+
}
|
|
461
|
+
} catch (e: any) {
|
|
462
|
+
console.error(`[scheduled-tasks] no-progress backoff failed schedule=${row.schedule_id}: ${e?.message || e}`);
|
|
463
|
+
}
|
|
452
464
|
return;
|
|
453
465
|
}
|
|
454
466
|
// Seeing the target online rearms exactly one warning for a future offline episode.
|
|
@@ -603,6 +615,13 @@ export function dispatchScheduledOccurrence(row: ScheduledRow, scheduledFor: str
|
|
|
603
615
|
// Dispatch is not completion. Keep the run open until the exact bound
|
|
604
616
|
// task reaches replied/failed/cancelled/expired; db.ts owns that mirror.
|
|
605
617
|
db.run("UPDATE scheduled_task_runs SET task_id = ?1, status = ?2, completed_at = NULL WHERE run_id = ?3", [taskId, deliveryState, runId]);
|
|
618
|
+
|
|
619
|
+
// #2622 —— 上一层任务还没跑完时按同因链放慢(间隔 180s 的排程曾一天写 343 行 skip)。
|
|
620
|
+
try {
|
|
621
|
+
applyNoProgressBackoff(row.schedule_id);
|
|
622
|
+
} catch (e: any) {
|
|
623
|
+
console.error(`[scheduled-tasks] no-progress backoff failed schedule=${row.schedule_id}: ${e?.message || e}`);
|
|
624
|
+
}
|
|
606
625
|
db.run(`UPDATE sessions SET task = ${sessionTaskOnDispatch("?1")}, updated_at = datetime('now') WHERE node_id = ?2 AND network_id = ?3`, [sessionTaskPreview(taskContent), node.node_id, row.network_id]);
|
|
607
626
|
db.run("UPDATE scheduled_tasks SET target_alias = ?1, last_run_at = ?2, updated_at = datetime('now') WHERE schedule_id = ?3", [node.alias, scheduledFor, row.schedule_id]);
|
|
608
627
|
if (advanceSchedule) advance({ ...row, target_alias: node.alias }, scheduledFor, advanceAfter);
|