From a3bd27ecfb6d6fc74f7f4af6d6b02feb33b5292f Mon Sep 17 00:00:00 2001
From: log
Date: Wed, 24 Jun 2026 19:33:34 +0800
Subject: [PATCH] fix: orchestrator state recovery and UI issues
---
video-claw/video-claw/restart.bat | 19 +--------
video-claw/video-claw/backend/core/orchestrator.py | 43 +++++++++++++++++++++
video-claw/video-claw/backend/api/routers/pipelines.py | 27 +++++++++++++
3 files changed, 70 insertions(+), 19 deletions(-)
diff --git a/video-claw/video-claw/backend/api/routers/pipelines.py b/video-claw/video-claw/backend/api/routers/pipelines.py
index 77851b6..00ffff1 100644
--- a/video-claw/video-claw/backend/api/routers/pipelines.py
+++ b/video-claw/video-claw/backend/api/routers/pipelines.py
@@ -155,10 +155,35 @@
ability: Optional[str] = Query(None),
verified_only: bool = False,
):
+ from config import Config
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
if model_type:
+ base_models = get_models_by_type(model_type)
+
+ # Inject models from config.yaml that might not be in hardcoded list
+ config_models = Config.as_dict().get("models", {})
+ type_to_keys = {
+ "llm": ["llm"],
+ "vlm": ["vlm"],
+ "t2i": ["image_t2i"],
+ "i2i": ["image_it2i"],
+ "video": ["video", "video_first_frame", "video_start_end", "video_reference"]
+ }
+ existing_ids = {m["id"] for m in base_models}
+ for key in type_to_keys.get(model_type, []):
+ cfg_id = config_models.get(key)
+ if cfg_id and cfg_id not in existing_ids:
+ base_models.append({
+ "id": cfg_id,
+ "name": cfg_id,
+ "provider": "custom",
+ "type": [model_type],
+ "concurrency": 3
+ })
+ existing_ids.add(cfg_id)
+
models = []
- for model in get_models_by_type(model_type):
+ for model in base_models:
capabilities = model_type_capabilities(model_type, model)
models.append({
"id": model["id"],
diff --git a/video-claw/video-claw/backend/core/orchestrator.py b/video-claw/video-claw/backend/core/orchestrator.py
index 16e321e..e8e78bf 100644
--- a/video-claw/video-claw/backend/core/orchestrator.py
+++ b/video-claw/video-claw/backend/core/orchestrator.py
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
"""
核心编排器 / 工作流引擎
管理六阶段状态机,协调各智能体执行,支持用户在任意阶段介入
@@ -198,8 +198,29 @@
state.status[stage.value] = "pending"
elif isinstance(loaded_status, dict):
state.status = loaded_status
+ # Scrub running and waiting statuses because this is loading from a restart/crash
+ for k, v in state.status.items():
+ if v == "running":
+ state.status[k] = "error"
+ state.error = "服务意外中断,任务已停止"
+ elif v == "waiting":
+ state.status[k] = "pending"
state.artifacts = data.get('artifacts', {})
+ # Scrub running and waiting artifact items
+ for stage, artifact in state.artifacts.items():
+ if not isinstance(artifact, dict):
+ continue
+ for key in ["clips", "images", "scenes", "characters", "settings"]:
+ items = artifact.get(key)
+ if isinstance(items, list):
+ for item in items:
+ if isinstance(item, dict):
+ if item.get("status") == "running":
+ item["status"] = "failed"
+ elif item.get("status") == "waiting":
+ item["status"] = "pending"
+
state.stage_progress = data.get('stage_progress', {})
state.meta = _extract_session_meta(data)
state.updated_at = data.get('updated_at', 0)
@@ -1450,8 +1471,28 @@
state.status[stage.value] = "pending"
elif isinstance(old_status, dict):
state.status = old_status
+ # Scrub running and waiting statuses
+ for k, v in state.status.items():
+ if v == "running":
+ state.status[k] = "error"
+ state.error = "服务意外中断,任务已停止"
+ elif v == "waiting":
+ state.status[k] = "pending"
state.artifacts = data.get("artifacts", {})
+ # Scrub artifact running/waiting items
+ for stage, artifact in state.artifacts.items():
+ if not isinstance(artifact, dict):
+ continue
+ for key in ["clips", "images", "scenes", "characters", "settings"]:
+ items = artifact.get(key)
+ if isinstance(items, list):
+ for item in items:
+ if isinstance(item, dict):
+ if item.get("status") == "running":
+ item["status"] = "failed"
+ elif item.get("status") == "waiting":
+ item["status"] = "pending"
state.stage_progress = data.get("stage_progress", {})
state.error = data.get("error")
state.updated_at = data.get("updated_at", 0)
diff --git a/video-claw/video-claw/restart.bat b/video-claw/video-claw/restart.bat
index 6d417d7..8b24e85 100644
--- a/video-claw/video-claw/restart.bat
+++ b/video-claw/video-claw/restart.bat
@@ -2,32 +2,17 @@
chcp 65001 >nul
echo 正在停止 Video-Claw 服务...
-REM 查找并终止占用 8000 端口的后端服务
-for /f "tokens=5" %%a in ('netstat -aon ^| findstr :8000 ^| findstr LISTENING') do (
- echo 正在关闭后端服务 PID: %%a ...
- taskkill /F /PID %%a 2>nul
-)
+for /f "tokens=5" %%p in ('netstat -ano ^| findstr LISTENING ^| findstr :8000') do taskkill /F /PID %%p 2>nul
+for /f "tokens=5" %%p in ('netstat -ano ^| findstr LISTENING ^| findstr :3000') do taskkill /F /PID %%p 2>nul
-REM 查找并终止占用 3000 端口的前端服务
-for /f "tokens=5" %%a in ('netstat -aon ^| findstr :3000 ^| findstr LISTENING') do (
- echo 正在关闭前端服务 PID: %%a ...
- taskkill /F /PID %%a 2>nul
-)
-
-echo.
echo 正在启动后端服务...
cd backend
-REM 在新窗口中启动后端,如果你的环境不是venv请自行修改
start "Video-Claw Backend" cmd /k ".\venv\Scripts\python.exe api_server.py"
cd ..
-echo.
echo 正在启动前端服务...
cd frontend
-REM 在新窗口中启动前端
start "Video-Claw Frontend" cmd /k "npm run dev"
cd ..
-echo.
echo 服务重启完成!前后端已在新的命令行窗口中运行。
-pause
--
Gitblit v1.8.0