feat: 任务断点续跑/暂停中断/LLM 过滤优化与调度容错
调度与状态机: - 修复 PAUSED 任务被拾起后复活执行(点击暂停反而开始任务):next_queued_run 只取 QUEUED,execute_run 以 PAUSED 进入直接返回,暂停必须显式 resume - 重启恢复:启动时 recover_interrupted_runs 把遗留 RUNNING 置 QUEUED(保留产物) - 暂停信号 paused.flag:暂停接口写、继续/重试清除,OCR 逐帧检查秒级中断, 节点内被暂停保持 PAUSED 不误报 FAILED - 调度轮询容错:_loop 异常不杀死线程(曾致任务永久停留 QUEUED) subtitle-ocr 节点级断点: - ocr_partial.jsonl 逐帧存档,重启/暂停后只处理未处理帧,产物与一次跑完一致 - 进度日志携带窗口平均耗时与线程数;取消后抑制进度日志井喷 llm-filter 过滤质量与限流自适应: - 上下文净化:喂给 LLM 的是过滤后的字幕(规则层垃圾从上下文剔除) - 正则确定性过滤:裸网址域名、HTML/水印模式直接删除 - 429/5xx 指数退避重试;worker 限流错误 report_failure 内存临时降最大线程数 并缩容(无错误窗口回升),失败条目降并发后重试一轮 - 保留长文本保护(noise 不删 ≥min_keep_len 文本,LLM 判定不稳的必要兜底) 前端: - 工作流编排页支持选择工作流编辑(加载最新/历史版本)、版本历史面板、 新建/编辑双模式;管理后台编辑跳转 workflow.html?edit=<id> 工作流:ocr-subtitle v7(filter pool_max_workers=20、pool_fast_threshold=1)
This commit is contained in:
@@ -497,3 +497,45 @@ def test_ocr_passes_short_text_through(monkeypatch, tmp_path) -> None:
|
||||
assert response.status == "completed", response.error
|
||||
srt = Path(response.outputs["srt_uri"]).read_text(encoding="utf-8")
|
||||
assert "SUB 001" in srt
|
||||
|
||||
|
||||
def test_ocr_interrupts_on_pause_flag(monkeypatch, tmp_path) -> None:
|
||||
"""暂停信号:任务被暂停(paused.flag 存在)时 OCR 立即中断。
|
||||
|
||||
output_dir = <storage>/runs/<run_id>/steps/ocr,run 根目录为其父父目录;
|
||||
调度器/API 在暂停时向 run 根写入 paused.flag,节点逐帧检查到即中止:
|
||||
不调用 vlm-ocr、不写该帧断点存档,invoke 返回 failed(由调度器识别为
|
||||
"被暂停"并保持 PAUSED,等待 resume 后从断点续跑)。
|
||||
"""
|
||||
image = tmp_path / "s0.png"
|
||||
image.write_bytes(TEXT_IMG.read_bytes())
|
||||
frames = [(i * 2.0, image) for i in range(4)]
|
||||
|
||||
# 暂停信号位于 run 根目录(steps/ocr 的父父目录)。
|
||||
run_root = tmp_path / "run_root"
|
||||
out_dir = run_root / "steps" / "ocr"
|
||||
out_dir.mkdir(parents=True)
|
||||
(run_root / "paused.flag").write_text("", encoding="utf-8")
|
||||
|
||||
calls: list[str] = []
|
||||
|
||||
def fake_vlm(node_id, request):
|
||||
calls.append(request.inputs["image_uri"])
|
||||
return InvokeResponse(status="completed", outputs={"text": "SUB 001"})
|
||||
|
||||
monkeypatch.setattr("wov_app.registry.invoke", fake_vlm)
|
||||
manifest = _frames_manifest(tmp_path, frames)
|
||||
response = ocr_invoke(
|
||||
InvokeRequest(
|
||||
run_id="run_paused_flag",
|
||||
node_instance_id="",
|
||||
inputs={"frames_manifest": str(manifest)},
|
||||
params={},
|
||||
output_dir=str(out_dir),
|
||||
)
|
||||
)
|
||||
# 节点以"被暂停"失败:调度器会据此保持 PAUSED 而不标 FAILED。
|
||||
assert response.status == "failed"
|
||||
assert "暂停" in (response.error or "")
|
||||
assert calls == [] # 一帧都没有真正 OCR。
|
||||
assert not (out_dir / "ocr_partial.jsonl").exists() # 未处理帧不入存档。
|
||||
|
||||
Reference in New Issue
Block a user