refactor: clarify thread execution failure notices

This commit is contained in:
kris
2026-04-05 05:19:18 +08:00
parent 276beb3486
commit af0cc3fead
3 changed files with 28 additions and 4 deletions

View File

@@ -6051,7 +6051,7 @@ function appendDispatchExecutionResultInState(
sender: "ops",
senderLabel: "主 Agent Relay",
body: payload.failureReason?.trim()
? `${threadTitle} 执行失败:${payload.failureReason.trim()}`
? `${threadTitle} 执行失败:${buildFriendlyThreadExecutionError(payload.failureReason)}`
: `${threadTitle} 执行失败,请稍后重试。`,
kind: "text",
});
@@ -6434,7 +6434,7 @@ export async function completeMasterAgentTask(payload: {
? `主 Agent Relay · ${task.accountLabel}`
: "主 Agent Relay",
body: isThreadConversationReply
? `${task.targetThreadDisplayName ?? "当前线程"} 执行失败:${task.errorMessage ?? "UNKNOWN_ERROR"}`
? `${task.targetThreadDisplayName ?? "当前线程"} 执行失败:${buildFriendlyThreadExecutionError(task.errorMessage)}`
: `Master Codex Node 执行失败:${task.errorMessage ?? "UNKNOWN_ERROR"}`,
kind: "text",
});
@@ -7605,6 +7605,30 @@ function buildProjectUnderstandingCollaborationNotice(projectName: string, snaps
.join("\n");
}
function buildFriendlyThreadExecutionError(errorMessage?: string) {
const message = errorMessage?.trim();
if (!message) {
return "线程执行失败,请稍后重试。";
}
if (message.includes("LOCAL_AGENT_CODEX_THREAD_BINDING_MISSING")) {
return "线程绑定缺失,请重新导入或重新绑定该线程后再试。";
}
if (message.includes("LOCAL_AGENT_CODEX_THREAD_BINDING_STALE")) {
return "线程绑定已失效,请重新导入或重新绑定该线程后再试。";
}
if (
message.includes("LOCAL_AGENT_CODEX_THREAD_BINDING_MISMATCH") ||
message.includes("LOCAL_AGENT_CODEX_WORKDIR_INVALID") ||
message.includes("THREAD_ENVIRONMENT_INVALID")
) {
return "线程环境异常,请重新绑定到正确项目或工作目录后再试。";
}
if (message.includes("LOCAL_AGENT_CODEX_THREAD_READ_ONLY")) {
return "线程当前处于只读环境,无法继续执行,请切换到可写线程后再试。";
}
return message;
}
function shouldQueueProjectUnderstandingSync(
project: Project,
observedActivityAt: string,

View File

@@ -328,7 +328,7 @@ test("POST /api/v1/master-agent/tasks/[taskId]/complete blocks leaked thread env
assert.equal(leakedReply, undefined);
const opsNotice = groupMessages.find((message) =>
message.body.includes("线程返回了内部环境提示,已拦截"),
message.body.includes("线程环境异常,请重新绑定到正确项目或工作目录后再试。"),
);
assert.ok(opsNotice, "expected a system notice instead of raw leaked diagnostics");
});

View File

@@ -255,7 +255,7 @@ test("POST /api/v1/master-agent/tasks/[taskId]/complete blocks leaked thread env
assert.equal(leakedReply, undefined);
const opsNotice = updatedProject?.messages.find((message) =>
message.body.includes("线程返回了内部环境提示,已拦截"),
message.body.includes("线程环境异常,请重新绑定到正确项目或工作目录后再试。"),
);
assert.ok(opsNotice, "expected a user-facing system notice instead of raw environment diagnostics");
});