@sleep2agi/commhub-server 0.9.0-preview.215 → 0.9.0-preview.216
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/task-late-reply-http.test.ts +31 -0
- package/src/tools.ts +25 -6
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.216",
|
|
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",
|
|
@@ -187,3 +187,34 @@ test("既有任务没有 turn 上下文时,迟到结果仍可落账并投递
|
|
|
187
187
|
in_reply_to: contextlessId, text: "impostor", thread_id: "t", turn_id: "u",
|
|
188
188
|
})).toMatchObject({ ok: false, error: "late_reply_task_not_owned" });
|
|
189
189
|
});
|
|
190
|
+
|
|
191
|
+
// #3061 续 —— 任务**从未记下 turn 上下文**时,不该再要求调用方凭空给出 thread/turn。
|
|
192
|
+
//
|
|
193
|
+
// 现场(2026-10-30 通信Dash欧):它对一条 failed 任务调 send_reply 补结果,
|
|
194
|
+
// 拿到 `reply_task_terminal`(因为没带 thread_id/turn_id),只好先 retry_task 把任务
|
|
195
|
+
// 重置成 delivered 再回复 —— 账本里那条从 failed 变成 retried→replied,
|
|
196
|
+
// **「当初失败过」这个事实被抹掉了**。而 #3244 只放宽了「id 对不上」,没放宽「必须给 id」。
|
|
197
|
+
test("既有任务没有 turn 上下文时,不带 thread/turn 也能补迟到结果", async () => {
|
|
198
|
+
const noIdTask = "task_late710_noid";
|
|
199
|
+
db.run(`INSERT INTO tasks
|
|
200
|
+
(task_id,from_name,to_name,to_node_id,status,content,result,network_id,thread_id,turn_id,completed_at)
|
|
201
|
+
VALUES(?1,?2,'late710-worker',?3,'failed','timed out','[超时] 已达 30 分钟上限',?4,NULL,NULL,datetime('now'))`,
|
|
202
|
+
[noIdTask, owner.user.username, workerId, owner.network_id]);
|
|
203
|
+
|
|
204
|
+
const accepted = await mcp(workerToken, "send_reply", {
|
|
205
|
+
in_reply_to: noIdTask,
|
|
206
|
+
text: "没带 id 也应该收下",
|
|
207
|
+
status: "replied",
|
|
208
|
+
});
|
|
209
|
+
expect(accepted).toMatchObject({ ok: true, late: true, duplicate: false });
|
|
210
|
+
const row = db.get("SELECT status,result FROM task_late_replies WHERE task_id=?1", noIdTask);
|
|
211
|
+
expect(row).toMatchObject({ status: "replied", result: "没带 id 也应该收下" });
|
|
212
|
+
// 任务行仍不改写
|
|
213
|
+
expect(db.get("SELECT status FROM tasks WHERE task_id=?1", noIdTask)).toEqual({ status: "failed" });
|
|
214
|
+
|
|
215
|
+
// 反例:任务**有**上下文时,仍然必须给匹配的 id(不能被这次放宽带偏)
|
|
216
|
+
const mismatch = await mcp(siblingToken, "send_reply", {
|
|
217
|
+
in_reply_to: taskId, text: "impostor", thread_id: threadId, turn_id: turnId,
|
|
218
|
+
});
|
|
219
|
+
expect(mismatch).toMatchObject({ ok: false, error: "late_reply_task_not_owned" });
|
|
220
|
+
});
|
package/src/tools.ts
CHANGED
|
@@ -2539,7 +2539,18 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2539
2539
|
if (lateCandidate && !["created", "delivered", "acked", "running"].includes(lateCandidate.status)) {
|
|
2540
2540
|
if (workSignal.outcome) return { content: [{ type: "text" as const, text: JSON.stringify({ ok: false, error: "scheduled_work_outcome_terminal", reply_queued: false }) }] };
|
|
2541
2541
|
// Old runtimes do not send turn identity and retain the old result.
|
|
2542
|
-
|
|
2542
|
+
// #3061 续 —— 任务**从未记下 turn 上下文**时,不该再要求调用方凭空给出 id。
|
|
2543
|
+
//
|
|
2544
|
+
// 现场(2026-10-30,通信Dash欧):它对一条 failed 任务调 send_reply 想补结果,
|
|
2545
|
+
// 拿到 `reply_task_terminal`,只好先 retry_task 把任务重置成 delivered 再回复 ——
|
|
2546
|
+
// 代价是账本里那条从 failed 变成 retried→replied,**「当初失败过」这个事实被抹掉了**。
|
|
2547
|
+
// 而 #3244 只放宽了「id 对不上」,没放宽「必须提供 id」。
|
|
2548
|
+
//
|
|
2549
|
+
// 新语义:
|
|
2550
|
+
// · 任务存了 thread/turn ⇒ 仍然要求调用方给出**匹配**的 id(防串号)
|
|
2551
|
+
// · 任务两个都是 null ⇒ 不要求 id;归属/终态/目标三条判据照样生效
|
|
2552
|
+
const storedCtx = !!(lateCandidate.thread_id || lateCandidate.turn_id);
|
|
2553
|
+
if (storedCtx && (!threadId || !turnId)) {
|
|
2543
2554
|
return { content: [{ type: "text" as const, text: JSON.stringify({
|
|
2544
2555
|
ok: false, error: "reply_task_terminal",
|
|
2545
2556
|
message: `cannot apply reply: task is already terminal (${lateCandidate.status})`,
|
|
@@ -2556,7 +2567,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2556
2567
|
if (!token?.bound_node_id || !lateCandidate.to_node_id || token.bound_node_id !== lateCandidate.to_node_id) {
|
|
2557
2568
|
return { content: [{ type: "text" as const, text: JSON.stringify({ ok: false, error: "late_reply_task_not_owned", reply_queued: false }) }] };
|
|
2558
2569
|
}
|
|
2559
|
-
if (!lateReplyContextMatches(lateCandidate.thread_id, lateCandidate.turn_id, threadId
|
|
2570
|
+
if (storedCtx && !lateReplyContextMatches(lateCandidate.thread_id, lateCandidate.turn_id, threadId!, turnId!)) {
|
|
2560
2571
|
return { content: [{ type: "text" as const, text: JSON.stringify({ ok: false, error: "late_reply_context_mismatch", reply_queued: false }) }] };
|
|
2561
2572
|
}
|
|
2562
2573
|
const canonicalOrigin = resolveCanonicalAlias(enforceNetworkId, lateCandidate.from_name).alias;
|
|
@@ -2564,6 +2575,10 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2564
2575
|
return { content: [{ type: "text" as const, text: JSON.stringify({ ok: false, error: "reply_target_mismatch", reply_queued: false }) }] };
|
|
2565
2576
|
}
|
|
2566
2577
|
|
|
2578
|
+
// 表列是 NOT NULL:任务没有上下文时用稳定占位值。
|
|
2579
|
+
// 幂等键是 (task_id, thread_id, turn_id),占位值仍能让「同一任务的重复补发」收敛成一条。
|
|
2580
|
+
const lateThreadId = threadId ?? "unrecorded";
|
|
2581
|
+
const lateTurnId = turnId ?? "unrecorded";
|
|
2567
2582
|
const lateOutcome = db.transaction(() => {
|
|
2568
2583
|
const currentParams: any[] = [in_reply_to];
|
|
2569
2584
|
let currentSql = "SELECT status,to_node_id,thread_id,turn_id FROM tasks WHERE task_id=?1";
|
|
@@ -2572,12 +2587,16 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2572
2587
|
if (!current || ["created", "delivered", "acked", "running"].includes(current.status)) {
|
|
2573
2588
|
return { ok: false as const, error: "late_reply_task_not_terminal" as const };
|
|
2574
2589
|
}
|
|
2575
|
-
|
|
2590
|
+
// 与上面同一判据:只有任务真的记过 thread/turn 时才要求调用方 id 匹配;
|
|
2591
|
+
// 两个都 null 的任务(#3061 的 289 条)不因为「没 id」被挡回去。
|
|
2592
|
+
const currentHasCtx = !!(current.thread_id || current.turn_id);
|
|
2593
|
+
if (current.to_node_id !== token.bound_node_id
|
|
2594
|
+
|| (currentHasCtx && !lateReplyContextMatches(current.thread_id, current.turn_id, threadId!, turnId!))) {
|
|
2576
2595
|
return { ok: false as const, error: "late_reply_context_mismatch" as const };
|
|
2577
2596
|
}
|
|
2578
2597
|
const existing = db.get<{ late_reply_id: string; inbox_id: string; from_node_id: string; status: string; result: string }>(
|
|
2579
2598
|
"SELECT late_reply_id,inbox_id,from_node_id,status,result FROM task_late_replies WHERE task_id=?1 AND thread_id=?2 AND turn_id=?3",
|
|
2580
|
-
in_reply_to,
|
|
2599
|
+
in_reply_to, lateThreadId, lateTurnId,
|
|
2581
2600
|
);
|
|
2582
2601
|
if (existing) {
|
|
2583
2602
|
if (existing.from_node_id !== token.bound_node_id || existing.status !== replyStatus || existing.result !== text) {
|
|
@@ -2588,7 +2607,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2588
2607
|
const lateReplyId = uuidv4();
|
|
2589
2608
|
const lateMeta = normalizeMetaJson({
|
|
2590
2609
|
...(mergedMeta && typeof mergedMeta === "object" && !Array.isArray(mergedMeta) ? mergedMeta : {}),
|
|
2591
|
-
late: true, late_reply_id: lateReplyId, thread_id:
|
|
2610
|
+
late: true, late_reply_id: lateReplyId, thread_id: lateThreadId, turn_id: lateTurnId,
|
|
2592
2611
|
});
|
|
2593
2612
|
db.run(
|
|
2594
2613
|
`INSERT INTO inbox (id,session_name,node_id,type,priority,content,from_session,in_reply_to,requires_response,network_id,meta_json)
|
|
@@ -2601,7 +2620,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
2601
2620
|
(late_reply_id,inbox_id,task_id,network_id,from_node_id,thread_id,turn_id,status,result,meta_json)
|
|
2602
2621
|
VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10)`,
|
|
2603
2622
|
[lateReplyId, id, in_reply_to, effectiveNetId ?? null, token.bound_node_id,
|
|
2604
|
-
|
|
2623
|
+
lateThreadId, lateTurnId, replyStatus, text, lateMeta],
|
|
2605
2624
|
);
|
|
2606
2625
|
return { ok: true as const, duplicate: false as const, lateReplyId, inboxId: id };
|
|
2607
2626
|
});
|