workflow

package
v0.2.0-alpha.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWorkflowsNotConfigured     = apierr.New(apierr.KindNotConfigured, "workflows not configured")
	ErrIssuesNotConfigured        = apierr.New(apierr.KindNotConfigured, "issues not configured")
	ErrTasksNotConfigured         = apierr.New(apierr.KindNotConfigured, "tasks not configured")
	ErrWorkflowNameRequired       = apierr.New(apierr.KindInvalid, "workflow name required")
	ErrWorkflowDefinitionRequired = apierr.New(apierr.KindInvalid, "workflow definition required")
	ErrWorkflowNotFound           = apierr.New(apierr.KindNotFound, "workflow not found")
	ErrWorkflowRunNotFound        = apierr.New(apierr.KindNotFound, "workflow run not found")
	ErrWorkflowRevisionNotFound   = apierr.New(apierr.KindNotFound, "workflow revision not found")
	ErrIssueNotFound              = apierr.New(apierr.KindNotFound, "issue not found")
	ErrIssueWorkflowMismatch      = apierr.New(apierr.KindInvalid, "issue not assigned to workflow")
	ErrInvalidDefinition          = apierr.New(apierr.KindInvalid, "invalid workflow definition")
	ErrUnsupportedSchemaVersion   = apierr.New(apierr.KindInvalid, "unsupported workflow schema_version: only schema_version 1 is supported")
	ErrInvalidInputSchema         = apierr.New(apierr.KindInvalid, "invalid workflow input_schema: must be within the supported JSON Schema subset")
	ErrInvalidResult              = apierr.New(apierr.KindInvalid, "invalid workflow result: source must be node.<id>.output naming an existing node, with a valid RFC 6901 pointer")
	ErrInvalidRunInput            = apierr.New(apierr.KindInvalid, "invalid workflow run input: it must be JSON satisfying the workflow input_schema, and is only accepted when the workflow declares one")
	ErrInvalidNodeType            = apierr.New(apierr.KindInvalid, "invalid workflow node type")
	ErrInvalidNodeID              = apierr.New(apierr.KindInvalid, "invalid workflow node id: each node needs a unique non-empty id")
	ErrInvalidNeeds               = apierr.New(apierr.KindInvalid, "invalid workflow node needs: each entry must name a distinct existing node, the edges must form a directed acyclic graph, and a node may not need itself")
	ErrInvalidPolicy              = apierr.New(apierr.KindInvalid, "invalid workflow policy: max_parallel_nodes must be between 1 and the deployment maximum")
	ErrInvalidIssueAccess         = apierr.New(apierr.KindInvalid, "invalid workflow node issue_access: must be none, if_bound, or required")
	ErrInvalidAgentRevision       = apierr.New(apierr.KindInvalid, "invalid workflow node agent revision: the pinned revision does not exist")
	ErrIssueRequired              = apierr.New(apierr.KindInvalid, "workflow run requires an issue: a node declares issue_access required but the run has none")
	ErrInvalidBinding             = apierr.New(apierr.KindInvalid, "invalid workflow node binding: a unique name, a source of workflow.input or node.<id>.output naming a predecessor node, and a valid RFC 6901 pointer are required")
	ErrInvalidOutputSchema        = apierr.New(apierr.KindInvalid, "invalid workflow node output_schema: must be within the supported JSON Schema subset")
	ErrInvalidTargetAgent         = apierr.New(apierr.KindInvalid, "invalid target agent")
	ErrInvalidWorkflowStatus      = apierr.New(apierr.KindInvalid, "invalid workflow status")
	ErrWorkflowNotPublished       = apierr.New(apierr.KindInvalid, "workflow not published")
	ErrWorkflowArchived           = apierr.New(apierr.KindInvalid, "workflow archived")
)

Functions

This section is empty.

Types

type ArtifactReader

type ArtifactReader interface {
	ListArtifactsBySource(ctx context.Context, sourceIDs []string) (map[string][]coreartifact.Artifact, error)
}

ArtifactReader lists the Artifacts a set of producing operations attributed to themselves, so a node output envelope can carry references to what its accepted TaskRun produced. It is optional: a deployment with no artifact store leaves it nil, and node output envelopes then carry no artifacts. coreartifact.Store satisfies it.

type CreateWorkflowCmd

type CreateWorkflowCmd struct {
	SpaceID     string
	UserID      string
	Name        string
	Description string
	Definition  string
}

type RestoreWorkflowRevisionCmd

type RestoreWorkflowRevisionCmd struct {
	SpaceID    string
	UserID     string
	WorkflowID string
	Revision   int
}

RestoreWorkflowRevisionCmd restores an earlier revision's content.

type Service

type Service struct {
	Workflows   coreworkflow.Store
	Agents      agentdef.Store
	Issues      coreissue.Store
	TaskService *task.Service
	// TaskRuns reads the TaskRun a step owns so Reconcile can fold its terminal
	// outcome. Wired from the same store the Task service uses.
	TaskRuns TaskRunReader
	// Artifacts is optional; nil leaves node output envelopes without Artifact
	// references, so a binding into a node's /artifacts resolves to an empty list.
	// Wired from the artifact store when a deployment has one.
	Artifacts ArtifactReader
	// Audit is optional; nil discards the events. A workflow is a reusable plan
	// that shared work runs against, so its creation, edits, and lifecycle moves
	// are governed acts worth the trail.
	Audit *audit.Recorder
}

func (*Service) CreateWorkflow

func (s *Service) CreateWorkflow(ctx context.Context, cmd CreateWorkflowCmd) (*coreworkflow.Workflow, error)

func (*Service) GetWorkflow

func (s *Service) GetWorkflow(ctx context.Context, spaceID, workflowID string) (*coreworkflow.Workflow, error)

func (*Service) GetWorkflowRunDetail

func (s *Service) GetWorkflowRunDetail(ctx context.Context, spaceID, workflowRunID string) (*coreworkflow.Run, []coreworkflow.NodeRun, error)

func (*Service) HandleTaskRunTerminal

func (s *Service) HandleTaskRunTerminal(ctx context.Context, info coretask.RunTerminalInfo) error

HandleTaskRunTerminal is only a wake-up now: it maps the finished TaskRun to its WorkflowRun and asks the reconciler to advance it. The reconciler reads the TaskRun's terminal facts from durable state itself, so a callback that is lost costs a wake-up the due-run sweep supplies, not the outcome it carried.

func (*Service) ListDueWorkflowRuns

func (s *Service) ListDueWorkflowRuns(ctx context.Context, now time.Time, limit int) ([]coreworkflow.Run, error)

ListDueWorkflowRuns exposes the store's due-run scan so the Server's recovery loop depends on this service -- which also owns Reconcile -- rather than reaching into the store for one half of the pair.

func (*Service) ListWorkflowRevisions

func (s *Service) ListWorkflowRevisions(ctx context.Context, spaceID, workflowID string, limit, offset int) ([]coreworkflow.Revision, int, error)

func (*Service) ListWorkflowRuns

func (s *Service) ListWorkflowRuns(ctx context.Context, spaceID, workflowID string, limit, offset int) ([]coreworkflow.Run, int, error)

func (*Service) ListWorkflows

func (s *Service) ListWorkflows(ctx context.Context, spaceID string) ([]coreworkflow.Workflow, error)

func (*Service) PublishedWorkflowsUsingAgent

func (s *Service) PublishedWorkflowsUsingAgent(ctx context.Context, spaceID, agentID string) ([]coreworkflow.Workflow, error)

PublishedWorkflowsUsingAgent returns the space's published workflows whose definition names agentID.

It exists so deleting an agent can be refused while a workflow that can still be run depends on it. Draft and archived workflows do not count: neither can start a run, and publishing one revalidates its agents.

A published workflow whose definition no longer parses is skipped rather than treated as a reference. It cannot run either way, and blocking an unrelated delete on it would leave no way forward.

func (*Service) Reconcile

func (s *Service) Reconcile(ctx context.Context, workflowRunID string) error

Reconcile advances one WorkflowRun from durable facts. It is the single progression entry point for the linear precursor: under a bounded lease it reads the run, its steps, and the TaskRun the running step owns; folds a terminal TaskRun into a guarded step and run transition; dispatches the next pending step (re-admitting its Task by the stable key, which recovers the crash window between admitting a step's Task and linking it); and records when the run next wants a pass while work remains.

It is safe to call after admission, from a terminal callback, from a due-run sweep, on restart, or by two callers at once. The lease only reduces duplicate work; idempotent admission and the guarded compare-and-set transitions are the correctness mechanism when a lease is lost or races.

func (*Service) RestoreWorkflowRevision

func (s *Service) RestoreWorkflowRevision(ctx context.Context, cmd RestoreWorkflowRevisionCmd) (*coreworkflow.Workflow, error)

RestoreWorkflowRevision writes an earlier revision's name, description, and definition back to the workflow, which appends a new revision rather than rewinding to the old one.

Status is deliberately not restored. It is lifecycle state, not content: restoring the definition of a draft revision must not unpublish a workflow spaces are running, and restoring a published one must not publish a draft without anyone deciding to. The definition is revalidated, so a revision whose agents have since been deleted is refused rather than restored into a plan that cannot run.

func (*Service) StartWorkflowRun

func (s *Service) StartWorkflowRun(ctx context.Context, cmd StartWorkflowRunCmd) (*coreworkflow.Run, []coreworkflow.NodeRun, error)

func (*Service) UpdateWorkflow

func (s *Service) UpdateWorkflow(ctx context.Context, cmd UpdateWorkflowCmd) (*coreworkflow.Workflow, error)

type StartWorkflowRunCmd

type StartWorkflowRunCmd struct {
	SpaceID    string
	UserID     string
	WorkflowID string
	IssueID    *string
	// Input is the caller-supplied run input JSON. It is validated against the
	// workflow's input_schema and frozen onto the run; empty means no input, which
	// a workflow that declares an input_schema rejects.
	Input string
}

type TaskRunReader

type TaskRunReader interface {
	GetTaskRun(ctx context.Context, taskRunID string) (*coretask.Run, error)
}

TaskRunReader is the read half of the Task plane a reconciliation observes. Reconcile folds a step's TaskRun terminal facts by reading them from durable state rather than trusting a pushed callback, so a lost callback loses a wake-up, not the outcome. coretask.RunStore satisfies it.

type UpdateWorkflowCmd

type UpdateWorkflowCmd struct {
	SpaceID     string
	UserID      string
	WorkflowID  string
	Name        *string
	Description *string
	Definition  *string
	Status      *string
	// ExpectedRevision pins the update to the revision the caller already
	// observed, so a restore conflicts against an edit that landed after the
	// caller read the workflow. It is nil for a plain edit, which observes the
	// current revision just before the write instead.
	ExpectedRevision *int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL