Run each workflow stage as its own task, with fan-out and fan-in

This commit is contained in:
Ian Gulliver
2026-10-15 22:53:54 -07:00
parent f7a0ffcd4c
commit 2180a7e824
15 changed files with 739 additions and 408 deletions
+22 -3
View File
@@ -14,6 +14,7 @@ type FrozenWorkflow struct {
Name string
Definition api.WorkflowDefinition
Brief string
Title string
}
func (s *Store) ListWorkflows(ctx context.Context) ([]api.WorkflowSummary, error) {
@@ -92,7 +93,7 @@ func (s *Store) FreezeWorkflow(ctx context.Context, name string) (FrozenWorkflow
func (s *Store) TaskWorkflow(ctx context.Context, taskID string) (FrozenWorkflow, error) {
f := FrozenWorkflow{}
def := ""
err := s.db.QueryRowContext(ctx, `SELECT workflow_name, workflow_definition, workflow_brief FROM tasks WHERE id = ?`, taskID).Scan(&f.Name, &def, &f.Brief)
err := s.db.QueryRowContext(ctx, `SELECT workflow_name, workflow_definition, workflow_brief, workflow_title FROM tasks WHERE id = ?`, taskID).Scan(&f.Name, &def, &f.Brief, &f.Title)
if errors.Is(err, sql.ErrNoRows) {
return FrozenWorkflow{}, fmt.Errorf("%w: no task %s", ErrNotFound, taskID)
}
@@ -106,6 +107,24 @@ func (s *Store) TaskWorkflow(ctx context.Context, taskID string) (FrozenWorkflow
return f, err
}
func (s *Store) RunTasks(ctx context.Context, run string) ([]api.Task, error) {
return s.queryTasks(ctx, `SELECT `+taskColumns+` FROM tasks WHERE workflow_run = ? ORDER BY created_at`, run)
}
func (s *Store) RecordStage(ctx context.Context, taskID, output, commit string) error {
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
_, err := tx.ExecContext(ctx, `UPDATE tasks SET stage_output = ?, stage_commit = ? WHERE id = ?`, output, commit, taskID)
return err
})
}
func (s *Store) StageResult(ctx context.Context, taskID string) (string, string, error) {
output := ""
commit := ""
err := s.db.QueryRowContext(ctx, `SELECT stage_output, stage_commit FROM tasks WHERE id = ?`, taskID).Scan(&output, &commit)
return output, commit, err
}
func (s *Store) SetStageOutput(ctx context.Context, sessionID, output string) error {
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
_, err := tx.ExecContext(ctx, `UPDATE agent_sessions SET stage_output = ? WHERE id = ?`, output, sessionID)
@@ -186,8 +205,8 @@ func (s *Store) FinishWorkflow(ctx context.Context, task api.Task, sessionID, wo
})
}
func (s *Store) WorkflowFinished(ctx context.Context, taskID string) (bool, error) {
func (s *Store) WorkflowFinished(ctx context.Context, run string) (bool, error) {
finished := false
err := s.db.QueryRowContext(ctx, `SELECT EXISTS (SELECT 1 FROM events WHERE task_id = ? AND kind = 'task.workflow_finished')`, taskID).Scan(&finished)
err := s.db.QueryRowContext(ctx, `SELECT EXISTS (SELECT 1 FROM events e JOIN tasks t ON t.id = e.task_id WHERE t.workflow_run = ? AND e.kind = 'task.workflow_finished')`, run).Scan(&finished)
return finished, err
}