✨ Report active Capture subdirectory in workflow run history

This commit is contained in:
eust-w 2026-09-07 03:53:45 +08:00
parent 371edf7de9
commit 4e761d6369
10 changed files with 118 additions and 20 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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")
}
}

View File

@ -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
}

View File

@ -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

View File

@ -271,6 +271,28 @@ export default function ProjectDetail() {
const [historyRuns, setHistoryRuns] = useState<ExecutionRunSummary[]>([]);
const [isHistoryLoading, setIsHistoryLoading] = useState(false);
const [historyError, setHistoryError] = useState("");
useEffect(() => {
if (!isHistoryModalOpen || !historyWorkflow?.id) return;
const controller = new AbortController();
let timer: ReturnType<typeof setTimeout>;
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<WorkflowRecord | null>(null);
const [automationData, setAutomationData] = useState<CaptureAutomationResponse | null>(null);
const [runtimePolicy, setRuntimePolicy] = useState<WorkflowRuntimePolicy | null>(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)}
</div>
{(run.status === "running" || run.status === "stopping") && (
<div className="mt-2 max-w-lg break-words text-xs text-[color:var(--app-text)]" aria-label="当前处理子目录">
{run.progress?.nodeId === run.currentNodeId && run.progress?.currentCaptureDirectories?.length ? (
<>
<div>正在处理子目录:{run.progress.currentCaptureDirectories.join("、")}</div>
{run.progress.currentFile && <div className="mt-1 break-all text-slate-500 dark:text-gray-400">当前文件:{run.progress.currentFile}</div>}
</>
) : "当前处理子目录:尚未上报"}
</div>
)}
</div>
</div>

View File

@ -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" }),

View File

@ -1689,6 +1689,9 @@ export interface ExecutionFailure {
}
export interface ExecutionProgress {
nodeId?: string;
currentCaptureDirectories?: string[];
currentFile?: string;
stage?: string;
epoch?: number;
step?: number;

View File

@ -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

View File

@ -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/);