Orchestrating Durable Workflows
Use one workflow per stage and chain them with an explicit auto flag:
selection -> script -> asset -> render -> youtube_upload
Stage Payload Contract
Pass these fields in every child trigger:
{
videoId,
auto,
triggerSource: 'workflow',
parentWorkflowId: workflowId
}
Run Persistence
Persist each workflow instance in workflow_runs:
workflow_id,stage,video_id,parent_workflow_id,trigger_source,status,config_json.- Move status through:
queued -> running -> complete|failed|terminated.
await createWorkflowRun(db, { workflowId, stage: 'script', videoId, triggerSource, config: { auto } });
await markWorkflowRunRunning(db, workflowId);
Chaining Guardrails
- If
autoisfalse, run current stage and stop. - If policy returns
BLOCK, stop downstream stages and write blocking reason to video row. - Do not overwrite previous stage ownership fields (for example script stage should not change selected format).
Retry Strategy
- Database and state updates: retry with constant backoff.
- AI calls: retry with exponential backoff.
- Expensive render/extract stages: disable retries when duplicate execution is harmful.