feat(maf): complete resilient roundtable workflow

This commit is contained in:
董宏凯 committed 2026-08-02 00:23:25 +08:00
1 parent bd4131b4e2
commit 21c4c898e7
23 files changed
+4810 -312

No files matched your search

@@ -96,6 +96,36 @@ class MafRunDispatcher:
runner = WorkflowRunner(self._app, service=service, user_id=user_id)
return await runner.resume(run_id)
async def recover(self, run_id: str, *, user_id: str) -> dict[str, Any] | None:
"""Re-enter the workflow from checkpoint after a process restart.
Unlike ``resume`` (approval path), this continues orchestration for
``running`` runs and skips ``completed_nodes``.
"""
from app.maf_roundtable.workflow_runner import WorkflowRunner
service = getattr(self._app.state, "maf_roundtable_service", None)
if service is None:
raise MafSdkNotAvailableError("MAF roundtable service not available")
# Avoid overlapping with an in-process execute task.
existing = self._tasks.get(run_id)
if existing is not None and not existing.done():
logger.info("recover(%s): background task still running — skip", run_id)
return await service.store.runs.get_run(run_id)
runner = WorkflowRunner(self._app, service=service, user_id=user_id)
task = asyncio.create_task(self._recover(runner, run_id))
self._tasks[run_id] = task
task.add_done_callback(lambda t, rid=run_id: self._tasks.pop(rid, None))
return await service.store.runs.get_run(run_id)
async def _recover(self, runner: Any, run_id: str) -> None:
try:
await runner.recover(run_id)
except Exception:
logger.exception("MAF recover failed for run %s", run_id)
async def cancel(self, run_id: str) -> dict[str, Any]:
"""Cancel a running workflow AND cascade to DeerFlow sub-runs.