重构 worker 对话:复用 resume 机制,改专属 goroutine 运行
把「给运行中 Worker 发消息调方向」从自建的介入持久化协议,改为复用 已有的暂停/恢复 + transcript resume 能力,实现与主 Agent chat 一致。 - 拆 runWorkerStep:抽出 runIntent(执行+善后),池子与消息路径共用一份 善后逻辑;新增 runDetachedIntent,把意图 paused→running(不经 frontier) 并在专属 goroutine 里直接跑,用户消息不受 3 槽池限制、随发随跑。 - 精简 sendWorkerMessage handler:校验 + emit 用户活动 + 专属运行;消息经 ExecuteWithMessage 作为下一轮输入注入,request_id 仅做 transcript 去重。 - 删除介入 DB 协议与 15 处 activity 查询过滤(回退 exploration.go)、 directedClaims 调度屏障、RecoverWorkerMessages 恢复、workerWake/waitWorker、 AbortWorkIntervenedByUser。无 DB schema 改动。 - 前端:保留消息框,恢复「直接继续」(resume)按钮;发送改由 SSE 承载, 去掉乐观插入。 - 取舍(低频可接受):消息仅存内存,不做崩溃恢复;发消息时该任务可能瞬时 超并发 1 个 worker。 净改动 9 文件 +583/-46(原 PR 15 文件 +1940/-72)。
This commit is contained in:
1 parent
ff493ae42b
commit
c9bf534818
14 files changed
+237
-1568
No files matched your search
+1
-2
@@ -287,9 +287,8 @@ export const api = {
|
||||
sendWorkerMessage: (taskId: string, intentId: string, message: string, requestId: string) =>
|
||||
post<{
|
||||
id: number;
|
||||
state: "open" | "running" | "paused";
|
||||
state: "running";
|
||||
accepted: true;
|
||||
activity_seq: number;
|
||||
request_id: string;
|
||||
}>(`/tasks/${taskId}/intents/${intentId}/messages`, { message, request_id: requestId }),
|
||||
taskLLMResolution: (id: string) => get<TaskLLMResolutions>(`/tasks/${id}/llm/resolution`),
|
||||
|
||||
@@ -465,23 +465,23 @@ function sendMockWorkerMessage(
|
||||
}
|
||||
const intent = mockIntents.find((item) => item.id === id);
|
||||
if (!intent) return { ok: false, error: "意图不存在" };
|
||||
if (intent.inherited || (intent.state !== "running" && intent.state !== "paused")) {
|
||||
return { ok: false, state: intent.state, error: "Worker 状态已变化" };
|
||||
if (intent.inherited || intent.state !== "paused") {
|
||||
return { ok: false, state: intent.state, error: "仅已暂停的 Worker 可以发送消息,请先暂停" };
|
||||
}
|
||||
if (!normalizedMessage) return { ok: false, state: intent.state, error: "消息不能为空" };
|
||||
if (Array.from(normalizedMessage).length > 4000) {
|
||||
return { ok: false, state: intent.state, error: "消息不能超过 4000 个字符" };
|
||||
}
|
||||
|
||||
// The real endpoint stops the active turn, persists a normal user message,
|
||||
// and immediately reopens the same intent. Keep the mock's transition in sync,
|
||||
// then emulate a Worker reclaiming it shortly afterward.
|
||||
intent.state = "open";
|
||||
// The real endpoint transitions the intent paused->running, records the user turn,
|
||||
// and runs it in a dedicated goroutine outside the worker pool. Keep the mock in
|
||||
// sync: flip to running immediately and emit the visible user activity.
|
||||
intent.state = "running";
|
||||
const activitySeq = nextMockWorkerMessageActivitySeq++;
|
||||
const workerMessage: MockWorkerMessage = {
|
||||
intentId: id,
|
||||
message: normalizedMessage,
|
||||
state: "open",
|
||||
state: "running",
|
||||
activitySeq,
|
||||
};
|
||||
mockWorkerMessages.set(normalizedRequestId, workerMessage);
|
||||
@@ -494,12 +494,6 @@ function sendMockWorkerMessage(
|
||||
summary: normalizedMessage,
|
||||
detail: normalizedMessage,
|
||||
} satisfies Activity);
|
||||
setTimeout(() => {
|
||||
if (intent.state === "open") {
|
||||
intent.state = "running";
|
||||
workerMessage.state = "running";
|
||||
}
|
||||
}, 250);
|
||||
return {
|
||||
ok: true,
|
||||
state: workerMessage.state,
|
||||
@@ -1008,9 +1002,8 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
if (!result.ok) throw new Error(result.error ?? "Worker 状态已变化");
|
||||
return {
|
||||
id: Number(id.replace(/\D/g, "")) || 0,
|
||||
state: result.state ?? "open",
|
||||
state: result.state ?? "running",
|
||||
accepted: true,
|
||||
activity_seq: result.activitySeq ?? 0,
|
||||
request_id: result.requestId ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user