@sleep2agi/commhub-server 0.9.0-preview.186 → 0.9.0-preview.187
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/db.ts +4 -3
- package/src/scheduled-failure-code.test.ts +25 -0
- package/src/scheduled-failure-code.ts +20 -0
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.187",
|
|
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/db.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { refreshScheduledBackoff } from "./scheduled-backoff.js";
|
|
1
|
+
import { refreshScheduledBackoff } from "./scheduled-backoff.js"; import { scheduledFailureCode } from "./scheduled-failure-code.js";
|
|
2
2
|
import { createAdapter, type DbAdapter } from "./db-adapter"; import { withStatementHook } from "./status-read-cache"; // #431 写 sessions 的语句让 /api/status 缓存失效
|
|
3
3
|
|
|
4
4
|
export const db: DbAdapter = withStatementHook(createAdapter());
|
|
@@ -2345,6 +2345,7 @@ type ScheduledTaskLifecycleRow = {
|
|
|
2345
2345
|
network_id: string | null;
|
|
2346
2346
|
status: string;
|
|
2347
2347
|
completed_at: string | null;
|
|
2348
|
+
result: string | null;
|
|
2348
2349
|
};
|
|
2349
2350
|
|
|
2350
2351
|
type ScheduledTaskBinding = { run_id: string; schedule_id: string };
|
|
@@ -2368,7 +2369,7 @@ export function syncScheduledRunForTask(taskId: string, expectedNetworkId?: stri
|
|
|
2368
2369
|
|
|
2369
2370
|
function syncScheduledRunForTaskInTransaction(taskId: string, expectedNetworkId?: string | null): { matched: boolean; status?: string } {
|
|
2370
2371
|
const task = db.get<ScheduledTaskLifecycleRow>(
|
|
2371
|
-
`SELECT task_id, network_id, status, completed_at
|
|
2372
|
+
`SELECT task_id, network_id, status, completed_at, result
|
|
2372
2373
|
FROM tasks
|
|
2373
2374
|
WHERE task_id = ?1
|
|
2374
2375
|
AND (CAST(?2 AS TEXT) IS NULL OR network_id = ?2)`,
|
|
@@ -2389,7 +2390,7 @@ function syncScheduledRunForTaskInTransaction(taskId: string, expectedNetworkId?
|
|
|
2389
2390
|
const binding = bindings[0];
|
|
2390
2391
|
|
|
2391
2392
|
if (SCHEDULED_RUN_TERMINAL_STATUSES.has(task.status)) {
|
|
2392
|
-
const errorCode = task.status
|
|
2393
|
+
const errorCode = scheduledFailureCode(task.status, task.result);
|
|
2393
2394
|
const updated = db.run(
|
|
2394
2395
|
`UPDATE scheduled_task_runs
|
|
2395
2396
|
SET status = ?1,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// #1879 —— 失败分类:共享会话忙与真失败分开。
|
|
2
|
+
import { describe, expect, test } from "bun:test";
|
|
3
|
+
import { scheduledFailureCode } from "./scheduled-failure-code.js";
|
|
4
|
+
|
|
5
|
+
describe("scheduledFailureCode", () => {
|
|
6
|
+
test("共享会话忙 → task_failed_busy(两种情况都覆盖)", () => {
|
|
7
|
+
const notSubmitted = "[TMA云盘欧] opencode 任务未提交:共享会话在 30 分钟 内一直处于忙碌状态(可能有人正在 TUI 里跑一轮),本任务没有发出";
|
|
8
|
+
expect(scheduledFailureCode("failed", notSubmitted)).toBe("task_failed_busy");
|
|
9
|
+
const stillRunning = "[通信客户端欧] ⏳ opencode 任务仍在节点的 TUI 会话里运行,没有被中止;bridge 等待回复已达 30 分钟";
|
|
10
|
+
expect(scheduledFailureCode("failed", stillRunning)).toBe("task_failed_busy");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("真失败仍然是 task_failed(不能被分类吞掉)", () => {
|
|
14
|
+
expect(scheduledFailureCode("failed", "runtime failed")).toBe("task_failed");
|
|
15
|
+
expect(scheduledFailureCode("failed", null)).toBe("task_failed");
|
|
16
|
+
// 提到「共享会话」但没有任何忙碌措辞 ⇒ 仍然算真失败,不能被分类吞掉
|
|
17
|
+
expect(scheduledFailureCode("failed", "共享会话已释放,任务失败原因不明")).toBe("task_failed");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("非 failed 状态不受影响", () => {
|
|
21
|
+
expect(scheduledFailureCode("replied", "共享会话忙")).toBeNull();
|
|
22
|
+
expect(scheduledFailureCode("cancelled", "共享会话一直处于忙碌")).toBe("task_cancelled");
|
|
23
|
+
expect(scheduledFailureCode("expired", null)).toBe("task_expired");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// #1879 —— 定时任务失败分类(纯函数,不 import db,便于单测)。
|
|
2
|
+
//
|
|
3
|
+
// 生产 24h(2026-10-28):144 条 failed run 的 error_code 全是 `task_failed`,
|
|
4
|
+
// 但其中 125 条(66%)的真实原因是「共享会话被人的 TUI 占着,任务 30 分钟内没提交上去」。
|
|
5
|
+
// 混在一个桶里,报表分不出来,也没法给它们配不同策略。
|
|
6
|
+
//
|
|
7
|
+
// 只做分类,**不改等待语义**:近 24h 有 108 个任务是等到 >25 分钟才成功的,
|
|
8
|
+
// 「忙就立刻失败」会打掉它们。
|
|
9
|
+
//
|
|
10
|
+
// `failureStreak()` 按 status='failed' 计数(不是按 error_code),所以新增一个 code
|
|
11
|
+
// 不影响「连续 N 次失败告警 / 自动暂停」的阈值。
|
|
12
|
+
export function scheduledFailureCode(status: string, result: string | null): string | null {
|
|
13
|
+
if (status === "replied") return null;
|
|
14
|
+
const base = `task_${status}`;
|
|
15
|
+
if (status !== "failed") return base;
|
|
16
|
+
const text = result ?? "";
|
|
17
|
+
if (/共享会话/.test(text) && /忙碌|一直处于|未获提交/.test(text)) return "task_failed_busy";
|
|
18
|
+
if (/仍在节点的 TUI 会话里运行|等待回复已达\s*30\s*分钟/.test(text)) return "task_failed_busy";
|
|
19
|
+
return base;
|
|
20
|
+
}
|