From 4e761d6369e72602cb2f3252b30a3ca8803cfc19 Mon Sep 17 00:00:00 2001 From: eust-w Date: Mon, 7 Sep 2026 03:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Report=20active=20Capture=20subdire?= =?UTF-8?q?ctory=20in=20workflow=20run=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builtin/orbbec_left_undistort/operator.py | 15 +++++++ internal/domain/types.go | 19 +++++---- internal/worker/capture_progress_test.go | 16 +++++++ internal/worker/runtime.go | 3 ++ .../orbbec_left_undistort/src/operator.py | 15 +++++++ src/pages/ProjectDetail.tsx | 42 +++++++++++++++---- src/services/api/workflows.ts | 4 +- src/types.ts | 3 ++ tests/backend/orbbec_left_undistort_test.py | 14 ++++++- .../frontend/project-ui-regressions.test.mjs | 7 ++++ 10 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 internal/worker/capture_progress_test.go diff --git a/backend/operators/builtin/orbbec_left_undistort/operator.py b/backend/operators/builtin/orbbec_left_undistort/operator.py index 4c93e376..abbad9ef 100644 --- a/backend/operators/builtin/orbbec_left_undistort/operator.py +++ b/backend/operators/builtin/orbbec_left_undistort/operator.py @@ -13,6 +13,7 @@ import json import pathlib import shutil import subprocess +from datetime import datetime, timezone from typing import Any, Callable @@ -438,6 +439,17 @@ def run( total_frames = 0 rectified_dir = output_root / "rectified" side_counts: dict[str, int] = {"left": 0, "right": 0} + def report_progress(stage: str, collection_id: str = "", filename: str = "") -> None: + print("DROBOTICFLOW_PROGRESS " + json.dumps({ + "nodeId": node_id, + "stage": stage, + "currentCaptureDirectories": [collection_id] if collection_id else [], + "currentFile": filename, + "step": sum(side_counts.values()), + "maxStep": len(videos), + "updatedAt": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"), + }, ensure_ascii=False), flush=True) + for camera_side in required_sides: videos_port = _output(node_data, f"{camera_side}RectifiedVideos") timestamps_port = _output(node_data, f"{camera_side}RectifiedTimestamps") @@ -446,6 +458,7 @@ def run( for entry in videos_by_side[camera_side]: name = str(entry.get("name", "")).strip() or f"{camera_side}-video.mp4" collection_id = _video_collection_id(entry) + report_progress("loading_video", collection_id, name) calibration_key = (collection_id, camera_side) if calibration_key not in calibrations: if require_calibration: @@ -462,6 +475,7 @@ def run( )) destination = rectified_dir / camera_side / name spec = calibrations[calibration_key] + report_progress("rectifying", collection_id, name) metrics = _rectify_video(source, destination, spec, alpha, preserve_audio, helpers) pts_destination = destination.with_name(f"{destination.stem}_pts.csv") _write_rectified_pts( @@ -544,6 +558,7 @@ def run( artifacts.append(helpers["write_json_artifact"]( run_id, node_id, output_root, "undistort-summary.json", summary, output=_output(node_data, "summary") )) + report_progress("completed") return artifacts diff --git a/internal/domain/types.go b/internal/domain/types.go index 78762196..b10a75f7 100644 --- a/internal/domain/types.go +++ b/internal/domain/types.go @@ -807,14 +807,17 @@ type RunFailure struct { // RunProgress carries structured progress for long-running operators. It is // optional so existing runners and persisted Run documents remain compatible. type RunProgress struct { - Stage string `json:"stage,omitempty" bson:"stage,omitempty"` - Epoch int `json:"epoch,omitempty" bson:"epoch,omitempty"` - Step int `json:"step,omitempty" bson:"step,omitempty"` - MaxStep int `json:"maxStep,omitempty" bson:"maxStep,omitempty"` - SamplesPerSecond float64 `json:"samplesPerSecond,omitempty" bson:"samplesPerSecond,omitempty"` - EstimatedRemainingSeconds int64 `json:"estimatedRemainingSeconds,omitempty" bson:"estimatedRemainingSeconds,omitempty"` - Checkpoint string `json:"checkpoint,omitempty" bson:"checkpoint,omitempty"` - UpdatedAt string `json:"updatedAt" bson:"updatedAt"` + NodeID string `json:"nodeId,omitempty" bson:"nodeId,omitempty"` + CurrentCaptureDirectories []string `json:"currentCaptureDirectories,omitempty" bson:"currentCaptureDirectories,omitempty"` + CurrentFile string `json:"currentFile,omitempty" bson:"currentFile,omitempty"` + Stage string `json:"stage,omitempty" bson:"stage,omitempty"` + Epoch int `json:"epoch,omitempty" bson:"epoch,omitempty"` + Step int `json:"step,omitempty" bson:"step,omitempty"` + MaxStep int `json:"maxStep,omitempty" bson:"maxStep,omitempty"` + SamplesPerSecond float64 `json:"samplesPerSecond,omitempty" bson:"samplesPerSecond,omitempty"` + EstimatedRemainingSeconds int64 `json:"estimatedRemainingSeconds,omitempty" bson:"estimatedRemainingSeconds,omitempty"` + Checkpoint string `json:"checkpoint,omitempty" bson:"checkpoint,omitempty"` + UpdatedAt string `json:"updatedAt" bson:"updatedAt"` } type RunRecord struct { diff --git a/internal/worker/capture_progress_test.go b/internal/worker/capture_progress_test.go new file mode 100644 index 00000000..ba0fb62a --- /dev/null +++ b/internal/worker/capture_progress_test.go @@ -0,0 +1,16 @@ +package worker + +import ( + "droboticflow/internal/domain" + "testing" +) + +func TestCaptureProgressPreservesActiveDirectories(t *testing.T) { + p, err := latestStructuredProgress(`DROBOTICFLOW_PROGRESS {"nodeId":"rectify","currentCaptureDirectories":["capture-a","capture-b"],"currentFile":"left.mp4","step":2,"updatedAt":"2026-09-07T00:00:01Z"}`) + if err != nil || p == nil || len(p.CurrentCaptureDirectories) != 2 || p.CurrentFile != "left.mp4" || p.NodeID != "rectify" { + t.Fatalf("lost capture progress: %#v %v", p, err) + } + if !progressAheadOf(p, &domain.RunProgress{NodeID: "previous", Step: 50, UpdatedAt: "2026-09-07T00:00:00Z"}) { + t.Fatal("new node progress must not be blocked by the previous node step") + } +} diff --git a/internal/worker/runtime.go b/internal/worker/runtime.go index 94c87b21..ecccc004 100644 --- a/internal/worker/runtime.go +++ b/internal/worker/runtime.go @@ -1626,6 +1626,9 @@ func progressAheadOf(next *domain.RunProgress, current *domain.RunProgress) bool if current == nil { return true } + if next.NodeID != "" && next.NodeID != current.NodeID { + return strings.TrimSpace(next.UpdatedAt) > strings.TrimSpace(current.UpdatedAt) + } if next.Epoch < current.Epoch || (next.Epoch == current.Epoch && next.Step < current.Step) { return false } diff --git a/operator-repos/builtin/orbbec_left_undistort/src/operator.py b/operator-repos/builtin/orbbec_left_undistort/src/operator.py index 4c93e376..abbad9ef 100644 --- a/operator-repos/builtin/orbbec_left_undistort/src/operator.py +++ b/operator-repos/builtin/orbbec_left_undistort/src/operator.py @@ -13,6 +13,7 @@ import json import pathlib import shutil import subprocess +from datetime import datetime, timezone from typing import Any, Callable @@ -438,6 +439,17 @@ def run( total_frames = 0 rectified_dir = output_root / "rectified" side_counts: dict[str, int] = {"left": 0, "right": 0} + def report_progress(stage: str, collection_id: str = "", filename: str = "") -> None: + print("DROBOTICFLOW_PROGRESS " + json.dumps({ + "nodeId": node_id, + "stage": stage, + "currentCaptureDirectories": [collection_id] if collection_id else [], + "currentFile": filename, + "step": sum(side_counts.values()), + "maxStep": len(videos), + "updatedAt": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"), + }, ensure_ascii=False), flush=True) + for camera_side in required_sides: videos_port = _output(node_data, f"{camera_side}RectifiedVideos") timestamps_port = _output(node_data, f"{camera_side}RectifiedTimestamps") @@ -446,6 +458,7 @@ def run( for entry in videos_by_side[camera_side]: name = str(entry.get("name", "")).strip() or f"{camera_side}-video.mp4" collection_id = _video_collection_id(entry) + report_progress("loading_video", collection_id, name) calibration_key = (collection_id, camera_side) if calibration_key not in calibrations: if require_calibration: @@ -462,6 +475,7 @@ def run( )) destination = rectified_dir / camera_side / name spec = calibrations[calibration_key] + report_progress("rectifying", collection_id, name) metrics = _rectify_video(source, destination, spec, alpha, preserve_audio, helpers) pts_destination = destination.with_name(f"{destination.stem}_pts.csv") _write_rectified_pts( @@ -544,6 +558,7 @@ def run( artifacts.append(helpers["write_json_artifact"]( run_id, node_id, output_root, "undistort-summary.json", summary, output=_output(node_data, "summary") )) + report_progress("completed") return artifacts diff --git a/src/pages/ProjectDetail.tsx b/src/pages/ProjectDetail.tsx index 35e471e5..5170a6ea 100644 --- a/src/pages/ProjectDetail.tsx +++ b/src/pages/ProjectDetail.tsx @@ -271,6 +271,28 @@ export default function ProjectDetail() { const [historyRuns, setHistoryRuns] = useState([]); const [isHistoryLoading, setIsHistoryLoading] = useState(false); const [historyError, setHistoryError] = useState(""); + useEffect(() => { + if (!isHistoryModalOpen || !historyWorkflow?.id) return; + const controller = new AbortController(); + let timer: ReturnType; + const refresh = async () => { + try { + const items = await workflowsApi.listRuns(historyWorkflow.id, controller.signal); + if (controller.signal.aborted) return; + setHistoryRuns(items || []); + setHistoryError(""); + } catch (error) { + if (!controller.signal.aborted) setHistoryError(getActionErrorMessage(error, "刷新运行进度失败")); + } finally { + if (!controller.signal.aborted) { + setIsHistoryLoading(false); + timer = setTimeout(refresh, 5000); + } + } + }; + void refresh(); + return () => { controller.abort(); clearTimeout(timer); }; + }, [isHistoryModalOpen, historyWorkflow?.id]); const [automationWorkflow, setAutomationWorkflow] = useState(null); const [automationData, setAutomationData] = useState(null); const [runtimePolicy, setRuntimePolicy] = useState(null); @@ -1125,15 +1147,7 @@ export default function ProjectDetail() { setIsHistoryModalOpen(true); setIsHistoryLoading(true); setHistoryError(""); - try { - const runs = await workflowsApi.listRuns(wf.id); - setHistoryRuns(runs || []); - } catch (error) { - console.error("Failed to load workflow run history", error); - setHistoryError(getActionErrorMessage(error, "加载运行历史失败")); - } finally { - setIsHistoryLoading(false); - } + setHistoryRuns([]); }; const openWorkflowCard = (workflow: WorkflowRecord) => { @@ -3438,6 +3452,16 @@ export default function ProjectDetail() { 触发方式: {run.trigger || "manual"} · 启动时间:{" "} {formatCompactDateTime(run.createdAt, timeZone)} + {(run.status === "running" || run.status === "stopping") && ( +
+ {run.progress?.nodeId === run.currentNodeId && run.progress?.currentCaptureDirectories?.length ? ( + <> +
正在处理子目录:{run.progress.currentCaptureDirectories.join("、")}
+ {run.progress.currentFile &&
当前文件:{run.progress.currentFile}
} + + ) : "当前处理子目录:尚未上报"} +
+ )} diff --git a/src/services/api/workflows.ts b/src/services/api/workflows.ts index 29172190..3d65db9e 100644 --- a/src/services/api/workflows.ts +++ b/src/services/api/workflows.ts @@ -77,8 +77,8 @@ export const workflowsApi = { { method: "POST" }, { reason }, ), - listRuns: async (id: string) => - (await apiRequest<{ items: ExecutionRunSummary[] }>(`/api/workflows/${id}/runs`)).items, + listRuns: async (id: string, signal?: AbortSignal) => + (await apiRequest<{ items: ExecutionRunSummary[] }>(`/api/workflows/${id}/runs`, { signal })).items, listVersions: async (id: string) => (await apiRequest<{ items: Workflow[] }>(`/api/workflows/${id}/versions`)).items, activateVersion: async (id: string) => apiRequest<{ workflow: Workflow; items: Workflow[] }>(`/api/workflows/${id}/activate`, { method: "POST" }), diff --git a/src/types.ts b/src/types.ts index a688cf21..1630e92c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1689,6 +1689,9 @@ export interface ExecutionFailure { } export interface ExecutionProgress { + nodeId?: string; + currentCaptureDirectories?: string[]; + currentFile?: string; stage?: string; epoch?: number; step?: number; diff --git a/tests/backend/orbbec_left_undistort_test.py b/tests/backend/orbbec_left_undistort_test.py index af8fe151..1c7f3532 100644 --- a/tests/backend/orbbec_left_undistort_test.py +++ b/tests/backend/orbbec_left_undistort_test.py @@ -2,6 +2,7 @@ import json import pathlib import tempfile import unittest +from unittest.mock import patch from typing import Any import cv2 @@ -166,7 +167,8 @@ def calibration_entry(path: pathlib.Path, collection_id: str = "capture-01") -> class OrbbecLeftUndistortTest(unittest.TestCase): - def test_materializes_left_and_right_rectified_videos_from_stereo_calibration(self): + @patch("builtins.print") + def test_materializes_left_and_right_rectified_videos_from_stereo_calibration(self, printed): with tempfile.TemporaryDirectory() as temp_dir: root = pathlib.Path(temp_dir) left_source = root / "capture-stereo" / "capture_camera_left_part0001.mp4" @@ -205,6 +207,16 @@ class OrbbecLeftUndistortTest(unittest.TestCase): helpers, ) + progress = [json.loads(call.args[0].removeprefix("DROBOTICFLOW_PROGRESS ")) + for call in printed.call_args_list + if str(call.args[0]).startswith("DROBOTICFLOW_PROGRESS ")] + active = [item for item in progress if item["stage"] == "rectifying"] + self.assertEqual(len(active), 2) + self.assertTrue(all(item["currentCaptureDirectories"] == ["capture-stereo"] for item in active)) + self.assertTrue(all(item["nodeId"] == "undistort" for item in active)) + self.assertNotEqual(active[0]["currentFile"], active[1]["currentFile"]) + self.assertEqual(progress[-1]["currentCaptureDirectories"], []) + self.assertEqual(progress[-1]["stage"], "completed") self.assertEqual(len(video_artifacts), 4) by_side = { artifact["data"]["cameraSide"]: artifact diff --git a/tests/frontend/project-ui-regressions.test.mjs b/tests/frontend/project-ui-regressions.test.mjs index b82598e5..8de64718 100644 --- a/tests/frontend/project-ui-regressions.test.mjs +++ b/tests/frontend/project-ui-regressions.test.mjs @@ -2,6 +2,13 @@ import test from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs"; const read = (f) => fs.readFileSync(new URL("../../src/" + f, import.meta.url), "utf8"); +test("run history refreshes actual node progress without guessing from the input root", () => { + const s = read("pages/ProjectDetail.tsx"); + assert.match(s, /progress\?\.nodeId === run.currentNodeId/); + assert.match(s, /currentCaptureDirectories\.join/); + assert.match(s, /setTimeout\(refresh, 5000\)/); + assert.match(s, /当前处理子目录:尚未上报/); +}); test("theme utilities follow the application class rather than OS preference", async () => { const source = read("index.css"); assert.match(source, /@custom-variant dark/);