fix: avoid invented task percentages
This commit is contained in:
parent
55be81d3d8
commit
7c9fd8a796
@ -240,8 +240,8 @@ type OpenClawBackgroundTask = {
|
|||||||
displayText: string;
|
displayText: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
completed: number;
|
completed: number;
|
||||||
total: number;
|
total: number | null;
|
||||||
progressPercent: number;
|
progressPercent: number | null;
|
||||||
pollEndpoint: string;
|
pollEndpoint: string;
|
||||||
pollAfterMs: number;
|
pollAfterMs: number;
|
||||||
maxWaitSeconds: number;
|
maxWaitSeconds: number;
|
||||||
@ -269,16 +269,17 @@ function parseOpenClawBackgroundTask(
|
|||||||
if (!jobId || !state) return null;
|
if (!jobId || !state) return null;
|
||||||
|
|
||||||
const completed = Math.max(0, Number(rawTask.completed) || 0);
|
const completed = Math.max(0, Number(rawTask.completed) || 0);
|
||||||
const total = Math.max(1, Number(rawTask.total) || 1);
|
const parsedTotal = Number(rawTask.total);
|
||||||
const progressPercent = Math.max(
|
const total =
|
||||||
0,
|
Number.isFinite(parsedTotal) && parsedTotal > 0 ? parsedTotal : null;
|
||||||
Math.min(
|
const parsedProgressPercent = Number(rawTask.progress_percent);
|
||||||
100,
|
const progressPercent =
|
||||||
Number.isFinite(Number(rawTask.progress_percent))
|
rawTask.progress_percent != null &&
|
||||||
? Number(rawTask.progress_percent)
|
Number.isFinite(parsedProgressPercent)
|
||||||
: Math.round((completed * 100) / total)
|
? Math.max(0, Math.min(100, parsedProgressPercent))
|
||||||
)
|
: total
|
||||||
);
|
? Math.round((completed * 100) / total)
|
||||||
|
: null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
jobId,
|
jobId,
|
||||||
@ -323,8 +324,10 @@ function buildOpenClawTaskProgress(task: OpenClawBackgroundTask) {
|
|||||||
task.phase ||
|
task.phase ||
|
||||||
(task.state === "processing" ? "任务正在处理" : "任务状态已更新"),
|
(task.state === "processing" ? "任务正在处理" : "任务状态已更新"),
|
||||||
completed: task.completed,
|
completed: task.completed,
|
||||||
total: task.total,
|
...(task.total != null ? { total: task.total } : {}),
|
||||||
progress_percent: task.progressPercent,
|
...(task.progressPercent != null
|
||||||
|
? { progress_percent: task.progressPercent }
|
||||||
|
: {}),
|
||||||
stage: task.stage,
|
stage: task.stage,
|
||||||
state: task.state,
|
state: task.state,
|
||||||
updated_at: task.updatedAt,
|
updated_at: task.updatedAt,
|
||||||
@ -524,7 +527,7 @@ function streamOpenClawBackgroundTask(params: {
|
|||||||
nextTask.stage,
|
nextTask.stage,
|
||||||
nextTask.updatedAt,
|
nextTask.updatedAt,
|
||||||
nextTask.completed,
|
nextTask.completed,
|
||||||
nextTask.total,
|
nextTask.total ?? "",
|
||||||
progress.message,
|
progress.message,
|
||||||
].join("|");
|
].join("|");
|
||||||
if (key === lastProgressKey) return;
|
if (key === lastProgressKey) return;
|
||||||
@ -572,8 +575,10 @@ function streamOpenClawBackgroundTask(params: {
|
|||||||
message: "任务仍在运行,正在重新连接进度服务",
|
message: "任务仍在运行,正在重新连接进度服务",
|
||||||
display: "任务仍在运行,正在重新连接进度服务",
|
display: "任务仍在运行,正在重新连接进度服务",
|
||||||
completed: task.completed,
|
completed: task.completed,
|
||||||
total: task.total,
|
...(task.total != null ? { total: task.total } : {}),
|
||||||
progress_percent: task.progressPercent,
|
...(task.progressPercent != null
|
||||||
|
? { progress_percent: task.progressPercent }
|
||||||
|
: {}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -543,8 +543,12 @@ function normalizeClawdProgressEvent(
|
|||||||
currentOrderId,
|
currentOrderId,
|
||||||
completed:
|
completed:
|
||||||
Number.isFinite(completed) && completed >= 0 ? completed : undefined,
|
Number.isFinite(completed) && completed >= 0 ? completed : undefined,
|
||||||
total: Number.isFinite(total) && total > 0 ? total : undefined,
|
total:
|
||||||
|
progress.total != null && Number.isFinite(total) && total > 0
|
||||||
|
? total
|
||||||
|
: undefined,
|
||||||
progressPercent:
|
progressPercent:
|
||||||
|
progress.progress_percent != null &&
|
||||||
Number.isFinite(progressPercent) &&
|
Number.isFinite(progressPercent) &&
|
||||||
progressPercent >= 0 &&
|
progressPercent >= 0 &&
|
||||||
progressPercent <= 100
|
progressPercent <= 100
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user