@gobing-ai/ts-dual-workflow-engine 0.5.14 → 0.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -22
- package/dist/action-step.d.ts +1 -0
- package/dist/action-step.d.ts.map +1 -1
- package/dist/action-step.js +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +137 -3
- package/dist/dag.d.ts +25 -0
- package/dist/dag.d.ts.map +1 -0
- package/dist/dag.js +215 -0
- package/dist/events.d.ts +33 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +4 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/persistence.d.ts +24 -1
- package/dist/persistence.d.ts.map +1 -1
- package/dist/persistence.js +91 -0
- package/dist/run-lifecycle.d.ts +8 -0
- package/dist/run-lifecycle.d.ts.map +1 -1
- package/dist/run-lifecycle.js +71 -2
- package/dist/schema-sql.d.ts.map +1 -1
- package/dist/schema-sql.js +20 -0
- package/dist/schema.d.ts +185 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +105 -14
- package/dist/service.d.ts +8 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +55 -3
- package/dist/state-machine.d.ts.map +1 -1
- package/dist/state-machine.js +8 -4
- package/dist/transition-flow.d.ts.map +1 -1
- package/dist/transition-flow.js +199 -4
- package/dist/types.d.ts +109 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/schemas/dag-workflow.schema.json +93 -0
- package/schemas/transition-flow-workflow.schema.json +34 -0
- package/src/action-step.ts +2 -0
- package/src/config.ts +152 -5
- package/src/dag.ts +297 -0
- package/src/events.ts +33 -0
- package/src/host.ts +4 -2
- package/src/index.ts +6 -0
- package/src/persistence.ts +155 -0
- package/src/run-lifecycle.ts +75 -2
- package/src/schema-sql.ts +20 -0
- package/src/schema.ts +108 -16
- package/src/service.ts +72 -7
- package/src/state-machine.ts +8 -3
- package/src/transition-flow.ts +279 -3
- package/src/types.ts +128 -2
package/README.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# @gobing-ai/ts-dual-workflow-engine
|
|
2
2
|
|
|
3
|
-
State-machine
|
|
3
|
+
State-machine, transition-flow, and static-dependency-DAG workflow runtime with pluggable action runners, guard runners, trust-gated extension loading, memory or database persistence, and rich observability.
|
|
4
4
|
|
|
5
5
|
## What It Provides
|
|
6
6
|
|
|
7
|
-
`ts-dual-workflow-engine` runs declarative workflows in
|
|
7
|
+
`ts-dual-workflow-engine` runs declarative workflows in three execution modes:
|
|
8
8
|
|
|
9
9
|
| Mode | Use When |
|
|
10
10
|
|------|----------|
|
|
11
11
|
| `state-machine` | A run owns one current state and chooses the next state by evaluating ordered transition guards |
|
|
12
12
|
| `transition-flow` | A run moves through nodes and edges in a DAG-like flow, executing node actions as it advances |
|
|
13
|
+
| `dag` | A run dispatches nodes as their declared `dependsOn` prerequisites complete; the graph must be acyclic (ADR-034) |
|
|
13
14
|
|
|
14
15
|
The package exposes:
|
|
15
16
|
|
|
@@ -17,9 +18,10 @@ The package exposes:
|
|
|
17
18
|
|
|
18
19
|
| Export | Purpose |
|
|
19
20
|
|--------|---------|
|
|
20
|
-
| `WorkflowService` | High-level loader and runner for
|
|
21
|
+
| `WorkflowService` | High-level loader and runner for all three workflow kinds |
|
|
21
22
|
| `StateMachineDriver` | Direct state-machine execution |
|
|
22
23
|
| `TransitionFlowDriver` | Direct transition-flow execution |
|
|
24
|
+
| `DagDriver` | Direct static dependency-DAG execution |
|
|
23
25
|
| `WorkflowEngineHost` | Capability registry for action runners and guard runners |
|
|
24
26
|
| `createDefaultWorkflowEngineHost()` | Creates a host with built-in `note`, `shell`, `event.emit`, `always`, `never`, and `action-ok` capabilities |
|
|
25
27
|
|
|
@@ -49,7 +51,7 @@ The package exposes:
|
|
|
49
51
|
|--------|---------|
|
|
50
52
|
| `loadWorkflowDef()` / `loadWorkflowDefFromText()` | YAML/JSON workflow loading and validation |
|
|
51
53
|
| `validateWorkflowDef()` | Semantic invariant checking beyond Zod schema |
|
|
52
|
-
| `StateMachineWorkflowDefSchema` / `TransitionFlowWorkflowDefSchema` / `WorkflowDefSchema` / `WorkflowExtensionsSchema` | Zod schemas for workflow definition validation |
|
|
54
|
+
| `StateMachineWorkflowDefSchema` / `TransitionFlowWorkflowDefSchema` / `DagWorkflowDefSchema` / `WorkflowDefSchema` / `WorkflowExtensionsSchema` | Zod schemas for workflow definition validation |
|
|
53
55
|
| `ActionDefSchema` / `GuardDefSchema` | Zod schemas for action and guard definitions |
|
|
54
56
|
|
|
55
57
|
### Extensions
|
|
@@ -154,23 +156,18 @@ erDiagram
|
|
|
154
156
|
|
|
155
157
|
## Architecture
|
|
156
158
|
|
|
159
|
+
`WorkflowService` loads a `WorkflowDef` and dispatches on `workflow.kind` to one of three drivers:
|
|
160
|
+
|
|
161
|
+
| `kind` | Driver | Execution model |
|
|
162
|
+
|--------|--------|-----------------|
|
|
163
|
+
| `state-machine` | `StateMachineDriver` | One current state; ordered transition guards choose the next state |
|
|
164
|
+
| `transition-flow` | `TransitionFlowDriver` | Single-cursor node/edge walk; declared fork/join regions run branches concurrently |
|
|
165
|
+
| `dag` | `DagDriver` | Nodes dispatch as their `dependsOn` prerequisites settle; acyclic only (ADR-034) |
|
|
166
|
+
|
|
167
|
+
All three delegate run identity, persistence sequencing, and observability to `RunLifecycle`:
|
|
168
|
+
|
|
157
169
|
```
|
|
158
|
-
|
|
159
|
-
│ WorkflowService │
|
|
160
|
-
│ load(path) → WorkflowDef │
|
|
161
|
-
│ run(WorkflowDef, options) → WorkflowRunResult │
|
|
162
|
-
│ listRuns() → WorkflowRunRecord[] │
|
|
163
|
-
└──────────────┬───────────────────────┬───────────────┘
|
|
164
|
-
│ dispatches on │
|
|
165
|
-
│ workflow.kind │
|
|
166
|
-
┌───────▼───────┐ ┌───────▼───────┐
|
|
167
|
-
│ StateMachine │ │ TransitionFlow│
|
|
168
|
-
│ Driver │ │ Driver │
|
|
169
|
-
└───────┬───────┘ └───────┬───────┘
|
|
170
|
-
│ │
|
|
171
|
-
│ both delegate to │
|
|
172
|
-
│ │
|
|
173
|
-
┌───────▼───────────────────────▼───────┐
|
|
170
|
+
┌───────────────────────────────────────┐
|
|
174
171
|
│ RunLifecycle │
|
|
175
172
|
│ • run identity (runId) │
|
|
176
173
|
│ • persistence (createRun, savePhase, │
|
|
@@ -591,6 +588,36 @@ const result = await service.run(workflow, {
|
|
|
591
588
|
|
|
592
589
|
`validateWorkflowDef()` is available when the caller already has an object and only needs validation.
|
|
593
590
|
|
|
591
|
+
## Fresh-run Start State
|
|
592
|
+
|
|
593
|
+
A fresh run can begin at a declared state/node instead of the definition's `initialState` / `initialNode`
|
|
594
|
+
by marking that state `startable: true` and passing `startState`. This is **not** resume semantics: no
|
|
595
|
+
snapshot is loaded, `resumeMode` is never set, and the start state's on-enter/node action executes.
|
|
596
|
+
|
|
597
|
+
```yaml
|
|
598
|
+
states:
|
|
599
|
+
- id: fetch # normal entry
|
|
600
|
+
onEnter:
|
|
601
|
+
- kind: note
|
|
602
|
+
options: { message: fetching }
|
|
603
|
+
- id: publish # opt in to being a start point
|
|
604
|
+
startable: true
|
|
605
|
+
onEnter:
|
|
606
|
+
- kind: note
|
|
607
|
+
options: { message: publishing }
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
```ts
|
|
611
|
+
await service.run(workflow, { startState: 'publish', vars: { publish_enabled: 'true' } });
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
`WorkflowService.run` refuses — before any run row is created, with `FSMError` — an undeclared state, a
|
|
615
|
+
terminal state, a failure state, a state not marked `startable`, and any `kind: 'dag'` workflow (DAG
|
|
616
|
+
resumes at node level instead). The marker is per-state by design: there is no workflow-level allow and no
|
|
617
|
+
caller override flag, because a mid-graph start on a state that assumed earlier artifacts must fail loud
|
|
618
|
+
rather than silently skip them. Resume semantics (`skip-enter` / `rerun-enter`, `resumeRerun`) are a
|
|
619
|
+
separate, unchanged path. See ADR-035.
|
|
620
|
+
|
|
594
621
|
## Variables and Environment
|
|
595
622
|
|
|
596
623
|
Actions receive resolved template values. The engine supports:
|
|
@@ -779,7 +806,7 @@ const workflow = StateMachineWorkflowDefSchema.parse(rawObject);
|
|
|
779
806
|
const def = WorkflowDefSchema.parse(rawObject);
|
|
780
807
|
```
|
|
781
808
|
|
|
782
|
-
`WorkflowDefSchema` is a `z.union` of `StateMachineWorkflowDefSchema` and `
|
|
809
|
+
`WorkflowDefSchema` is a `z.union` of `StateMachineWorkflowDefSchema`, `TransitionFlowWorkflowDefSchema`, and `DagWorkflowDefSchema` (`kind: 'dag'`). `ActionDefSchema` and `GuardDefSchema` validate individual action/guard definitions.
|
|
783
810
|
|
|
784
811
|
## Variable Utilities
|
|
785
812
|
|
|
@@ -850,6 +877,10 @@ output or control events without widening the persisted action schema.
|
|
|
850
877
|
| `workflow.run.paused` | `{ runId, node, transitionsTaken, externalKey? }` | When a run pauses at a declared pause point |
|
|
851
878
|
| `workflow.run.resumed` | `{ runId, node, resumeMode, ownerAttemptId, externalKey? }` | When a paused or interrupted run is resumed (`resumeMode`: `skip-enter` \| `rerun-enter`) |
|
|
852
879
|
| `workflow.run.interrupted` | `{ runId, node?, reason, externalKey?, severity }` | When a running run is marked interrupted (crash marker / external stop) |
|
|
880
|
+
| `workflow.branch.started` | `{ runId, parallelNode, branchId, node }` | When an execution branch in a parallel region starts |
|
|
881
|
+
| `workflow.branch.done` | `{ runId, parallelNode, branchId, durationMs, ok }` | When an execution branch in a parallel region finishes |
|
|
882
|
+
| `workflow.branch.failed` | `{ runId, parallelNode, branchId, error? }` | When an execution branch in a parallel region fails |
|
|
883
|
+
| `workflow.branch.paused` | `{ runId, parallelNode, branchId, node }` | When an execution branch in a parallel region pauses |
|
|
853
884
|
### Compatibility Policy
|
|
854
885
|
|
|
855
886
|
The event map is a **cross-package public contract**. Policy: **additive-only** — new events allowed, new optional payload fields allowed; never rename, remove, or repurpose an existing event or field.
|
|
@@ -910,7 +941,7 @@ When no `events` option is provided, the engine incurs zero observability overhe
|
|
|
910
941
|
|
|
911
942
|
## RunLifecycle
|
|
912
943
|
|
|
913
|
-
`RunLifecycle` is the shared bookkeeping layer
|
|
944
|
+
`RunLifecycle` is the shared bookkeeping layer all three drivers delegate to. It manages:
|
|
914
945
|
|
|
915
946
|
- **Run identity** — generates a `runId` (or honors caller-provided), timestamps, and run record
|
|
916
947
|
- **Persistence sequencing** — `createRun` → per-step atomic `commitHop` (transition + state + phase in one batch) → `finalizeRun` at the end (ADR-020)
|
package/dist/action-step.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface ActionStepDeps {
|
|
|
40
40
|
readonly env: Record<string, string>;
|
|
41
41
|
readonly options: WorkflowRunOptions;
|
|
42
42
|
readonly defaultOnError: OnErrorPolicy | undefined;
|
|
43
|
+
readonly signal?: AbortSignal;
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Run one action through its full lifecycle: resolve templates, persist the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-step.d.ts","sourceRoot":"","sources":["../src/action-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EACR,SAAS,EACT,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,0BAA0B,EAC1B,kBAAkB,EACrB,MAAM,SAAS,CAAC;AASjB;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAElE,0JAA0J;AAC1J,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,cAAc,EAAE,aAAa,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"action-step.d.ts","sourceRoot":"","sources":["../src/action-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EACR,SAAS,EACT,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,0BAA0B,EAC1B,kBAAkB,EACrB,MAAM,SAAS,CAAC;AASjB;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAElE,0JAA0J;AAC1J,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,cAAc,EAAE,aAAa,GAAG,SAAS,CAAC;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CACjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAC/B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,IAAI,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CAwD3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACnC,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,IAAI,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CAc3B"}
|
package/dist/action-step.js
CHANGED
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAIhH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAIhH,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3D,mDAAmD;AACnD,MAAM,WAAW,mBAAmB;IAChC,mFAAmF;IACnF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oEAAoE;IACpE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACjD;;;;OAIG;IACH,UAAU,CAAC,EAAE,2BAA2B,CAAC,YAAY,CAAC,CAAC;CAC1D;AAED,yDAAyD;AACzD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAa,GAAG,WAAW,CAGtF;AAED,yDAAyD;AACzD,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,WAAW,CAAC,CAE3G;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAQ/D"}
|
package/dist/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { loadStructuredConfig, parseYamlObject } from '@gobing-ai/ts-runtime';
|
|
2
2
|
import { WorkflowValidationError } from './errors.js';
|
|
3
3
|
import { RUNTIME_BUILTIN_KEYS } from './run-lifecycle.js';
|
|
4
|
-
import { StateMachineWorkflowDefSchema, TransitionFlowWorkflowDefSchema } from './schema.js';
|
|
4
|
+
import { DagWorkflowDefSchema, StateMachineWorkflowDefSchema, TransitionFlowWorkflowDefSchema } from './schema.js';
|
|
5
5
|
/** Load a workflow definition from YAML or JSON text. */
|
|
6
6
|
export function loadWorkflowDefFromText(text, source = '<inline>') {
|
|
7
7
|
const parsed = source.endsWith('.json') ? JSON.parse(text) : parseYamlObject(text);
|
|
@@ -16,6 +16,9 @@ export function validateWorkflowDef(workflow) {
|
|
|
16
16
|
if (workflow.kind === 'transition-flow') {
|
|
17
17
|
validateTransitionFlow(workflow);
|
|
18
18
|
}
|
|
19
|
+
else if (workflow.kind === 'dag') {
|
|
20
|
+
validateDagWorkflowDef(workflow);
|
|
21
|
+
}
|
|
19
22
|
else {
|
|
20
23
|
validateStateMachine(workflow);
|
|
21
24
|
}
|
|
@@ -97,7 +100,10 @@ function parseWorkflowDef(parsed, source) {
|
|
|
97
100
|
function selectWorkflowSchema(parsed) {
|
|
98
101
|
if (parsed !== null && typeof parsed === 'object') {
|
|
99
102
|
const value = parsed;
|
|
100
|
-
if (value.kind === '
|
|
103
|
+
if (value.kind === 'dag') {
|
|
104
|
+
return DagWorkflowDefSchema;
|
|
105
|
+
}
|
|
106
|
+
if (value.kind === 'transition-flow' || 'edges' in value || 'initialNode' in value) {
|
|
101
107
|
return TransitionFlowWorkflowDefSchema;
|
|
102
108
|
}
|
|
103
109
|
}
|
|
@@ -142,16 +148,142 @@ function validateTransitionFlow(workflow) {
|
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
150
|
for (const node of workflow.nodes) {
|
|
151
|
+
if (node.type === 'parallel')
|
|
152
|
+
continue;
|
|
145
153
|
const outbound = workflow.edges.filter((edge) => edge.from === node.id);
|
|
146
154
|
const unconditional = outbound.findIndex((edge) => edge.condition === undefined);
|
|
147
155
|
if (unconditional !== -1 && unconditional < outbound.length - 1) {
|
|
148
156
|
errors.push(`Node "${node.id}" has an unconditional edge that is not last; later edges are unreachable`);
|
|
149
157
|
}
|
|
150
158
|
}
|
|
159
|
+
// Parallel fork-join validation
|
|
160
|
+
const nodeMap = new Map(workflow.nodes.map((n) => [n.id, n]));
|
|
161
|
+
const outboundByFrom = new Map();
|
|
162
|
+
for (const edge of workflow.edges) {
|
|
163
|
+
const list = outboundByFrom.get(edge.from) ?? [];
|
|
164
|
+
list.push(edge.to);
|
|
165
|
+
outboundByFrom.set(edge.from, list);
|
|
166
|
+
}
|
|
167
|
+
for (const node of workflow.nodes) {
|
|
168
|
+
if (node.type === 'parallel') {
|
|
169
|
+
if (!node.branches || node.branches.length < 2) {
|
|
170
|
+
errors.push(`Parallel node "${node.id}" must declare at least 2 branches`);
|
|
171
|
+
}
|
|
172
|
+
if (node.branches) {
|
|
173
|
+
for (const dupe of duplicates(node.branches.map((b) => b.id))) {
|
|
174
|
+
errors.push(`Parallel node "${node.id}" declares duplicate branch id "${dupe}"`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (node.join !== undefined) {
|
|
178
|
+
if (!nodes.has(node.join)) {
|
|
179
|
+
errors.push(`Parallel node "${node.id}" references undeclared join node "${node.join}"`);
|
|
180
|
+
}
|
|
181
|
+
else if (node.join === node.id) {
|
|
182
|
+
errors.push(`Parallel node "${node.id}" cannot have join set to itself`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (node.branches && node.join && nodes.has(node.join) && node.join !== node.id) {
|
|
186
|
+
for (const branch of node.branches) {
|
|
187
|
+
if (!nodes.has(branch.startNode)) {
|
|
188
|
+
errors.push(`Branch "${branch.id}" in parallel node "${node.id}" references undeclared startNode "${branch.startNode}"`);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (branch.startNode === node.join) {
|
|
192
|
+
errors.push(`Branch "${branch.id}" in parallel node "${node.id}" has startNode equal to join node "${node.join}"`);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
// Check for nested parallel nodes and cycles within branch before reaching join
|
|
196
|
+
const visiting = new Set();
|
|
197
|
+
const visited = new Set();
|
|
198
|
+
let hasCycle = false;
|
|
199
|
+
const walk = (currentId) => {
|
|
200
|
+
if (currentId === node.join)
|
|
201
|
+
return;
|
|
202
|
+
if (visiting.has(currentId)) {
|
|
203
|
+
hasCycle = true;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (visited.has(currentId))
|
|
207
|
+
return;
|
|
208
|
+
const currentNode = nodeMap.get(currentId);
|
|
209
|
+
if (currentNode && currentNode.id !== node.id && currentNode.type === 'parallel') {
|
|
210
|
+
errors.push(`Parallel node "${currentNode.id}" is nested inside parallel node "${node.id}" (nested parallel regions are forbidden)`);
|
|
211
|
+
}
|
|
212
|
+
visiting.add(currentId);
|
|
213
|
+
const nextIds = outboundByFrom.get(currentId) ?? [];
|
|
214
|
+
for (const nextId of nextIds) {
|
|
215
|
+
walk(nextId);
|
|
216
|
+
}
|
|
217
|
+
visiting.delete(currentId);
|
|
218
|
+
visited.add(currentId);
|
|
219
|
+
};
|
|
220
|
+
walk(branch.startNode);
|
|
221
|
+
if (hasCycle) {
|
|
222
|
+
errors.push(`Parallel branch "${branch.id}" in node "${node.id}" contains a cycle`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
151
228
|
// Template variable references must resolve.
|
|
152
229
|
errors.push(...checkVariableReferences(collectActionOptions(workflow), workflow.vars, workflow.env));
|
|
153
230
|
throwIfErrors(workflow, errors);
|
|
154
231
|
}
|
|
232
|
+
function validateDagWorkflowDef(workflow) {
|
|
233
|
+
const errors = [];
|
|
234
|
+
const ids = workflow.nodes.map((node) => node.id);
|
|
235
|
+
const nodes = new Set(ids);
|
|
236
|
+
// Duplicate node IDs
|
|
237
|
+
for (const id of duplicates(ids)) {
|
|
238
|
+
errors.push(`Node "${id}" is declared more than once`);
|
|
239
|
+
}
|
|
240
|
+
// Validate dependsOn references and self-dependencies
|
|
241
|
+
for (const node of workflow.nodes) {
|
|
242
|
+
for (const dep of node.dependsOn ?? []) {
|
|
243
|
+
if (dep === node.id) {
|
|
244
|
+
errors.push(`Node "${node.id}" cannot depend on itself`);
|
|
245
|
+
}
|
|
246
|
+
else if (!nodes.has(dep)) {
|
|
247
|
+
errors.push(`Node "${node.id}" references undeclared dependency "${dep}"`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Cycle detection via Kahn's algorithm (topological sort)
|
|
252
|
+
const inDegree = new Map();
|
|
253
|
+
const adjList = new Map();
|
|
254
|
+
for (const id of ids) {
|
|
255
|
+
inDegree.set(id, 0);
|
|
256
|
+
adjList.set(id, []);
|
|
257
|
+
}
|
|
258
|
+
for (const node of workflow.nodes) {
|
|
259
|
+
for (const dep of node.dependsOn ?? []) {
|
|
260
|
+
if (nodes.has(dep) && dep !== node.id) {
|
|
261
|
+
adjList.get(dep)?.push(node.id);
|
|
262
|
+
inDegree.set(node.id, (inDegree.get(node.id) ?? 0) + 1);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const queue = ids.filter((id) => (inDegree.get(id) ?? 0) === 0);
|
|
267
|
+
let visitedCount = 0;
|
|
268
|
+
while (queue.length > 0) {
|
|
269
|
+
const curr = queue.shift();
|
|
270
|
+
if (curr === undefined)
|
|
271
|
+
break;
|
|
272
|
+
visitedCount++;
|
|
273
|
+
for (const neighbor of adjList.get(curr) ?? []) {
|
|
274
|
+
const newDeg = (inDegree.get(neighbor) ?? 1) - 1;
|
|
275
|
+
inDegree.set(neighbor, newDeg);
|
|
276
|
+
if (newDeg === 0)
|
|
277
|
+
queue.push(neighbor);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (visitedCount < ids.length && errors.length === 0) {
|
|
281
|
+
errors.push('Cycle detected in DAG dependencies');
|
|
282
|
+
}
|
|
283
|
+
// Variable template references in actions
|
|
284
|
+
errors.push(...checkVariableReferences(collectActionOptions(workflow), workflow.vars, workflow.env));
|
|
285
|
+
throwIfErrors(workflow, errors);
|
|
286
|
+
}
|
|
155
287
|
/** Return the ids that appear more than once, in first-seen order. */
|
|
156
288
|
function duplicates(ids) {
|
|
157
289
|
const seen = new Set();
|
|
@@ -168,7 +300,9 @@ function collectActionOptions(workflow) {
|
|
|
168
300
|
const optionSets = [];
|
|
169
301
|
const actions = workflow.kind === 'transition-flow'
|
|
170
302
|
? workflow.nodes.flatMap((node) => (node.action ? [node.action] : []))
|
|
171
|
-
: workflow.
|
|
303
|
+
: workflow.kind === 'dag'
|
|
304
|
+
? workflow.nodes.flatMap((node) => (node.action ? [node.action] : []))
|
|
305
|
+
: workflow.states.flatMap((state) => [...(state.onEnter ?? []), ...(state.onExit ?? [])]);
|
|
172
306
|
for (const action of actions) {
|
|
173
307
|
if (action.options)
|
|
174
308
|
optionSets.push(action.options);
|
package/dist/dag.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WorkflowEngineHost } from './host';
|
|
2
|
+
import type { DagWorkflowDef, WorkflowPersistenceAdapter, WorkflowRunOptions, WorkflowRunResult } from './types';
|
|
3
|
+
/** Dependencies required by the static dependency DAG driver. */
|
|
4
|
+
export interface DagDriverOptions {
|
|
5
|
+
readonly host: WorkflowEngineHost;
|
|
6
|
+
readonly persistence: WorkflowPersistenceAdapter;
|
|
7
|
+
}
|
|
8
|
+
/** Execution status of a single DAG node within a run. */
|
|
9
|
+
export type DagNodeStatus = 'pending' | 'ready' | 'running' | 'done' | 'failed' | 'skipped' | 'paused';
|
|
10
|
+
/**
|
|
11
|
+
* Static dependency DAG workflow driver (task 0100, ADR-034).
|
|
12
|
+
* Manages an in-process ready queue of runnable nodes, dispatching them as upstream
|
|
13
|
+
* dependencies complete, propagating skips on conditional branches, and supporting
|
|
14
|
+
* pause, resume, and durable recovery.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DagDriver {
|
|
17
|
+
private readonly options;
|
|
18
|
+
constructor(options: DagDriverOptions);
|
|
19
|
+
/** Run a DAG workflow to completion, pause, or failure. */
|
|
20
|
+
run(workflow: DagWorkflowDef, options?: WorkflowRunOptions): Promise<WorkflowRunResult>;
|
|
21
|
+
/** Resume a paused DAG workflow run. */
|
|
22
|
+
resume(workflow: DagWorkflowDef, runId: string, externalKey: string | undefined, options?: WorkflowRunOptions): Promise<WorkflowRunResult>;
|
|
23
|
+
private loop;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dag.d.ts","sourceRoot":"","sources":["../src/dag.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,KAAK,EAER,cAAc,EAEd,0BAA0B,EAC1B,kBAAkB,EAClB,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAGjB,iEAAiE;AACjE,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAC;CACpD;AAED,0DAA0D;AAC1D,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAKvG;;;;;GAKG;AACH,qBAAa,SAAS;IACN,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,gBAAgB;IAEtD,2DAA2D;IACrD,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAUjG,wCAAwC;IAClC,MAAM,CACR,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,GAAE,kBAAuB,GACjC,OAAO,CAAC,iBAAiB,CAAC;YAYf,IAAI;CAyOrB"}
|
package/dist/dag.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { runActionStep } from './action-step.js';
|
|
2
|
+
import { allowedEnv, RunLifecycle, snapshotTransitions } from './run-lifecycle.js';
|
|
3
|
+
import { mergeSetVars, mergeVars, resolveShellCommandTemplates, resolveTemplates } from './variables.js';
|
|
4
|
+
// Reserved parallel_node namespace reusing the 0094 branch ledger for per-node DAG execution records.
|
|
5
|
+
const DAG_LEDGER_NAMESPACE = '__dag__';
|
|
6
|
+
/**
|
|
7
|
+
* Static dependency DAG workflow driver (task 0100, ADR-034).
|
|
8
|
+
* Manages an in-process ready queue of runnable nodes, dispatching them as upstream
|
|
9
|
+
* dependencies complete, propagating skips on conditional branches, and supporting
|
|
10
|
+
* pause, resume, and durable recovery.
|
|
11
|
+
*/
|
|
12
|
+
export class DagDriver {
|
|
13
|
+
options;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
/** Run a DAG workflow to completion, pause, or failure. */
|
|
18
|
+
async run(workflow, options = {}) {
|
|
19
|
+
return await RunLifecycle.run(workflow.name, 'dag', { persistence: this.options.persistence, events: options.events }, options, (lifecycle) => this.loop(workflow, options, lifecycle));
|
|
20
|
+
}
|
|
21
|
+
/** Resume a paused DAG workflow run. */
|
|
22
|
+
async resume(workflow, runId, externalKey, options = {}) {
|
|
23
|
+
return await RunLifecycle.resume(workflow.name, 'dag', { persistence: this.options.persistence, events: options.events }, runId, externalKey, (lifecycle) => this.loop(workflow, options, lifecycle), options.resumeOwner?.attemptId);
|
|
24
|
+
}
|
|
25
|
+
async loop(workflow, options, lifecycle) {
|
|
26
|
+
const runId = lifecycle.runId;
|
|
27
|
+
let vars = mergeVars(workflow.vars, options.vars);
|
|
28
|
+
const env = allowedEnv(workflow.env?.allow ?? [], options.env);
|
|
29
|
+
const defaultOnError = workflow.defaultOnError;
|
|
30
|
+
// Restore snapshot if resuming
|
|
31
|
+
const snapshot = await this.options.persistence.loadLatestStateSnapshot(runId);
|
|
32
|
+
let transitionsTaken = snapshotTransitions(snapshot?.data);
|
|
33
|
+
if (snapshot?.data?.effectiveVars && typeof snapshot.data.effectiveVars === 'object') {
|
|
34
|
+
vars = mergeVars(vars, snapshot.data.effectiveVars);
|
|
35
|
+
}
|
|
36
|
+
const nodeStatuses = new Map();
|
|
37
|
+
// If resuming, determine if any node was already paused or completed
|
|
38
|
+
const pausedNodeId = snapshot?.state;
|
|
39
|
+
// Seed from the durable per-node ledger (task 0101): settled nodes are never
|
|
40
|
+
// re-dispatched. 'cancelled' rows are condition-skipped nodes; 'paused'/'running'/
|
|
41
|
+
// 'pending' rows fall through to the dependsOn rule so interrupted nodes re-run.
|
|
42
|
+
const priorRows = await this.options.persistence.listRunBranches(runId, DAG_LEDGER_NAMESPACE);
|
|
43
|
+
const priorByNode = new Map(priorRows.map((r) => [r.branch_id, r.status]));
|
|
44
|
+
for (const node of workflow.nodes) {
|
|
45
|
+
const deps = node.dependsOn ?? [];
|
|
46
|
+
const prior = priorByNode.get(node.id);
|
|
47
|
+
if (prior === 'done') {
|
|
48
|
+
nodeStatuses.set(node.id, 'done');
|
|
49
|
+
}
|
|
50
|
+
else if (prior === 'cancelled') {
|
|
51
|
+
nodeStatuses.set(node.id, 'skipped');
|
|
52
|
+
}
|
|
53
|
+
else if (prior === 'failed') {
|
|
54
|
+
nodeStatuses.set(node.id, 'failed');
|
|
55
|
+
}
|
|
56
|
+
else if (pausedNodeId && node.id === pausedNodeId) {
|
|
57
|
+
nodeStatuses.set(node.id, 'done');
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
nodeStatuses.set(node.id, deps.length === 0 ? 'ready' : 'pending');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const checkDependenciesSatisfied = (node) => {
|
|
64
|
+
const deps = node.dependsOn ?? [];
|
|
65
|
+
if (deps.length === 0)
|
|
66
|
+
return { ready: true, shouldSkip: false };
|
|
67
|
+
const policy = node.dependencyPolicy ?? 'all';
|
|
68
|
+
const depStatuses = deps.map((d) => nodeStatuses.get(d) ?? 'pending');
|
|
69
|
+
if (policy === 'any') {
|
|
70
|
+
const anyDone = depStatuses.some((s) => s === 'done');
|
|
71
|
+
if (anyDone)
|
|
72
|
+
return { ready: true, shouldSkip: false };
|
|
73
|
+
const allSettled = depStatuses.every((s) => s === 'done' || s === 'skipped' || s === 'failed');
|
|
74
|
+
const allSkipped = depStatuses.every((s) => s === 'skipped');
|
|
75
|
+
return { ready: false, shouldSkip: allSettled && allSkipped };
|
|
76
|
+
}
|
|
77
|
+
// policy === 'all'
|
|
78
|
+
const allDone = depStatuses.every((s) => s === 'done');
|
|
79
|
+
if (allDone)
|
|
80
|
+
return { ready: true, shouldSkip: false };
|
|
81
|
+
// Skip propagation: if all parents have settled, and none failed, but some are skipped
|
|
82
|
+
const allSettled = depStatuses.every((s) => s === 'done' || s === 'skipped');
|
|
83
|
+
const hasSkipped = depStatuses.some((s) => s === 'skipped');
|
|
84
|
+
if (allSettled && hasSkipped) {
|
|
85
|
+
// If every dependent branch was skipped, skip this node too
|
|
86
|
+
const allSkipped = depStatuses.every((s) => s === 'skipped');
|
|
87
|
+
if (allSkipped) {
|
|
88
|
+
return { ready: false, shouldSkip: true };
|
|
89
|
+
}
|
|
90
|
+
// If some are done and some are skipped, join proceeds with completed branches!
|
|
91
|
+
return { ready: true, shouldSkip: false };
|
|
92
|
+
}
|
|
93
|
+
return { ready: false, shouldSkip: false };
|
|
94
|
+
};
|
|
95
|
+
let pausedNode;
|
|
96
|
+
let failureError;
|
|
97
|
+
while (true) {
|
|
98
|
+
// Find nodes ready to run
|
|
99
|
+
const readyNodes = [];
|
|
100
|
+
for (const node of workflow.nodes) {
|
|
101
|
+
const status = nodeStatuses.get(node.id);
|
|
102
|
+
if (status === 'pending') {
|
|
103
|
+
const check = checkDependenciesSatisfied(node);
|
|
104
|
+
if (check.shouldSkip) {
|
|
105
|
+
nodeStatuses.set(node.id, 'skipped');
|
|
106
|
+
}
|
|
107
|
+
else if (check.ready) {
|
|
108
|
+
nodeStatuses.set(node.id, 'ready');
|
|
109
|
+
readyNodes.push(node);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (status === 'ready') {
|
|
113
|
+
readyNodes.push(node);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (readyNodes.length === 0) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
// Dispatch ready nodes concurrently
|
|
120
|
+
const results = await Promise.all(readyNodes.map(async (node) => {
|
|
121
|
+
nodeStatuses.set(node.id, 'running');
|
|
122
|
+
// Ledger rows make per-node completion durable; dryRun executes nothing and records nothing.
|
|
123
|
+
const nodeStartMs = Date.now();
|
|
124
|
+
if (!options.dryRun) {
|
|
125
|
+
await this.options.persistence.saveBranchStart(runId, DAG_LEDGER_NAMESPACE, node.id, node.id);
|
|
126
|
+
}
|
|
127
|
+
// Check condition if declared
|
|
128
|
+
if (node.condition) {
|
|
129
|
+
const resolvedOptions = node.condition.kind === 'shell'
|
|
130
|
+
? resolveShellCommandTemplates(node.condition.options ?? {}, { vars, env })
|
|
131
|
+
: resolveTemplates(node.condition.options ?? {}, { vars, env });
|
|
132
|
+
const passed = await this.options.host.evaluateGuard(node.condition.kind, resolvedOptions, {
|
|
133
|
+
runId,
|
|
134
|
+
current: node.id,
|
|
135
|
+
vars,
|
|
136
|
+
env,
|
|
137
|
+
workdir: options.workdir,
|
|
138
|
+
});
|
|
139
|
+
if (!passed) {
|
|
140
|
+
nodeStatuses.set(node.id, 'skipped');
|
|
141
|
+
// BranchStatus has no 'skipped'; 'cancelled' marks settled-without-running.
|
|
142
|
+
if (!options.dryRun) {
|
|
143
|
+
await this.options.persistence.saveBranchFinalize(runId, node.id, 'cancelled', Date.now() - nodeStartMs);
|
|
144
|
+
}
|
|
145
|
+
return { id: node.id, status: 'skipped' };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (node.pause === true) {
|
|
149
|
+
nodeStatuses.set(node.id, 'paused');
|
|
150
|
+
if (!options.dryRun) {
|
|
151
|
+
await this.options.persistence.saveBranchFinalize(runId, node.id, 'paused', Date.now() - nodeStartMs);
|
|
152
|
+
}
|
|
153
|
+
return { id: node.id, status: 'paused' };
|
|
154
|
+
}
|
|
155
|
+
if (!options.dryRun && node.action) {
|
|
156
|
+
const step = await runActionStep(node.action, vars, {
|
|
157
|
+
host: this.options.host,
|
|
158
|
+
persistence: this.options.persistence,
|
|
159
|
+
lifecycle,
|
|
160
|
+
workflowName: workflow.name,
|
|
161
|
+
stateOrNodeId: node.id,
|
|
162
|
+
runId,
|
|
163
|
+
mode: 'dag',
|
|
164
|
+
transitionsTaken,
|
|
165
|
+
env,
|
|
166
|
+
options,
|
|
167
|
+
defaultOnError,
|
|
168
|
+
});
|
|
169
|
+
if (step.outcome === 'fail') {
|
|
170
|
+
nodeStatuses.set(node.id, 'failed');
|
|
171
|
+
if (!options.dryRun) {
|
|
172
|
+
await this.options.persistence.saveBranchFinalize(runId, node.id, 'failed', Date.now() - nodeStartMs, undefined, step.result?.error ?? 'failed');
|
|
173
|
+
}
|
|
174
|
+
return { id: node.id, status: 'failed', error: step.result?.error ?? 'failed' };
|
|
175
|
+
}
|
|
176
|
+
if (step.result?.setVars) {
|
|
177
|
+
vars = mergeSetVars(vars, step.result.setVars);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
nodeStatuses.set(node.id, 'done');
|
|
181
|
+
transitionsTaken++;
|
|
182
|
+
if (!options.dryRun) {
|
|
183
|
+
await this.options.persistence.saveBranchFinalize(runId, node.id, 'done', Date.now() - nodeStartMs);
|
|
184
|
+
}
|
|
185
|
+
return { id: node.id, status: 'done' };
|
|
186
|
+
}));
|
|
187
|
+
// Check if any failed or paused
|
|
188
|
+
for (const res of results) {
|
|
189
|
+
if (res.status === 'failed') {
|
|
190
|
+
failureError = res.error;
|
|
191
|
+
}
|
|
192
|
+
else if (res.status === 'paused') {
|
|
193
|
+
pausedNode = res.id;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (failureError) {
|
|
197
|
+
return await lifecycle.fail('dag', transitionsTaken, failureError);
|
|
198
|
+
}
|
|
199
|
+
if (pausedNode) {
|
|
200
|
+
return await lifecycle.pause(pausedNode, transitionsTaken, vars);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Final completion check
|
|
204
|
+
const anyFailed = Array.from(nodeStatuses.values()).some((s) => s === 'failed');
|
|
205
|
+
if (anyFailed) {
|
|
206
|
+
return await lifecycle.fail('dag', transitionsTaken, failureError ?? 'dag-failed');
|
|
207
|
+
}
|
|
208
|
+
// Never report done while a node is stranded (task 0101 R3): unreachable = loud failure.
|
|
209
|
+
const stuck = workflow.nodes.filter((n) => nodeStatuses.get(n.id) === 'pending').map((n) => n.id);
|
|
210
|
+
if (stuck.length > 0) {
|
|
211
|
+
return await lifecycle.fail('dag', transitionsTaken, `dag-unreachable-nodes: ${stuck.join(',')}`);
|
|
212
|
+
}
|
|
213
|
+
return await lifecycle.done('dag', transitionsTaken);
|
|
214
|
+
}
|
|
215
|
+
}
|
package/dist/events.d.ts
CHANGED
|
@@ -163,5 +163,38 @@ export type WorkflowEngineEvents = {
|
|
|
163
163
|
externalKey?: string;
|
|
164
164
|
severity: EventSeverity;
|
|
165
165
|
}) => void;
|
|
166
|
+
/** Emitted when an execution branch in a parallel region starts. */
|
|
167
|
+
'workflow.branch.started': (data: {
|
|
168
|
+
runId: string;
|
|
169
|
+
parallelNode: string;
|
|
170
|
+
branchId: string;
|
|
171
|
+
node: string;
|
|
172
|
+
severity: EventSeverity;
|
|
173
|
+
}) => void;
|
|
174
|
+
/** Emitted when an execution branch in a parallel region finishes. */
|
|
175
|
+
'workflow.branch.done': (data: {
|
|
176
|
+
runId: string;
|
|
177
|
+
parallelNode: string;
|
|
178
|
+
branchId: string;
|
|
179
|
+
durationMs: number;
|
|
180
|
+
ok: boolean;
|
|
181
|
+
severity: EventSeverity;
|
|
182
|
+
}) => void;
|
|
183
|
+
/** Emitted when an execution branch in a parallel region fails. */
|
|
184
|
+
'workflow.branch.failed': (data: {
|
|
185
|
+
runId: string;
|
|
186
|
+
parallelNode: string;
|
|
187
|
+
branchId: string;
|
|
188
|
+
error?: string;
|
|
189
|
+
severity: EventSeverity;
|
|
190
|
+
}) => void;
|
|
191
|
+
/** Emitted when an execution branch in a parallel region pauses. */
|
|
192
|
+
'workflow.branch.paused': (data: {
|
|
193
|
+
runId: string;
|
|
194
|
+
parallelNode: string;
|
|
195
|
+
branchId: string;
|
|
196
|
+
node: string;
|
|
197
|
+
severity: EventSeverity;
|
|
198
|
+
}) => void;
|
|
166
199
|
};
|
|
167
200
|
//# sourceMappingURL=events.d.ts.map
|