Workflow semantics
Exactly how a workflow runs: nodes, ports, files, branching, AND, OR and NOT, ordering, errors, cancellation and limits.
What this page covers
This page describes how a version 2 workflow runs, block by block. It is written from the engine's code, so where the engine makes no promise, the page says so. The same rules apply whether the workflow is run from the Workflow board or with window.eeshgarg.runWorkflow. The format itself is in Workflow API.
Nodes, ports and edges
| Node | Input ports | Output ports | Settings |
|---|---|---|---|
| input | none | out | type: any, or one file kind |
| task | in | out | tool (a tool id or text:<op>), options |
| if | in | true, false | field, operator, value |
| and | a, b | out | none |
| or | a, b | out | none |
| not | in, unless | out | none |
| output | in | none | none |
An edge joins one output port to one input port. Validation rejects an edge whose ports do not exist on those node types, and the same edge listed twice. Every and, or and not input port must have at least one edge. A block with no connected output port simply has nowhere for its files to go; that is allowed.
How files move
- Several edges into one input port are joined: the files of each edge are concatenated, in the order the edges appear in the workflow's
edgeslist (gatherwalks the edges in that order). - One output port with several edges sends the same list to each of them. The engine passes the same File objects along; it does not copy the bytes.
- Nothing arriving is recorded as an empty edge. A block that needs files on a port skips when that port carries none (see Skipping).
- Files are not renamed by the engine. A tool names its own outputs; a text operation keeps each file's name (
runTextTask), so a hash task produces a file with the input's name and the digest as its content.
Input blocks
An input block takes the files you pass to the run whose kind matches its type, or every file for any. Files of another kind are dropped at that block and do not reach anything else. An input block cannot fail. If it matches nothing, it is still reported as done with zero files, and everything after it is skipped.
Kinds come from the file name and, for PDFs and images, the MIME type (classify). A .csv file is anxlsx file for this purpose, because the kinds are tried in the order pdf, image, docx, xlsx, pptx, html, text, and xlsx is the first to list csv. A .json or .md file is text. A file of a kind the site does not know (for example an SVG) has no kind: it passes only an any input or a test with !=.
Task blocks
There are two kinds of task.
- A tool task (
toolis a tool or feature id) is called once with all the files on its input port. It is not called once per file. The tool then applies its own rules: a tool that takes one file fails when it receives several, and a tool that refuses a file type throws. The engine does not drop the files the tool refuses; the whole task fails. - A text task (
toolistext:<op>) runs the text operation on each file in turn, one after another, and writes the result back under the same name. A file that is not valid UTF-8 for a text operation makes the task fail.
A task's output replaces the files on its output port. A task that returns no files fails with the message "The step produced no files." Tool warnings are added to the node's message when the task succeeds. Option names and kinds are checked when the workflow is validated, before any file is read.
If blocks and their tests
An if block tests the whole group of files that reaches it. It does not split a mixed group. The group goes to true when the test passes and to false when it does not; the other port gets nothing.
| Field | Operators | Passes when |
|---|---|---|
type | == or != | == : every file is the kind given. != : no file is that kind. |
count | == != < <= > >= | The number of files in the group compares with the whole number. |
size | == != < <= > >= | The total bytes of the group compare with the whole number. |
name | contains or matches | Every file name contains the text (case-insensitive), or matches the regular expression (case-insensitive). |
If a test cannot run (for example, the expression is not usable at run time), the block fails and both of its outputs are marked failed (see Errors).
AND, OR and NOT
| Block | Runs when | Output | Skipped when |
|---|---|---|---|
and | Both a and b carry files | The files of a, then the files of b | Either port carries none |
or | a or b (or both) carries files | The files of a, then the files of b, for whichever arrived | Neither port carries files |
not | in carries files and unless carries none and has not failed | The files of in | in has no files, or unless has files, or unless failed |
So not is "in and not unless". It is not a NOR block, and it does not look at the content of unless, only at whether anything arrived there. A failed unless blocks the output rather than letting the files through, because a failure is not the same as nothing arriving.
When both inputs of an and or or carry the same files, the files appear twice in the output. The engine concatenates; it does not remove duplicates.
NOR: there is no NOR block
A NOR ("the group passes when neither test holds") is built from an or and a not. Feed the whole group into not.in, feed each test into an or, and send the or output to not.unless. The files pass only when neither test passes. Because the if blocks test whole groups, this works on the group, not file by file. For file-by-file routing, use separate input blocks for each kind first.
Skipping and branch selection
- A task, if, output or and block whose input ports do not all carry files is skipped. An or block is skipped only when neither input carries files. A not block is skipped when its in input carries no files, or its unless input carries files or has failed. A skipped block passes "no files" on all its outputs.
- A skip caused by a failed branch says so ("Skipped: an earlier step failed."); any other skip says "Skipped: no files reached this step."
- A failure travels downstream through skips. A block that loses its files because of a failed branch is skipped with the failure reason, and the blocks after it are skipped in turn unless they still receive files from another branch.
- An and block is skipped when either input carries no files, even if the other input carries some. The files it has are not passed on. The same holds for a not block whose unless input failed: the files on in are not passed on.
- An or block can run from the input that is not failed. If the other input failed and the or input carries files, the or block runs with those files and its output goes on as usual, while the run still reports the failure.
- A skipped branch does not make the run fail. Skips alone do not set the run status to failed.
Execution order and ordering guarantees
- Sequential. Blocks run one at a time, in a single loop with
await. Nothing is run in parallel by the graph engine. A tool may use workers or threads internally, which is the tool's business. - Topological. The order is a topological sort (Kahn's algorithm). A block runs only after every block that feeds it, directly or through other blocks, has finished or been skipped.
- Deterministic for a given workflow. The sort starts from the input blocks in the order they appear in
nodesand works through successors first-in, first-out, so the same workflow gives the same order each time. The engine does not promise a particular order between independent branches, and the order is not part of the format. Do not depend on it. - No pruning. A block runs if it receives files, even when nothing downstream reaches an output block.
- Positions do not matter. The x and y numbers on the board do not affect the order.
Output blocks and the result
An output block collects the files on its input port. Each output block that runs adds one entry to outputs, with its id and its files. A skipped output block adds nothing. The result's files are all the collected files, in the order the output blocks ran. A workflow may have several output blocks; there must be at least one.
Errors and partial failure
- A failing task (it throws, or returns no files) is marked failed with its message. Its outputs are marked failed, so the blocks after it are skipped with the failure reason.
- The run does not stop. Other branches that do not depend on the failed block keep running and can reach an output block.
- Partial results are returned. A run with a failure still returns the files that reached output blocks in the branches that succeeded.
- The status is "failed" when any block is marked failed, unless the run was cancelled, which takes priority.
- No retries: a failed block is not run again. There is no option for it.
Retries, timeouts and idempotency
- No retries. The engine does not repeat a failed block.
- No timeout. The engine sets no time limit on a block. A block runs until its tool finishes, fails or is cancelled.
- Nothing is cached between runs. Every run executes every block that receives files. Running the same workflow twice on the same files runs the tools twice.
- The input files are read, not changed. The engine reads the bytes of the files you pass and creates new files for results.
- Output bytes are the tool's. The engine adds no timestamps or random values to the results. Whether a particular tool produces identical bytes on each run is a property of that tool.
Cancellation
- The engine checks the cancellation signal before each block and after each task finishes. A text task also checks before each file.
- A task that finishes after the signal was aborted is discarded and marked waiting with "Cancelled."; its files are not passed on.
- Blocks that have not started stay waiting, and the run ends with status
cancelled. - Output files collected before the cancellation are still returned. Treat a cancelled result as partial.
- An abort that arrives after the last block has finished changes nothing: the status is the normal one (done or failed).
- Within a tool, cancellation depends on that tool honouring the signal it is given.
Field names, the onNode progress callback and code for aborting a run are on the Workflow API page, under "The result, progress and cancellation".
What is rejected before a run
Validation runs first, and an invalid workflow never starts. It rejects: a version other than 2; unknown fields; a missing input or output block; a node unreachable from any input block; a cycle; an unconnected and, or or not input port; an unknown node type, tool, text operation, option, option kind or test value; a bad port name; a duplicate edge. Up to 20 problems are reported, each with its location.
Resource limits
| What | Limit | Where |
|---|---|---|
| Nodes in a graph | 100 | GRAPH_LIMITS.MAX_NODES |
| Edges in a graph | 200 | GRAPH_LIMITS.MAX_EDGES |
| Workflow JSON text | 256 KB (UTF-8 bytes) | GRAPH_LIMITS.MAX_JSON_BYTES |
| Workflow name | 120 characters | GRAPH_LIMITS.MAX_NAME |
| Node id | 1 to 40 letters, digits, - or _ | checkNode |
| Node x and y | Within plus or minus 100000 | MAX_COORD |
| Nesting depth scanned for forbidden keys | 32 | GRAPH_LIMITS.MAX_DEPTH |
| If test text (name) | 1 to 200 characters | MAX_TEST_TEXT |
| If test count | 0 to 100000 | MAX_COUNT |
| If test size | 0 to 2^40 bytes | MAX_SIZE |
| Text value per text step (characters) | 16,777,216 | LIMITS.MAX_VALUE_CHARS (text tasks only) |
| Bytes value per step | 64 MiB (67,108,864 bytes) | LIMITS.MAX_VALUE_BYTES (text tasks only) |
| json.parse input | 16,777,216 characters | LIMITS.MAX_JSON_PARSE_CHARS |
| hex.decode input | 33,554,432 characters | LIMITS.MAX_HEX_CHARS |
Not limited by the engine: the number of files in a run, the total size of the files, and how long a tool takes. Tools set their own file rules, and those appear on each tool's page.
Permissions, network and side effects
- No network of its own. The graph engine makes no network requests of its own. Tools run in the page or in workers on your device. The one exception is the optional statistics beacon described below.
- No browser permissions are requested by the engine. A tool that needs one asks when it runs.
- No storage. A run writes nothing to the browser. Results exist as files in memory until you save them.
- One optional side effect. When statistics are turned on in Settings and an endpoint is configured in the build, each task that succeeds adds one count to an in-memory batch, labelled workflow. Nothing about the files is recorded. Off by default. See Statistics.
Determinism
For a given workflow and given inputs, the engine visits blocks in the same order, concatenates files in the same order and makes the same branch decisions. The branch decisions depend only on the files' names, kinds, count and sizes. The bytes a tool produces are that tool's property, as described under retries. Text operations are computed from their input and options.
Versioning and compatibility
- Version 2 is the graph format described here (
GRAPH_VERSION). Validation rejects any other version number, except that a version 1 pipeline is accepted and converted (below). - Version 1 is the older text pipeline (
FORMAT_VERSION). It is accepted, and converted on import into a version 2 graph: an input block, one text task per step (namedtext:<op>), and an output block. - The converted graph has the ids input, step1, step2 and so on, and output. The conversion keeps each step's options.
- Compatibility promise. A later format would have a new version number. This page describes version 2 only. The API version is reported by
window.eeshgarg.version.
Direct invocation or a workflow
| Direct (runTool) | Task block in a workflow | |
|---|---|---|
| How you call it | One tool, one call, with the files you choose and typed options | One block; the engine calls the same tool path with the files on its port |
| Files | Checked against the tool's accepted kinds and counts; a bad file throws | Same checks; a bad file fails that block and the failure travels downstream |
| Errors | Thrown to the caller | Recorded on the block, and the run returns status failed or cancelled |
| Text operations | Not available | Available as text:<op> |
| Conditions and branching | None: you do the branching in your code | if, and, or and not blocks |
| Statistics | Counted as direct when the tool page or API records a successful run | Counted as workflow for each successful task |
A direct run is the right choice when one tool does the job. A workflow is the right choice when the decision of what to run depends on the files, or when several tools have to run in one defined order.